@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()); }
@Test public void testDefaultGeometry() throws IOException { FeatureTypeInfo featureType = getCatalog().getResourceByName("cdf", "Nulls", FeatureTypeInfo.class); GeometryDescriptor schemaDefaultGeometry = featureType.getFeatureType().getGeometryDescriptor(); FeatureIterator i = featureType.getFeatureSource(null, null).getFeatures().features(); GeometryDescriptor featureDefaultGeometry = i.next().getDefaultGeometryProperty().getDescriptor(); assertNotNull(schemaDefaultGeometry); assertNotNull(featureDefaultGeometry); assertEquals("pointProperty", schemaDefaultGeometry.getLocalName()); assertEquals(schemaDefaultGeometry, featureDefaultGeometry); } }
/** * 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; } } }
public void set(Object object, String xpath, Object value, Class target) throws IllegalAttributeException { if (object instanceof Feature) { final Feature f = (Feature) object; GeometryAttribute geom; if (value instanceof GeometryAttribute) { geom = (GeometryAttribute) value; f.setDefaultGeometryProperty(geom); } else if (value instanceof Geometry) { geom = f.getDefaultGeometryProperty(); geom.setValue(value); } else { throw new IllegalArgumentException("Argument is not a geometry: " + value); } } if (object instanceof FeatureType) { throw new IllegalAttributeException(null, "feature type is immutable"); } } }
public Object get(Object object, String xpath, Class target) { if (object instanceof Feature) return ((Feature) object).getDefaultGeometryProperty(); if (object instanceof FeatureType) { FeatureType ft = (FeatureType) object; GeometryDescriptor gd = ft.getGeometryDescriptor(); if (gd == null) { // look for any geometry descriptor for (PropertyDescriptor pd : ft.getDescriptors()) { if (Geometry.class.isAssignableFrom(pd.getType().getBinding())) { return pd; } } } return gd; } return 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()); } } }
/** * 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(); } }
Feature feature = (Feature) attribute; if (feature.getDefaultGeometryProperty() != null) { if (crs == null) { crs = feature.getDefaultGeometryProperty() .getType() .getCoordinateReferenceSystem(); defaultGeometry = feature.getDefaultGeometryProperty().getValue();
/** * 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; }
lineMerger.add( (Geometry) feature.getDefaultGeometryProperty() .getValue()); } else if (fromMeasure > featureFromMeasure new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty() .getValue()); double featureLength = featureToMeasure - featureFromMeasure; double calcLength = ((Geometry) feature.getDefaultGeometryProperty() .getValue()) .getLength(); new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty() .getValue()); double featureLength = featureToMeasure - featureFromMeasure; double calcLength = ((Geometry) feature.getDefaultGeometryProperty() .getValue()) .getLength();
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);
LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) nearestFeature.getDefaultGeometryProperty().getValue()); double lineIndex = lengthIndexedLine.indexOf(nearestCoords[1]); double lineLength = ((Geometry) nearestFeature.getDefaultGeometryProperty().getValue()) .getLength(); Double featureFromMeasure = + (featureToMeasure - featureFromMeasure) * lineIndex / lineLength; nearestFeature .getDefaultGeometryProperty() .setValue( geometryFactory.createPoint(
public Object get(Object object, String xpath, Class target) { if (object instanceof Feature) return ((Feature) object).getDefaultGeometryProperty(); if (object instanceof FeatureType) { FeatureType ft = (FeatureType) object; GeometryDescriptor gd = ft.getGeometryDescriptor(); if (gd == null) { // look for any geometry descriptor for (PropertyDescriptor pd : ft.getDescriptors()) { if (Geometry.class.isAssignableFrom(pd.getType().getBinding())) { return pd; } } } return gd; } return null; }
assertEquals("st.1", station1.getIdentifier().toString()); GeometryAttribute defaultGeom = station1.getDefaultGeometryProperty(); assertNotNull(defaultGeom); assertNotNull(defaultGeom.getValue());
assertEquals("st.1", station1.getIdentifier().toString()); GeometryAttribute defaultGeom = station1.getDefaultGeometryProperty(); assertNotNull(defaultGeom); assertNotNull(defaultGeom.getValue());
public Map<Integer, Geometry> getAllGeometriesInLayer(String layerName, String refSysName) throws DaoException{ FeatureIterator iterator = getFeatureIteratorForLayer(layerName, refSysName); if(!iterator.hasNext()){ iterator.close(); return null; } Feature feature; Map<Integer, Geometry> geometries = new HashMap<Integer, Geometry>(); while (iterator.hasNext()){ feature = iterator.next(); geometries.put((Integer)((SimpleFeatureImpl)feature).getAttribute("item_id"), (Geometry) feature.getDefaultGeometryProperty().getValue()); } iterator.close(); return geometries; }
public Map<Integer, Geometry> getAllGeometriesInLayer(String layerName, String refSysName) throws DaoException{ FeatureIterator iterator = getFeatureIteratorForLayer(layerName, refSysName); if(!iterator.hasNext()){ iterator.close(); return null; } Feature feature; Map<Integer, Geometry> geometries = new HashMap<Integer, Geometry>(); while (iterator.hasNext()){ feature = iterator.next(); geometries.put((Integer)((SimpleFeatureImpl)feature).getAttribute("item_id"), (Geometry) feature.getDefaultGeometryProperty().getValue()); } iterator.close(); return geometries; }