Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String lines = "/tmp/ian.shp";
- GeometryFactory factory = new GeometryFactory();
- Map<String, Object> params = new HashMap<>();
- params.put("url", URLs.fileToUrl(new File(lines)));
- DataStore ds = DataStoreFinder.getDataStore(params);
- String name = ds.getTypeNames()[0];
- SimpleFeatureSource source = ds.getFeatureSource(name);
- SimpleFeatureCollection features = source.getFeatures();
- try (SimpleFeatureIterator itr = features.features()) {
- ArrayList<Geometry> geometries = new ArrayList<>();
- while (itr.hasNext()) {
- SimpleFeature f = itr.next();
- Geometry geom = (Geometry) f.getDefaultGeometry();
- geometries.add(geom);
- SimpleFeatureCollection others = source
- .getFeatures(ECQL.toFilter("intersects(the_geom," + geom.toText() + ")"));
- try (SimpleFeatureIterator oiter = others.features()) {
- while (oiter.hasNext()) {
- geometries.add((Geometry) oiter.next().getDefaultGeometry());
- }
- }
- GeometryCollection geometryCollection = (GeometryCollection) factory.buildGeometry(geometries);
- Geometry union = geometryCollection.union();
- System.out.println(union);
- }
- }
Add Comment
Please, Sign In to add comment