Guest User

Untitled

a guest
Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. String lines = "/tmp/ian.shp";
  2. GeometryFactory factory = new GeometryFactory();
  3. Map<String, Object> params = new HashMap<>();
  4. params.put("url", URLs.fileToUrl(new File(lines)));
  5. DataStore ds = DataStoreFinder.getDataStore(params);
  6. String name = ds.getTypeNames()[0];
  7. SimpleFeatureSource source = ds.getFeatureSource(name);
  8. SimpleFeatureCollection features = source.getFeatures();
  9. try (SimpleFeatureIterator itr = features.features()) {
  10. ArrayList<Geometry> geometries = new ArrayList<>();
  11.  
  12. while (itr.hasNext()) {
  13. SimpleFeature f = itr.next();
  14. Geometry geom = (Geometry) f.getDefaultGeometry();
  15. geometries.add(geom);
  16. SimpleFeatureCollection others = source
  17. .getFeatures(ECQL.toFilter("intersects(the_geom," + geom.toText() + ")"));
  18.  
  19. try (SimpleFeatureIterator oiter = others.features()) {
  20. while (oiter.hasNext()) {
  21. geometries.add((Geometry) oiter.next().getDefaultGeometry());
  22. }
  23. }
  24.  
  25. GeometryCollection geometryCollection = (GeometryCollection) factory.buildGeometry(geometries);
  26.  
  27. Geometry union = geometryCollection.union();
  28. System.out.println(union);
  29.  
  30. }
  31. }
Add Comment
Please, Sign In to add comment