public void testAppend() throws Exception { SimpleFeatureType type = DataUtilities.createType("trees", "the_geom:Point,FID:String,NAME:String"); SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(type); WKTReader reader = new WKTReader(); sfb.set("the_geom", reader.read("POINT (0.002 0.0008)")); sfb.set("FID", "023"); sfb.set("NAME", "Old oak"); SimpleFeature feature = sfb.buildFeature(null); SimpleFeatureCollection fc = DataUtilities.collection(feature);
SecuredSimpleFeatureCollection( FeatureCollection<SimpleFeatureType, SimpleFeature> delegate, WrapperPolicy policy) { super(delegate, policy); if (policy.getLimits() instanceof VectorAccessLimits) { List<PropertyName> properties = ((VectorAccessLimits) policy.getLimits()).getReadAttributes(); if (properties == null) { this.readSchema = getSchema(); } else { List<String> names = new ArrayList<String>(); for (PropertyName property : properties) { names.add(property.getPropertyName()); } String[] nameArray = (String[]) names.toArray(new String[names.size()]); try { this.readSchema = DataUtilities.createSubType(getSchema(), nameArray); } catch (SchemaException e) { // should just not happen throw new RuntimeException(e); } } } else { this.readSchema = getSchema(); } }
/** Traverses the filter and returns any encountered property names. */ public static String[] attributeNames(Filter filter) { return attributeNames(filter, null); }
public void testComposeMany() { SimpleFeatureCollection roads = DataUtilities.collection(roadFeatures); SimpleFeatureCollection rivers = DataUtilities.collection(riverFeatures); SimpleFeatureCollection lakes = DataUtilities.collection(lakeFeatures); CompositeFeatureCollection fc = new CompositeFeatureCollection(Arrays.asList(roads, rivers, lakes)); // 3 roads, 2 rivers, 1 lake assertEquals(6, fc.size()); assertEquals( new ReferencedEnvelope(1, 16, 0, 10, riverType.getCoordinateReferenceSystem()), fc.getBounds()); assertEquals(roadFeatures[0], DataUtilities.first(fc)); } }
while (featureIterator.hasNext()) { final SimpleFeature feature = featureIterator.next(); final Point pt = (Point) feature.getDefaultGeometry(); coordList.add(pt.getCoordinate()); final GeometryFactory geometryFactory = new GeometryFactory(); SimpleFeatureType featureType; SimpleFeatureBuilder featureBuilder; featureType = DataUtilities.createType("Geometry", "geometry:Polygon"); featureBuilder = new SimpleFeatureBuilder(featureType); feature = featureBuilder.buildFeature(Integer.toString(coordList.size() + 1)); final LinearRing polygon = geometryFactory.createLinearRing(coordList.toArray(new Coordinate[coordList.size()])); feature.setDefaultGeometry(polygon); } else { featureType = DataUtilities.createType("Geometry", "geometry:LineString"); featureBuilder = new SimpleFeatureBuilder(featureType); feature = featureBuilder.buildFeature(Integer.toString(coordList.size() + 1)); final LineString lineString = geometryFactory.createLineString(coordList.toArray(new Coordinate[coordList.size()])); feature.setDefaultGeometry(lineString);
protected void addFeature(SimpleFeatureType featureType, JDBCFeatureStore features) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureType); b.add("four"); b.add(new GeometryFactory().createPoint(new Coordinate(4, 4))); SimpleFeature f = b.buildFeature(null); features.addFeatures(DataUtilities.collection(f)); // pattern match to handle the multi primary key case assertTrue( ((String) f.getUserData().get("fid")) .matches(tname(featureType.getTypeName()) + ".4(\\..*)?")); }
SimpleFeatureCollection expected = DataUtilities.collection(td.roadFeatures); e.include(td.roadFeatures[0].getBounds()); e.include(td.roadFeatures[1].getBounds()); Query query = new Query(tname("road"), td.rd12Filter, new String[] {aname("name")}); assertEquals(1, half.getSchema().getAttributeCount()); SimpleFeatureType actual = reader.next().getFeatureType(); assertEquals(type.getName(), actual.getName()); assertEquals(type.getAttributeCount(), actual.getAttributeCount());
assertEquals(roadBounds, all.getBounds()); SimpleFeatureCollection expected = DataUtilities.collection(roadFeatures); assertEquals(some.getSchema(), road.getSchema()); Query query = new Query("road", rd12Filter, new String[] {"name", "geom"}); assertEquals(2, half.getSchema().getAttributeCount()); SimpleFeatureIterator reader = half.features(); SimpleFeatureType type = half.getSchema(); SimpleFeatureType actual = half.getSchema(); assertEquals(type.getTypeName(), actual.getTypeName()); assertEquals(type.getName(), actual.getName()); assertEquals(type.getAttributeCount(), actual.getAttributeCount());
@Before public void setUp() throws Exception { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("render-test"); ftb.add("the_geom", Point.class, DefaultGeographicCRS.WGS84); ftb.setDefaultGeometry("the_geom"); ftb.add("name", String.class); featureType = ftb.buildFeatureType(); GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(featureType); fb.set("the_geom", gf.createPoint(new Coordinate(10, 10))); fb.set("name", "The name"); feature = fb.buildFeature(null); File shpFile = new File( "./target/screenMapTest/" + feature.getFeatureType().getName().getLocalPart() + ".shp"); shpFile.getParentFile().mkdirs(); ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put(ShapefileDataStoreFactory.URLP.key, shpFile.toURI().toURL()); shapeFileDataStore = dataStoreFactory.createNewDataStore(params); shapeFileDataStore.createSchema(feature.getFeatureType()); SimpleFeatureStore featureStore = (SimpleFeatureStore) shapeFileDataStore.getFeatureSource(shapeFileDataStore.getTypeNames()[0]); featureStore.addFeatures(DataUtilities.collection(feature)); RendererBaseTest.setupVeraFonts(); }
public void testAdd() throws IOException { SimpleFeatureBuilder b = new SimpleFeatureBuilder(collection.getSchema()); b.set(aname("intProperty"), Integer.valueOf(3)); b.set(aname("doubleProperty"), new Double(3.3)); b.set(aname("stringProperty"), "three"); b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(3, 3))); assertEquals(3, collection.size()); source.addFeatures(DataUtilities.collection(feature)); SimpleFeature f = (SimpleFeature) i.next(); if ("three".equals(f.getAttribute(aname("stringProperty")))) { assertEquals( ((Double) feature.getAttribute(aname("doubleProperty"))).doubleValue(), ((Double) f.getAttribute(aname("doubleProperty"))).doubleValue(), 1e-5); assertEquals(
public void testCreateSubType() throws Exception { SimpleFeatureType before = DataUtilities.createType("cities", "the_geom:Point:srid=4326,name:String"); SimpleFeatureType after = DataUtilities.createSubType(before, new String[] {"the_geom"}); assertEquals(1, after.getAttributeCount()); DataUtilities.createType( "cities", "the_geom:Point:srid=4326,name:String,population:Integer"); URI here = new URI("http://localhost/"); after = DataUtilities.createSubType( before, new String[] {"the_geom"}, DefaultGeographicCRS.WGS84, "now", here); assertEquals(here.toString(), after.getName().getNamespaceURI()); assertEquals("now", after.getName().getLocalPart()); assertEquals(DefaultGeographicCRS.WGS84, after.getCoordinateReferenceSystem()); assertEquals(1, after.getAttributeCount()); DataUtilities.createType( "cities", "the_geom:Point:srid=4326,name:String,population:Integer"); after = DataUtilities.createSubType(before, new String[] {"the_geom"}); assertEquals(before.getGeometryDescriptor(), after.getGeometryDescriptor()); DataUtilities.createType( "cities", "the_geom:Point:srid=4326,name:String,population:Integer"); after = DataUtilities.createSubType(before, new String[] {"the_geom"}); assertEquals(before.getGeometryDescriptor(), after.getGeometryDescriptor());
DataUtilities.createType( "Contact", "id:Integer,party:String,geom:Geometry:srid=4326"); SimpleFeature feature1 = DataUtilities.createFeature( featureType, "fid1=1|Jody Garnett\\nSteering Committee|POINT(1 2)"); SimpleFeature feature2 = DataUtilities.createFeature( featureType, "2|John Hudson\\|Hapless Victim|POINT(6 2)"); assertNotNull(featureType.getCoordinateReferenceSystem()); Geometry geometry = (Geometry) feature1.getAttribute("geom"); assertEquals("geom", 2.0, geometry.getCoordinate().y); assertEquals("fid preservation", "fid1", feature1.getID()); "newline decode check", "Jody Garnett\nSteering Committee", feature1.getAttribute("party")); assertEquals("escape check", "John Hudson|Hapless Victim", feature2.getAttribute("party"));
if (query.getStartIndex() != null && (query.getSortBy() == null || query.getSortBy().length == 0)) { Query dq = new Query(query); dq.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER}); if (query.getSortBy() != null && query.getSortBy().length != 0) { if (!canSort()) { reader = new SortedFeatureReader(DataUtilities.simple(reader), query); CoordinateReferenceSystem targetCRS = query.getCoordinateSystemReproject(); CoordinateReferenceSystem nativeCRS = reader.getFeatureType().getCoordinateReferenceSystem();
private void checkGMLPoiImport(File gmlFile, DataStoreInfo store) throws IOException, CQLException { SpatialFile importData = new SpatialFile(gmlFile); ImportContext context = importer.createContext(importData, store); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.READY, task.getState()); assertEquals(ImportContext.State.PENDING, context.getState()); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo fti = getCatalog().getResourceByName("poi", FeatureTypeInfo.class); assertNotNull(fti); SimpleFeatureType featureType = (SimpleFeatureType) fti.getFeatureType(); GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor(); assertEquals( "Expecting a point geometry", Point.class, geometryDescriptor.getType().getBinding()); assertEquals(4, featureType.getAttributeCount()); // read the features, check they are in the right order SimpleFeatureSource fs = (SimpleFeatureSource) fti.getFeatureSource(null, null); SimpleFeatureCollection fc = fs.getFeatures(CQL.toFilter("NAME = 'museam'")); assertEquals(1, fc.size()); SimpleFeature sf = DataUtilities.first(fc); Point p = (Point) sf.getDefaultGeometry(); assertEquals(-74.0104611, p.getX(), 1e-6); assertEquals(40.70758763, p.getY(), 1e-6); }
String[] propertyNames = query.getPropertyNames(); String defaultGeomName = schema.getGeometryDescriptor().getLocalName(); Filter filter = query.getFilter(); filter.accept(extractor, null); String[] filterAttnames = extractor.getAttributeNames(); .equals(defaultGeomName)))) { try { SimpleFeatureType newSchema = DataUtilities.createSubType( schema, propertyNames); newSchema = DataUtilities.createSubType( schema, requiredProperties);
public void testFixture() throws Exception { SimpleFeatureType type = DataUtilities.createType( "namespace.typename", "name:String,id:0,geom:MultiLineString"); assertEquals("namespace", "namespace", type.getName().getNamespaceURI()); assertEquals("typename", "typename", type.getTypeName()); assertEquals("attributes", 3, type.getAttributeCount()); assertEquals("a1", "name", type.getDescriptor(0).getLocalName()); assertEquals("a1", String.class, type.getDescriptor(0).getType().getBinding()); assertEquals("a2", "id", type.getDescriptor(1).getLocalName()); assertEquals("a2", Integer.class, type.getDescriptor(1).getType().getBinding()); assertEquals("a3", "geom", type.getDescriptor(2).getLocalName()); assertEquals("a3", MultiLineString.class, type.getDescriptor(2).getType().getBinding()); }
final String productIdColumn = granuleSchema .getAttributeDescriptors() .stream() .map(ad -> ad.getLocalName()) FF.equal(FF.property("eoParentIdentifier"), FF.literal(collectionId), true), FF.equal(FF.property("eoIdentifier"), FF.literal(productId), true)); SimpleFeature productFeature = DataUtilities.first(products.getFeatures(productFilter)); Query granulesQuery = new Query(); final Object dbProductId = productFeature.getAttribute("id"); granulesQuery.setFilter( FF.equal(FF.property(productIdColumn), FF.literal(dbProductId), true)); List<String> names = granuleSchema .getAttributeDescriptors() .stream() .map(ad -> ad.getLocalName()) .filter(s -> !s.equals(productIdColumn)) .collect(Collectors.toList()); granulesQuery.setPropertyNames(names);
indexSchema=DataUtilities.createType(mosaicConfiguration.getName(), schema); indexSchema=DataUtilities.createSubType(indexSchema, DataUtilities.attributeNames(indexSchema), actualCRS); final SimpleFeature feature = DataUtilities.template(indexSchema); feature.setAttribute(indexSchema.getGeometryDescriptor().getLocalName(), geomFactory.toGeometry(new ReferencedEnvelope((Envelope) envelope))); feature.setAttribute(runConfiguration.getLocationAttribute(), prepareLocation(fileBeingProcessed));
public void testFeatureEvents() throws Exception { SimpleFeatureStore store1 = (SimpleFeatureStore) data.getFeatureSource(roadFeatures[0].getFeatureType().getTypeName()); SimpleFeatureStore store2 = (SimpleFeatureStore) data.getFeatureSource(roadFeatures[0].getFeatureType().getTypeName()); store1.setTransaction(defaultTransaction); class Listener implements FeatureListener { factory.id(Collections.singleton(factory.featureId(feature.getID())))); assertEquals(1, listener1.events.size()); assertEquals(0, listener2.events.size()); listener2.events.clear(); store1.addFeatures(DataUtilities.collection(feature)); store2.addFeatures(DataUtilities.collection(feature));
public void testBetweenNegation() throws Exception { Not filter = ff.not( ff.between( ff.property(aname(B)), ff.property(aname(A)), ff.property(aname(C)))); ContentFeatureSource fs = dataStore.getFeatureSource(tname(ABC)); Query q = new Query(tname(ABC), filter); int count = fs.getCount(q); assertEquals(1, count); SimpleFeature f = DataUtilities.first(fs.getFeatures(q)); assertEquals("n_n_n", f.getAttribute(aname(NAME))); }