public FeatureCollection<T, F> getFeatures(Filter filter) throws IOException { return delegate.getFeatures(filter); }
public FeatureCollection<T, F> getFeatures() throws IOException { return delegate.getFeatures(); }
public FeatureCollection<T, F> getFeatures(Query query) throws IOException { return delegate.getFeatures(query); }
public void initialize() throws IOException { if (shapefile == null) { throw new IllegalStateException("shapefile path is not set"); } // get feature results ShapefileDataStore store = new ShapefileDataStore(new File(shapefile).toURI().toURL()); String name = store.getTypeNames()[0]; FeatureSource source = store.getFeatureSource(name); collection = source.getFeatures(); }
public FeatureCollection<T, F> getFeatures() throws IOException { final FeatureCollection<T, F> fc = delegate.getFeatures(getReadQuery()); if (fc == null) return null; else return (FeatureCollection) SecuredObjects.secure(fc, policy); }
File file = new File("mayshapefile.shp"); try { Map connect = new HashMap(); connect.put("url", file.toURL()); DataStore dataStore = DataStoreFinder.getDataStore(connect); String[] typeNames = dataStore.getTypeNames(); String typeName = typeNames[0]; System.out.println("Reading content " + typeName); FeatureSource featureSource = dataStore.getFeatureSource(typeName); FeatureCollection collection = featureSource.getFeatures(); FeatureIterator iterator = collection.features(); try { while (iterator.hasNext()) { Feature feature = iterator.next(); Geometry sourceGeometry = feature.getDefaultGeometry(); } } finally { iterator.close(); } } catch (Throwable e) {}
/** We have to cache all the features in the supplemental file, because * if we try to load them on the fly, GeoTools wigs out. */ private void ensureCached() { if (cache != null) { return; } cache = new HashMap<String, SimpleFeature>(); try { FeatureCollection<SimpleFeatureType, SimpleFeature> features = joinedSource .getFeatures(); FeatureIterator<SimpleFeature> it = features.features(); while (it.hasNext()) { SimpleFeature feature = it.next(); String joinedKeyValue = toHashableString(feature.getAttribute(joinedKey)); if (joinedKeyValue != null) { cache.put(joinedKeyValue, feature); } else { log.warn("Feature " + feature.getID() + " has null value for its joinedKey (" + joinedKey + ")"); } } it.close(); } catch (IOException e) { throw new RuntimeException("Could not cache values for joined shapefile", e); } }
/** * Retreives the bounds for a feature source. * * <p>If the feautre source can calculate the bounds directly, those bounds are returned. * Otherwise, the underlying feature collection is retreived and asked to calculate bounds. If * that fails, an empty envelope is returned. * * @param fs The feature source. * @return The bounds. * @throws IOException Execption calculating bounds on feature source. */ public static ReferencedEnvelope getBoundingBoxEnvelope( FeatureSource<? extends FeatureType, ? extends Feature> fs) throws IOException { ReferencedEnvelope ev = fs.getBounds(); if ((ev == null) || ev.isNull()) { try { ev = fs.getFeatures().getBounds(); } catch (Throwable t) { LOGGER.log( Level.FINE, "Could not compute the data bounding box. Returning an empty envelope", t); ev = new ReferencedEnvelope(fs.getSchema().getCoordinateReferenceSystem()); } } return ev; } }
/** * The function is run periodically by the update manager. * The extending class should provide the getNote method. It is not implemented here * as the requirements for different updaters can be vastly different dependent on the data source. */ @Override protected void runPolling() throws IOException{ LOG.info("Run WFS polling updater with hashcode: {}", this.hashCode()); notesForEdge = HashMultimap.create(); uniqueMatchers = new HashMap<>(); FeatureIterator<SimpleFeature> features = featureSource.getFeatures(query).features(); while ( features.hasNext()){ SimpleFeature feature = features.next(); if (feature.getDefaultGeometry() == null) continue; Alert alert = getNote(feature); if (alert == null) continue; Geometry geom = (Geometry) feature.getDefaultGeometry(); Geometry searchArea = geom.buffer(SEARCH_RADIUS_DEG); Collection<Edge> edges = graph.streetIndex.getEdgesForEnvelope(searchArea.getEnvelopeInternal()); for(Edge edge: edges){ if (edge instanceof StreetEdge && !searchArea.disjoint(edge.getGeometry())) { addNote(edge, alert, NOTE_MATCHER); } } } updaterManager.execute(new WFSGraphWriter()); }
final Query mixed = mixQueries(query, readQuery); int limitedAttributeSize = mixed.getProperties() != null ? mixed.getProperties().size() : 0; final FeatureCollection<T, F> fc = delegate.getFeatures(mixed); if (fc == null) { return null;
FeatureCollection fc = fs.getFeatures(query); return fc.getSchema();
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); dq.setFilter(ff.greater(ff.property("PERSONS"), ff.literal(20000000))); FeatureCollection fc = fs.getFeatures(dq); if (fc.size() != 1) { logger.log(
.getFeatures(query); features = featureSource.getFeatures(query);
@Test public void testForce() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.BASIC_POLYGONS.getLocalPart()); assertEquals("EPSG:4269", fti.getSRS()); assertEquals(ProjectionPolicy.FORCE_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4269"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); fi.close(); assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testLeaveNative() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LINES.getLocalPart()); assertEquals("EPSG:3004", fti.getSRS()); assertEquals(ProjectionPolicy.NONE, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:32615"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that the geometry was left in tact Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertTrue(g.equalsExact(WKT.read("LINESTRING(500125 500025,500175 500075)"))); fi.close(); assertEquals(CRS.decode("EPSG:32615"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testReproject() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart()); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was actually reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse( g.equalsExact( WKT.read( "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
((FeatureTypeInfo) layers.get(5).getResource()) .getFeatureSource(null, null) .getFeatures() .features() .next();
@Test public void testWithRename() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName("MyPoints"); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse(g.equalsExact(WKT.read("POINT(500050 500050)"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testDefaultGeometry() throws IOException { FeatureTypeInfo featureType = getCatalog().getResourceByName("cdf", "Nulls", FeatureTypeInfo.class); GeometryDescriptor schemaDefaultGeometry = featureType.getFeatureType().getGeometryDescriptor(); FeatureIterator i = featureType.getFeatureSource(null, null).getFeatures().features(); GeometryDescriptor featureDefaultGeometry = i.next().getDefaultGeometryProperty().getDescriptor(); assertNotNull(schemaDefaultGeometry); assertNotNull(featureDefaultGeometry); assertEquals("pointProperty", schemaDefaultGeometry.getLocalName()); assertEquals(schemaDefaultGeometry, featureDefaultGeometry); } }
public void testGetFeatureId() throws Exception { FeatureSource fsView = dataStore.getFeatureSource("riverReducedPk"); assertFalse(fsView instanceof FeatureStore); assertEquals(1, fsView.getCount(Query.ALL)); try (FeatureIterator<SimpleFeature> it = fsView.getFeatures().features()) { assertTrue(it.hasNext()); SimpleFeature sf = it.next(); // check the primary key is build out of the fid attribute assertEquals("riverReducedPk.0", sf.getID()); } }