/** Returns a feature collection with a simplified US geometry and PERSONS count */ public static ListFeatureCollection getSimplifiedStatesCollection() throws SchemaException, IOException { SimpleFeatureType schema = DataUtilities.createType( "states", "the_geom:MultiPolygon,STATE_ABBR:String,PERSONS:Double"); try (BufferedReader br = new BufferedReader( new InputStreamReader( EqualAreaListVisitorTest.class.getResourceAsStream( "states.properties")))) { List<SimpleFeature> featureList = br.lines() .map(line -> DataUtilities.createFeature(schema, line)) .collect(Collectors.toList()); return new ListFeatureCollection(schema, featureList); } }
/** Test createType and createFeature methods as per GEOT-4150 */ public void testEncode() throws Exception { SimpleFeatureType featureType = 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)"); String spec = DataUtilities.encodeType(featureType); assertEquals("id:Integer,party:String,geom:Geometry:srid=4326", spec); String text = DataUtilities.encodeFeature(feature1); assertEquals("fid1=1|Jody Garnett\\nSteering Committee|POINT (1 2)", text); }
SimpleFeature feature = DataUtilities.createFeature(featureType, "1|POINT(1 2)"); ListFeatureCollection features = new ListFeatureCollection(featureType); features.add(feature);
"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)");
protected void addFeature( int id, Date time, Double elevation, Date referenceTime, Double scanningAngle) throws IOException { FeatureTypeInfo timeElevationCustom = getCatalog().getFeatureTypeByName(TIME_ELEVATION_CUSTOM.getLocalPart()); FeatureStore fs = (FeatureStore) timeElevationCustom.getFeatureSource(null, null); SimpleFeatureType type = (SimpleFeatureType) timeElevationCustom.getFeatureType(); MemoryFeatureCollection coll = new MemoryFeatureCollection(type); StringBuffer content = new StringBuffer(); content.append(id); content.append('|'); content.append(time.toString()); content.append('|'); content.append(elevation); content.append('|'); content.append(referenceTime.toString()); content.append('|'); content.append(scanningAngle); SimpleFeature f = DataUtilities.createFeature(type, content.toString()); coll.add(f); org.geotools.data.Transaction tx = fs.getTransaction(); fs.addFeatures(coll); tx.commit(); }
protected void addFeature(int id, Date time, Double elevation) throws IOException { FeatureTypeInfo timeWithStartEnd = getCatalog().getFeatureTypeByName(TIME_WITH_START_END.getLocalPart()); FeatureStore fs = (FeatureStore) timeWithStartEnd.getFeatureSource(null, null); SimpleFeatureType type = (SimpleFeatureType) timeWithStartEnd.getFeatureType(); MemoryFeatureCollection coll = new MemoryFeatureCollection(type); StringBuffer content = new StringBuffer(); content.append(id); content.append('|'); content.append(time.toString()); content.append("||"); content.append(elevation); content.append('|'); SimpleFeature f = DataUtilities.createFeature(type, content.toString()); coll.add(f); org.geotools.data.Transaction tx = fs.getTransaction(); fs.addFeatures(coll); tx.commit(); }
protected void addFeature(int id, Date time, Double elevation) throws IOException { FeatureTypeInfo timeWithStartEnd = getCatalog().getFeatureTypeByName(ELEVATION_WITH_START_END.getLocalPart()); FeatureStore fs = (FeatureStore) timeWithStartEnd.getFeatureSource(null, null); SimpleFeatureType type = (SimpleFeatureType) timeWithStartEnd.getFeatureType(); MemoryFeatureCollection coll = new MemoryFeatureCollection(type); StringBuffer content = new StringBuffer(); content.append(id); content.append('|'); content.append(time.toString()); content.append("||"); content.append(elevation); content.append('|'); SimpleFeature f = DataUtilities.createFeature(type, content.toString()); coll.add(f); org.geotools.data.Transaction tx = fs.getTransaction(); fs.addFeatures(coll); tx.commit(); }
@Test public void testFeatureScreenMapPredicate() throws SchemaException { SimpleFeatureType lineType = DataUtilities.createType("LINE", "centerline:LineString,name:\"\",id:0"); SimpleFeature feature1 = DataUtilities.createFeature(lineType, "LINESTRING(0.1 0.1, 0.9 0.9)|dave|7"); SimpleFeature feature2 = DataUtilities.createFeature(lineType, "LINESTRING(0.1 0.1, 0.9 0.9)|dave|7"); ScreenMap sm = new ScreenMap(0, 0, 100, 100, IdentityTransform.create(2)); sm.setSpans(1, 1); //both are in the same pixel assertTrue(sm.canSimplify(((Geometry) feature1.getDefaultGeometry()).getEnvelopeInternal())); assertTrue(sm.canSimplify(((Geometry) feature2.getDefaultGeometry()).getEnvelopeInternal())); FeatureScreenMapPredicate smp = new FeatureScreenMapPredicate(sm); //first one goes through assertTrue(smp.apply(feature1)); //second one doesn't assertFalse(smp.apply(feature2)); }
@Test public void testFeatureScreenMapPredicate() throws SchemaException { SimpleFeatureType lineType = DataUtilities.createType("LINE", "centerline:LineString,name:\"\",id:0"); SimpleFeature feature1 = DataUtilities.createFeature(lineType, "LINESTRING(0.1 0.1, 0.9 0.9)|dave|7"); SimpleFeature feature2 = DataUtilities.createFeature(lineType, "LINESTRING(0.1 0.1, 0.9 0.9)|dave|7"); ScreenMap sm = new ScreenMap(0, 0, 100, 100, IdentityTransform.create(2)); sm.setSpans(1, 1); //both are in the same pixel assertTrue(sm.canSimplify(((Geometry) feature1.getDefaultGeometry()).getEnvelopeInternal())); assertTrue(sm.canSimplify(((Geometry) feature2.getDefaultGeometry()).getEnvelopeInternal())); FeatureScreenMapPredicate smp = new FeatureScreenMapPredicate(sm); //first one goes through assertTrue(smp.apply(feature1)); //second one doesn't assertFalse(smp.apply(feature2)); }
@Test public void testGeometryReplacer() throws SchemaException, TransformException { SimpleFeatureType lineType = DataUtilities.createType("LINE", "centerline:LineString,name:\"\",id:0"); SimpleFeature feature1 = DataUtilities.createFeature(lineType, "LINESTRING(0.1 0.1, 0.9 0.9)|dave|7"); SimpleFeature feature2 = DataUtilities.createFeature(lineType, "LINESTRING(0 0,10 10)|dave|7");
@Test public void testGeometryReplacer() throws SchemaException, TransformException { SimpleFeatureType lineType = DataUtilities.createType("LINE", "centerline:LineString,name:\"\",id:0"); SimpleFeature feature1 = DataUtilities.createFeature(lineType, "LINESTRING(0.1 0.1, 0.9 0.9)|dave|7"); SimpleFeature feature2 = DataUtilities.createFeature(lineType, "LINESTRING(0 0,10 10)|dave|7");