public Object convert(Object source, Class target) throws Exception { if (source instanceof GeometryAttribute) { return Converters.convert(((GeometryAttribute) source).getValue(), target); } return null; } };
@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()); }
@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()); }
@Override public void setDefaultGeometryProperty(GeometryAttribute geometryAttribute) { if (geometryAttribute != null) setDefaultGeometry(geometryAttribute.getValue()); else setDefaultGeometry(null); }
public void setDefaultGeometryProperty(GeometryAttribute geometryAttribute) { if (geometryAttribute != null) setDefaultGeometry(geometryAttribute.getValue()); else setDefaultGeometry(null); }
public void setDefaultGeometryProperty(GeometryAttribute defaultGeometry) { if (defaultGeometry != null) setDefaultGeometry(defaultGeometry.getValue()); else setDefaultGeometry(null); }
public Object evaluate(Feature feature) { if (feature == null) { return null; } else if (feature instanceof SimpleFeature) { SimpleFeature sf = (SimpleFeature) feature; return geometry(sf.getDefaultGeometry()); } else { GeometryAttribute ga = feature.getDefaultGeometryProperty(); if (ga == null) { return null; } else { return geometry(ga.getValue()); } } }
/** * Return gml:boundedBy property if wanted. * * @param feature feature for which bounds might be required * @param configuration encoder configuration, used to suppress feature bounds * @return the feature bounds, or null if none or unwanted */ private BoundingBox getBoundedBy(Feature feature, Configuration configuration) { // check for flag not to include bounds if (configuration.hasProperty(GMLConfiguration.NO_FEATURE_BOUNDS)) { return null; } else { BoundingBox bounds = feature.getBounds(); // do a check for the case where the feature has no geometry properties if (bounds.isEmpty() && (feature.getDefaultGeometryProperty() == null || feature.getDefaultGeometryProperty().getValue() == null)) { return null; } else { return bounds; } } }
/** * Finds the geometric attribute requested by the symbolizer * * @param drawMe The feature * @param s * <p>/** Finds the geometric attribute requested by the symbolizer * @param drawMe The feature * @param s The symbolizer * @return The geometry requested in the symbolizer, or the default geometry if none is * specified */ private org.locationtech.jts.geom.Geometry findGeometry(Object drawMe, Symbolizer s) { Expression geomExpr = s.getGeometry(); // get the geometry Geometry geom; if (geomExpr == null) { if (drawMe instanceof SimpleFeature) { geom = (Geometry) ((SimpleFeature) drawMe).getDefaultGeometry(); } else if (drawMe instanceof Feature) { geom = (Geometry) ((Feature) drawMe).getDefaultGeometryProperty().getValue(); } else { geom = defaultGeometryPropertyName.evaluate(drawMe, Geometry.class); } } else { geom = geomExpr.evaluate(drawMe, Geometry.class); } return geom; }
/** * Stolen from {@link ReprojectFeatureResults}. * * @see org.geotools.feature.FeatureCollection#getBounds() */ public ReferencedEnvelope getBounds() { FeatureIterator<Feature> features = features(); try { Envelope newBBox = new Envelope(); Envelope internal; Feature feature; while (features.hasNext()) { feature = features.next(); final Geometry geometry = feature.getDefaultGeometryProperty() != null ? ((Geometry) feature.getDefaultGeometryProperty().getValue()) : null; if (geometry != null) { internal = geometry.getEnvelopeInternal(); newBBox.expandToInclude(internal); } } return ReferencedEnvelope.reference(newBBox); } catch (Exception e) { throw new RuntimeException("Exception occurred while computing bounds", e); } finally { features.close(); } }
public void testDefaultGeometryProperty() { assertTrue( "expected GeometryAttribute, got " + feature.getProperty("the_geom").getClass().getName(), feature.getProperty("the_geom") instanceof GeometryAttribute); GeometryAttribute defaultGeometryProperty = feature.getDefaultGeometryProperty(); assertNotNull(defaultGeometryProperty); assertNull(defaultGeometryProperty.getValue()); assertNotNull(defaultGeometryProperty.getDescriptor()); assertTrue(defaultGeometryProperty.getDescriptor() instanceof GeometryDescriptor); }
.getCoordinateReferenceSystem(); defaultGeometry = feature.getDefaultGeometryProperty().getValue();
LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty().getValue()); double featureLength = featureToMeasure - featureFromMeasure; double startOffset = measure - featureFromMeasure; double calcLength = ((Geometry) feature.getDefaultGeometryProperty().getValue()).getLength(); if (calcLength == 0) { LOGGER.info("Edge feature has zero length");
fi = features.features(); while (fi.hasNext()) { Geometry g = (Geometry) fi.next().getDefaultGeometryProperty().getValue(); collector.add(g);
while (featureIterator.hasNext()) { SimpleFeature f = (SimpleFeature) featureIterator.next(); if (f.getDefaultGeometryProperty().getValue() == null) continue; DistanceOp op = new DistanceOp( point, (Geometry) f.getDefaultGeometryProperty().getValue()); Coordinate[] co = op.closestPoints(); double[] co0 = LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) nearestFeature.getDefaultGeometryProperty().getValue()); double lineIndex = lengthIndexedLine.indexOf(nearestCoords[1]); double lineLength = ((Geometry) nearestFeature.getDefaultGeometryProperty().getValue()) .getLength(); Double featureFromMeasure =
while (featureIterator.hasNext()) { SimpleFeature f = (SimpleFeature) featureIterator.next(); if (f.getDefaultGeometryProperty().getValue() == null) continue; DistanceOp op = new DistanceOp( point, (Geometry) f.getDefaultGeometryProperty().getValue()); Coordinate[] co = op.closestPoints(); double[] co0 =
while (featureIterator.hasNext()) { SimpleFeature f = (SimpleFeature) featureIterator.next(); if (f.getDefaultGeometryProperty().getValue() == null) continue; DistanceOp op = new DistanceOp( point, (Geometry) f.getDefaultGeometryProperty().getValue()); Coordinate[] co = op.closestPoints(); double[] co0 =