Refine search
ProgressListener progressListener) throws IOException { int count = features.size(); float done = 0; GeometryCollector collector = new GeometryCollector(); try { fi = features.features(); while (fi.hasNext()) { Geometry g = (Geometry) fi.next().getDefaultGeometryProperty().getValue(); collector.add(g); fi.close();
@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); } }
Feature feature = (Feature) attribute; if (feature.getDefaultGeometryProperty() != null) { if (crs == null) { crs = feature.getDefaultGeometryProperty() .getType() .getCoordinateReferenceSystem(); defaultGeometry = feature.getDefaultGeometryProperty().getValue();
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); }
/** * 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(); } }
@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()); }
try { if (crs == null) { GeometryDescriptor gd = featureCollection.getSchema().getGeometryDescriptor(); if (gd != null) { crs = gd.getCoordinateReferenceSystem(); FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema()); Unit fromUnit = SI.METRE; Unit toUnit = USCustomary.MILE; double nearestDistance = 9e9; double nearestBearing = 0; FeatureIterator featureIterator = featureCollection.features(); try { 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 = featureIterator.close();
Feature feature; try (FeatureIterator<?> it = features.features()) { while (it.hasNext()) { feature = it.next(); total++; Geometry originalGeom; Geometry finalGeom; originalGeom = (Geometry) feature.getDefaultGeometryProperty().getValue(); try { finalGeom = pipeline.execute(originalGeom); final String layerName = feature.getName().getLocalPart(); final String featureId = feature.getIdentifier().toString(); final String geometryName = geometryDescriptor.getName().getLocalPart();
protected Map<String, Geometry> loadGeometries() throws IOException { Map<String, Geometry> result = new HashMap<String, Geometry>(); if (file != null && file.exists()) { Map<String, Object> map = new HashMap<String, Object>(); map.put("url", file.toURI().toURL()); DataStore dataStore = DataStoreFinder.getDataStore(map); String typeName = dataStore.getTypeNames()[0]; FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore .getFeatureSource(typeName); try (FeatureIterator<SimpleFeature> features = source.getFeatures(Filter.INCLUDE).features()) { while (features.hasNext()) { SimpleFeature feature = features.next(); result.put(feature.getAttribute("WARNCELLID").toString(), (Geometry)feature.getDefaultGeometryProperty().getValue()); } } finally { dataStore.dispose(); } } return result; }
FeatureCollection fc = fs.getFeatures(filter); assertEquals(1, size(fc)); try (FeatureIterator it = fc.features()) { Feature station1 = it.next(); assertEquals("st.1", station1.getIdentifier().toString()); GeometryAttribute defaultGeom = station1.getDefaultGeometryProperty(); assertNotNull(defaultGeom); assertNotNull(defaultGeom.getValue()); assertTrue(defaultGeom.getValue() instanceof Polygon); Polygon poly = (Polygon) defaultGeom.getValue(); assertEquals("POLYGON ((-2 2, 0 2, 0 -2, -2 -2, -2 2))", writer.write(poly));
SimpleFeatureType type = null; SimpleFeatureBuilder build = null; FeatureIterator<?> iterator = collection.features(); FeatureCollection<SimpleFeatureType, SimpleFeature> modifiedFeatureCollection = null; Transaction transaction = new DefaultTransaction("create"); File shp = File.createTempFile("Shape_" + uuid, ".shp"); shp.deleteOnExit(); while (iterator.hasNext()) { SimpleFeature sf = (SimpleFeature) iterator.next(); .getSchema(); SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(inType.getName()); builder.setNamespaceURI(inType.getName().getNamespaceURI()); if (collection.getSchema().getCoordinateReferenceSystem() == null) { builder.setCRS(DefaultGeographicCRS.WGS84); } else { .getName().getLocalPart()); GeometryType type1 = new GeometryTypeImpl(geomProperty.getName(),MultiPolygon.class, oldGeometryDescriptor.getType().getCoordinateReferenceSystem(),oldGeometryDescriptor.getType().isIdentified(),oldGeometryDescriptor.getType().isAbstract(),oldGeometryDescriptor.getType().getRestrictions(),oldGeometryDescriptor.getType().getSuper(),oldGeometryDescriptor.getType().getDescription()); builder.add(geo.getName().getLocalPart(), geo .getType().getBinding());
FeatureIterator<SimpleFeature> featureIterator = fc.features(); while (featureIterator.hasNext()) { SimpleFeature feature = (SimpleFeature) featureIterator.next(); if (g != null) { GeometryAttribute oldGeometryDescriptor = feature.getDefaultGeometryProperty(); GeometryType type = new GeometryTypeImpl(property.getName(), (Class<?>) oldGeometryDescriptor.getType().getBinding(), oldGeometryDescriptor.getType().getCoordinateReferenceSystem(), oldGeometryDescriptor.getType().isIdentified(), oldGeometryDescriptor.getType().isAbstract(), oldGeometryDescriptor.getType().getRestrictions(), oldGeometryDescriptor.getType().getSuper() ,oldGeometryDescriptor.getType().getDescription());
while(featureIterator.hasNext()){ SimpleFeature feature = (SimpleFeature) featureIterator.next(); if(feature.getDefaultGeometry()==null){ Collection<org.opengis.feature.Property>properties = feature.getProperties(); if(g!=null){ GeometryAttribute oldGeometryDescriptor = feature.getDefaultGeometryProperty(); GeometryType type = new GeometryTypeImpl(property.getName(),(Class<?>)oldGeometryDescriptor.getType().getBinding(),oldGeometryDescriptor.getType().getCoordinateReferenceSystem(),oldGeometryDescriptor.getType().isIdentified(),oldGeometryDescriptor.getType().isAbstract(),oldGeometryDescriptor.getType().getRestrictions(),oldGeometryDescriptor.getType().getSuper(),oldGeometryDescriptor.getType().getDescription());
try { if (crs == null) { GeometryDescriptor gd = featureCollection.getSchema().getGeometryDescriptor(); if (gd != null) { crs = gd.getCoordinateReferenceSystem(); FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema()); Unit fromUnit = SI.METER; Unit toUnit = Unit.valueOf("mi"); Iterator featureIterator = null; try { featureIterator = featureCollection.iterator(); 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 = new double[] { co[0].x, co[0].y, };
final SimpleFeature[] features = collection.toArray(new SimpleFeature[collection.size()]); imageToModelTransform = Product.findImageToModelTransform(geoCoding); for (SimpleFeature feature : features) { final Point point = (Point) feature.getDefaultGeometryProperty().getValue(); Point2D modelPos = new Point2D.Float((float) point.getX(), (float) point.getY()); final Point2D imagePos = imageToModelTransform.inverseTransform(modelPos, null);
Class<?> clazz = attribute.getType().getBinding(); if (Geometry.class.isAssignableFrom(clazz)) { Geometry geom = prepareGeometry((Geometry) feature.getDefaultGeometryProperty() .getValue()); if (geom == null) { return Optional.absent(); String id = feature.getIdentifier().getID(); featureBuilder.set("id", id); if (defaultFields != null) { for (DefaultField df : defaultFields) { featureBuilder.set(df.name(), feature.getProperty(df.name()).getValue());
@SuppressWarnings("unchecked") @Override public F next() { F next = super.next(); String fid = ((SimpleFeature) next).getID(); Name geometryAttributeName = builder.getFeatureType().getGeometryDescriptor().getName(); builder.set(geometryAttributeName, next.getDefaultGeometryProperty().getValue()); for (AttributeDescriptor attribute : builder.getFeatureType() .getAttributeDescriptors()) { Name name = attribute.getName(); if (!name.equals(geometryAttributeName)) { Property property = next.getProperty(name); if (property == null) { throw new GeoToolsOpException( GeoToolsOpException.StatusCode.INCOMPATIBLE_FEATURE_TYPE); } builder.set(name, next.getProperty(name).getValue()); } } return (F) builder.buildFeature(fid); } }
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()); } } }
double mag; if(diss_fld.equals("::area::")){ mag = ((Geometry)diss.getDefaultGeometryProperty().getValue()).getArea(); } else { Property magProp = diss.getProperty(diss_fld); Collection<Property> props = diss.getProperties(); for( Property prop : props ){ propStrings += " "+prop.getName();
public Object convert(Object source, Class target) throws Exception { if (source instanceof GeometryAttribute) { return Converters.convert(((GeometryAttribute) source).getValue(), target); } return null; } };