public ReprojectingFeatureCollection( SimpleFeatureCollection delegate, CoordinateReferenceSystem target) throws SchemaException, OperationNotFoundException, FactoryRegistryException, FactoryException { super(delegate); this.target = target; this.schema = FeatureTypes.transform(delegate.getSchema(), target); // create transform cache transformers = new HashMap(); // cache "default" transform CoordinateReferenceSystem source = delegate.getSchema().getCoordinateReferenceSystem(); if (source != null) { MathTransform tx = ReferencingFactoryFinder.getCoordinateOperationFactory(hints) .createOperation(source, target) .getMathTransform(); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); transformers.put(source, transformer); } else { throw new RuntimeException( "Source was null in trying to create a reprojected feature collection!"); } }
/** * Flattens a SimpleFeatureCollection that may contain SimpleFeatures as attributes of other * features. * * @param collection The input SimpleFeatureCollection * @return A SimpleFeatureCollection whose features have no SimpleFeature attributes, or the * original one, if no SimpleFeature attributes were found */ public static SimpleFeatureCollection flatten(SimpleFeatureCollection collection) { SimpleFeatureType schema = collection.getSchema(); // collect the attributes List<AttributeDescriptor> attributeDescriptors = new ArrayList<AttributeDescriptor>(); scanAttributeDescriptors(attributeDescriptors, schema, null); // build the flattened feature type SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(schema.getName()); for (AttributeDescriptor desc : attributeDescriptors) builder.add(desc); SimpleFeatureType flattenedType = builder.buildFeatureType(); // if the number of attributes is the same, we did not encounter a new attribute if (collection.getSchema().getAttributeCount() == flattenedType.getAttributeCount()) { return collection; } return new FlatteningFeatureCollection(collection, flattenedType); }
public SimpleFeatureCollection subCollection(Filter filter) { // reproject the filter to the delegate native crs CoordinateReferenceSystem crs = getSchema().getCoordinateReferenceSystem(); CoordinateReferenceSystem crsDelegate = delegate.getSchema().getCoordinateReferenceSystem(); if (crs != null) { DefaultCRSFilterVisitor defaulter = new DefaultCRSFilterVisitor(FF, crs); filter = (Filter) filter.accept(defaulter, null); if (crsDelegate != null && !CRS.equalsIgnoreMetadata(crs, crsDelegate)) { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(FF, delegate.getSchema()); filter = (Filter) filter.accept(reprojector, null); } } SimpleFeatureCollection sub = delegate.subCollection(filter); if (sub != null) { try { ReprojectingFeatureCollection wrapper = new ReprojectingFeatureCollection(sub, target); wrapper.setDefaultSource(defaultSource); return wrapper; } catch (Exception e) { throw new RuntimeException(e); } } return null; }
} else { SimpleFeatureType schema = collections.get(0).getSchema(); result = new CompositeFeatureCollection(collections, schema);
SimpleFeatureType target = SimpleFeatureTypeBuilder.retype( sfc.getSchema(), mixed.getPropertyNames()); ReTypingFeatureCollection retyped = new ReTypingFeatureCollection(sfc, target); return (FeatureCollection) SecuredObjects.secure(retyped, policy);
/** * TEST for GEOS-8176 [https://osgeo-org.atlassian.net/browse/GEOS-8176]. * * <p>Make sure that the subCollection returned is retyped. * * @author Ian Turton */ @Test public void testSubCollectionRetyping() { RetypingFeatureCollection retypedCollection = new RetypingFeatureCollection(collection, renamedSchema); SimpleFeatureCollection subCollection = retypedCollection.subCollection(Filter.INCLUDE); assertSame(renamedSchema, subCollection.getSchema()); } }
public SimpleFeatureType getSchema() { return collection.getSchema(); }
public ClippingFeatureCollection( SimpleFeatureCollection delegate, Geometry clip, boolean preserveZ) { super(delegate); this.clip = clip; this.targetSchema = buildTargetSchema(delegate.getSchema()); this.preserveZ = preserveZ; }
public SpatialIndexFeatureCollection(SimpleFeatureCollection copy) throws IOException { this(copy.getSchema()); addAll(copy); }
/** * Constructor * * @param features the feature collection to load into the table */ public FeatureCollectionTableModel(SimpleFeatureCollection features) { this.load = new TableWorker(features); load.execute(); this.schema = features.getSchema(); }
public ReprojectingFeatureCollection( SimpleFeatureCollection delegate, CoordinateReferenceSystem target) { this( delegate, delegate.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem(), target); }
@Test public void testFeautureSourceFidFilter() throws Exception { // grab the last feature in the collection (there are more than one) SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); // build a filter that will retrieve that feature only FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); final String fid = RENAMED + ".1107531701011"; Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); SimpleFeatureCollection fc = fs.getFeatures(new Query(RENAMED, fidFilter)); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertEquals(1, fc.size()); FeatureIterator<SimpleFeature> it = fc.features(); assertTrue(it.hasNext()); SimpleFeature sf = it.next(); assertFalse(it.hasNext()); it.close(); assertEquals(fid, sf.getID()); }
@Test public void testSimpleRename() throws IOException { SimpleFeatureSource fs = store.getFeatureSource(BUILDINGS.getLocalPart()); SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(fs.getSchema()); tb.setName("houses"); SimpleFeatureType target = tb.buildFeatureType(); SimpleFeatureSource retyped = RetypingFeatureSource.getRetypingSource(fs, target); assertTrue(retyped instanceof SimpleFeatureLocking); assertEquals(target, retyped.getSchema()); assertEquals(target, ((DataStore) retyped.getDataStore()).getSchema("houses")); assertEquals(target, retyped.getFeatures().getSchema()); SimpleFeatureIterator it = retyped.getFeatures().features(); SimpleFeature f = it.next(); it.close(); assertEquals(target, f.getType()); }
@Test public void testFeautureSourceFidFilter() throws Exception { // grab the last feature in the collection (there are more than one) SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); // build a filter that will retrieve that feature only FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); final String fid = RENAMED + ".f001"; Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); SimpleFeatureCollection fc = fs.getFeatures(new Query(RENAMED, fidFilter)); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertEquals(1, fc.size()); FeatureIterator<SimpleFeature> it = fc.features(); assertTrue(it.hasNext()); SimpleFeature sf = it.next(); assertFalse(it.hasNext()); it.close(); assertEquals(fid, sf.getID()); }
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(RENAMED, fs.getSchema().getName().getLocalPart()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(RENAMED, sf.getFeatureType().getName().getLocalPart()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(primitive, fs.getSchema()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(primitive, fc.getSchema()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(primitive, sf.getFeatureType()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); // check mappings occurred assertEquals("description-f001", sf.getAttribute("description")); assertTrue( new WKTReader() .read("MULTIPOINT(39.73245 2.00342)") .equalsExact((Geometry) sf.getAttribute("pointProperty"))); assertEquals(Long.valueOf(155), sf.getAttribute("intProperty")); assertNull(sf.getAttribute("newProperty")); }
public ZonalStatisticsIterator( SimpleFeatureIterator zones, String dataAttribute, SimpleFeatureCollection data, SimpleFeatureType targetSchema) { this.zones = zones; this.dataAttribute = dataAttribute; this.data = data; this.builder = new SimpleFeatureBuilder(targetSchema); this.dataGeomName = data.getSchema().getGeometryDescriptor().getLocalName(); }
public IncludedFeatureIterator( SimpleFeatureIterator delegate, SimpleFeatureCollection firstFeatures, SimpleFeatureCollection secondFeatures, SimpleFeatureType schema) { this.delegate = delegate; this.firstFeatures = firstFeatures; this.secondFeatures = secondFeatures; this.fb = new SimpleFeatureBuilder(schema); this.dataGeomName = this.firstFeatures.getSchema().getGeometryDescriptor().getLocalName(); }
public void testSchema() throws Exception { SimpleFeatureCollection original = featureCollection; assertEquals(wgs84, original.getSchema().getCoordinateReferenceSystem()); SimpleFeatureCollection forced = new ForceCoordinateSystemFeatureResults(original, utm32n); assertEquals(utm32n, forced.getSchema().getCoordinateReferenceSystem()); }