public static FeatureCollection<SimpleFeatureType, SimpleFeature> createFeatureCollection(URL url, CoordinateReferenceSystem targetCrs, Geometry clipGeometry) throws IOException { FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = getFeatureSource(url); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = featureSource.getFeatures(); featureCollection = clipCollection(featureCollection, DefaultGeographicCRS.WGS84, clipGeometry, DefaultGeographicCRS.WGS84, null, targetCrs, ProgressMonitor.NULL); return featureCollection; }
public static FeatureCollection<SimpleFeatureType, SimpleFeature> loadShapefileForProduct(File file, Product product, FeatureCrsProvider crsProvider, ProgressMonitor pm) throws IOException { pm.beginTask("Loading Shapefile", 100); try { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = loadFeatureCollectionFromShapefile(file); pm.worked(10); return clipFeatureCollectionToProductBounds(featureCollection, product, crsProvider, pm); } finally { pm.done(); } }
/** * @deprecated since BEAM 4.10, use FeatureUtils instead */ @Deprecated public static Geometry createGeoBoundaryPolygon(Product product) { return FeatureUtils.createGeoBoundaryPolygon(product); }
public static FeatureCollection<SimpleFeatureType, SimpleFeature> clipFeatureCollectionToProductBounds(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection, Product product, FeatureCrsProvider crsProvider, ProgressMonitor pm) { final CoordinateReferenceSystem targetCrs = ImageManager.getModelCrs(product.getGeoCoding()); final Geometry clipGeometry = createGeoBoundaryPolygon(product); pm.worked(10); CoordinateReferenceSystem featureCrs = featureCollection.getSchema().getCoordinateReferenceSystem(); if (featureCrs == null) { featureCrs = crsProvider.getFeatureCrs(product); } return FeatureUtils.clipCollection(featureCollection, featureCrs, clipGeometry, DefaultGeographicCRS.WGS84, null, targetCrs, SubProgressMonitor.create(pm, 80)); }
public static FeatureCollection<SimpleFeatureType, SimpleFeature> loadFeatureCollectionFromShapefile(File shapefile) throws IOException { final URL shapefileUrl = shapefile.toURI().toURL(); FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = getFeatureSource(shapefileUrl); return featureSource.getFeatures(); }
GeometryCoordinateSequenceTransformer clip2SourceTransformer = getTransform(clipCrs, sourceCrs); clipGeometry = clip2SourceTransformer.transform(clipGeometry); } catch (TransformException e) { targetSchema = FeatureTypes.transform(sourceSchema, targetCrs); targetSchema.getUserData().putAll(userData); source2TargetTransformer = getTransform(sourceCrs, targetCrs); } catch (SchemaException e) { throw new IllegalStateException(e); try { Geometry sourceGeometry = (Geometry) sourceFeature.getDefaultGeometry(); clippedSourceGeometry = getClippedGeometry(sourceGeometry, clipGeometry); } catch (TopologyException ignored) { continue; SimpleFeature targetFeature = createTargetFeature(clippedSourceGeometry, targetSchema, sourceFeature, source2TargetTransformer); if (targetFeature != null) {
private static void transformFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection, CoordinateReferenceSystem targetCRS) throws TransformException { final GeometryCoordinateSequenceTransformer transform = FeatureUtils.getTransform(DefaultGeographicCRS.WGS84, targetCRS); final FeatureIterator<SimpleFeature> features = featureCollection.features(); final GeometryFactory geometryFactory = new GeometryFactory(); while (features.hasNext()) { final SimpleFeature simpleFeature = features.next(); final Point sourcePoint = (Point) simpleFeature.getDefaultGeometry(); final Point targetPoint = transform.transformPoint(sourcePoint, geometryFactory); simpleFeature.setDefaultGeometry(targetPoint); } }
newCollection.add(wktFeature); FeatureCollection<SimpleFeatureType, SimpleFeature> productFeatures = FeatureUtils.clipFeatureCollectionToProductBounds( newCollection, sceneView.getProduct(),
String targetID, CoordinateReferenceSystem targetCrs) { return FeatureUtils.clipCollection(sourceCollection, defaultSourceCrs, clipGeometry,
@Override public FeatureCollection<SimpleFeatureType, SimpleFeature> read(File shapeFile) throws IOException { return FeatureUtils.loadFeatureCollectionFromShapefile(shapeFile); } };
@Override public void setName(SimpleFeatureTypeBuilder builder) { builder.setName(FeatureUtils.createFeatureTypeName(builder.getDefaultGeometry())); }
@Override public String getFeatureId(String[] tokens) { return FeatureUtils.createFeatureId(count++); }
@Override protected Layer createLayer(LayerType layerType) throws Exception { final PropertySet configuration = layerType.createLayerConfig(null); final URL shapefileUrl = getClass().getResource("bundeslaender.shp"); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_URL, shapefileUrl); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CRS, DefaultGeographicCRS.WGS84); final Coordinate[] coordinates = { new Coordinate(-10, 50), new Coordinate(+10, 50), new Coordinate(+10, 30), new Coordinate(-10, 30), new Coordinate(-10, 50) }; final GeometryFactory geometryFactory = new GeometryFactory(); final LinearRing ring = geometryFactory.createLinearRing(coordinates); final Polygon clipGeometry = geometryFactory.createPolygon(ring, new LinearRing[0]); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, clipGeometry); configuration.setValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE, createStyle()); FeatureCollection<SimpleFeatureType, SimpleFeature> fc; try { fc = FeatureUtils.createFeatureCollection( shapefileUrl, DefaultGeographicCRS.WGS84, clipGeometry); } catch (IOException e) { throw new IllegalArgumentException(e); } return new FeatureLayer(layerType, fc, configuration); }
final Geometry clipGeometry = FeatureUtils.createGeoBoundaryPolygon(product); clippedCollection = FeatureUtils.clipCollection(featureCollection, null, clipGeometry,
private FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection(File file) throws IOException { Object featureCollectionValue = context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection; if (featureCollectionValue == null) { featureCollection = FeatureUtils.getFeatureSource(file.toURI().toURL()).getFeatures(); } else { featureCollection = (FeatureCollection<SimpleFeatureType, SimpleFeature>) featureCollectionValue; } return featureCollection; }
private static void transformFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection, CoordinateReferenceSystem targetCRS) throws TransformException { final GeometryCoordinateSequenceTransformer transform = FeatureUtils.getTransform(DefaultGeographicCRS.WGS84, targetCRS); final FeatureIterator<SimpleFeature> features = featureCollection.features(); final GeometryFactory geometryFactory = new GeometryFactory(); while (features.hasNext()) { final SimpleFeature simpleFeature = features.next(); final Point sourcePoint = (Point) simpleFeature.getDefaultGeometry(); final Point targetPoint = transform.transformPoint(sourcePoint, geometryFactory); simpleFeature.setDefaultGeometry(targetPoint); } }
if (features != null) { final FeatureCollection<SimpleFeatureType, SimpleFeature> productFeatures = FeatureUtils.clipFeatureCollectionToProductBounds(features, product, crsProvider, pm); vectorDataNodes = createVectorDataNodes(productFeatures); for (VectorDataNode vectorDataNode : vectorDataNodes) {
assertTrue(expectedEnvelope.boundsEquals2D(marcoSource.getBounds(Query.ALL), 1.0e-6)); FeatureCollection<SimpleFeatureType, SimpleFeature> normanSource = FeatureUtils.clipCollection(marcoSource.getFeatures(), null, clipGeometry,
public StatisticComputer(File shapefile, BandConfiguration[] bandConfigurations, int initialBinCount, Logger logger) { this.initialBinCount = initialBinCount; this.logger = logger != null ? logger : BeamLogManager.getSystemLogger(); if (shapefile != null) { try { features = FeatureUtils.loadFeatureCollectionFromShapefile(shapefile); } catch (IOException e) { throw new OperatorException("Unable to load shapefile '" + shapefile.getAbsolutePath() + "'", e); } } else { features = null; } crsProvider = new FeatureUtils.FeatureCrsProvider() { @Override public CoordinateReferenceSystem getFeatureCrs(Product targetProduct) { if (ImageManager.getModelCrs(targetProduct.getGeoCoding()) == ImageManager.DEFAULT_IMAGE_CRS) { return ImageManager.DEFAULT_IMAGE_CRS; } return DefaultGeographicCRS.WGS84; } }; pm = ProgressMonitor.NULL; this.bandConfigurations = bandConfigurations; stxOpMappings = new HashMap<BandConfiguration, StxOpMapping>(); }
@Override public void setName(SimpleFeatureTypeBuilder builder) { builder.setName(FeatureUtils.createFeatureTypeName(builder.getDefaultGeometry())); }