public SimpleFeatureType getSchema() { return delegate.getSchema(); }
/** * Builds a retyping wrapper * * @param wrapped * @param targetTypeName * @param targetSchema The target schema can have a different name and less attributes than the * original one */ public static SimpleFeatureSource getRetypingSource( SimpleFeatureSource wrapped, SimpleFeatureType targetSchema) throws IOException { FeatureTypeMap map = new FeatureTypeMap(wrapped.getSchema(), targetSchema); if (wrapped instanceof SimpleFeatureLocking) { return new RetypingFeatureLocking((SimpleFeatureLocking) wrapped, map); } else if (wrapped instanceof SimpleFeatureStore) { return new RetypingFeatureStore((SimpleFeatureStore) wrapped, map); } else { return new RetypingFeatureSource(wrapped, map); } }
@Test public void testGetTypeNamesCalls() throws Exception { SimpleFeatureType orig = createNiceMock(SimpleFeatureType.class); expect(orig.getTypeName()).andReturn("orig").anyTimes(); replay(orig); SimpleFeatureType wrapped = createNiceMock(SimpleFeatureType.class); expect(wrapped.getTypeName()).andReturn("wrapped").anyTimes(); replay(wrapped); // ensure that getTypeNames() never called DataStore ds = createMock(DataStore.class); SimpleFeatureSource fs = createMock(SimpleFeatureSource.class); expect(fs.getSchema()).andReturn(orig).anyTimes(); expect(fs.getDataStore()).andReturn(ds).anyTimes(); expect(fs.getFeatures(new Query(orig.getTypeName(), Filter.INCLUDE))) .andReturn(null) .once(); replay(fs); SimpleFeatureSource rts = RetypingFeatureSource.getRetypingSource(fs, wrapped); rts.getFeatures(); } }
@Override public String toString() { return "Transformer[ feature source= " + source + " , type=" + source.getSchema() + ", definitions=" + definitions; } }
private Query reprojectFilter(Query query) throws IOException { SimpleFeatureType nativeFeatureType = source.getSchema(); final GeometryDescriptor geom = nativeFeatureType.getGeometryDescriptor();
public TransformFeatureCollection( SimpleFeatureSource source, Transformer transformer, Query query) { super(retypeSchema(source.getSchema(), query)); this.source = source; this.transformer = transformer; this.query = query; }
@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()); }
@Override public SimpleFeatureSource getFeatureSource(String typeName) throws IOException { SimpleFeatureType schema = source.getSchema(); if (schema.getName().getLocalPart().equals(typeName)) { return source; } else { throw new IOException("Schema '" + typeName + "' does not exist."); } }
@Override public SimpleFeatureSource getFeatureSource(Name typeName) throws IOException { SimpleFeatureType schema = source.getSchema(); if (schema.getName().equals(typeName)) { return source; } else { throw new IOException("Schema '" + typeName + "' does not exist."); } }
} else { CoordinateReferenceSystem resultCRS = null; GeometryDescriptor gd = fs.getSchema().getGeometryDescriptor(); CoordinateReferenceSystem nativeCRS = gd != null ? gd.getCoordinateReferenceSystem() : null;
@Override public SimpleFeatureType getSchema(Name name) throws IOException { SimpleFeatureType schema = source.getSchema(); if (schema.getName().equals(name)) { return schema; } else { return null; } }
public DataStoreAdaptor(SimpleFeatureSource source) { this.source = source; this.schema = source.getSchema(); this.name = schema.getName(); this.typeName = name.getLocalPart(); }
@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)); }
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.init(fsp.getSchema()); tb.remove("surfaceProperty"); // the store cannot create multi-geom tables it seems tb.remove("curveProperty"); // the store cannot create multi-geom tables it seems
@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")); }
private BBOX bboxFilter(Envelope bbox) { return ff.bbox( wrapped.getSchema().getGeometryDescriptor().getLocalName(), bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY(), null); }
public void testCreateView() throws Exception { String[] propNames = {"id", "geom"}; Query query = new Query(roadType.getTypeName(), Filter.INCLUDE, 100, propNames, null); SimpleFeatureSource source = DataUtilities.source(roadFeatures); SimpleFeatureSource view = DataUtilities.createView(source, query); assertNotNull(view); List<AttributeDescriptor> desc = view.getSchema().getAttributeDescriptors(); assertTrue(desc.size() == propNames.length); assertTrue(desc.get(0).getLocalName().equals(propNames[0])); assertTrue(desc.get(1).getLocalName().equals(propNames[1])); }
public void testDataStore() throws IOException { SimpleFeatureSource features = DataUtilities.source(roadFeatures); Name name = features.getName(); String typeName = name.getLocalPart(); DataStore store = DataUtilities.dataStore(features); assertSame(features.getSchema(), store.getSchema(name)); assertSame(features.getSchema(), store.getSchema(typeName)); assertSame(features, store.getFeatureSource(name)); assertSame(features, store.getFeatureSource(typeName)); assertEquals(name, store.getNames().get(0)); assertEquals(typeName, store.getTypeNames()[0]); }
public void testGetFeatureSourceRiver() throws NoSuchElementException, IOException { SimpleFeatureSource river = data.getFeatureSource("river"); assertSame(riverType, river.getSchema()); assertSame(data, river.getDataStore()); SimpleFeatureCollection all = river.getFeatures(); assertEquals(2, all.size()); assertEquals(riverBounds, all.getBounds()); assertTrue("rivers", covers(all.features(), riverFeatures)); SimpleFeatureCollection expected = DataUtilities.collection(riverFeatures); assertCovers("all", expected, all); assertEquals(riverBounds, all.getBounds()); }