/** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { ZoneCollection zones = new ZoneCollection(); String data = new String( Files.readAllBytes(Paths.get("/home/johannes/gsv/gis/nuts/de.nuts3.gk3.geojson"))); zones.addAll(ZoneGeoJsonIO.parseFeatureCollection(data)); data = null; zones.setPrimaryKey("gsvId"); Map<String, Set<Zone>> aggZones = new HashMap<>(); for (Zone zone : zones.getZones()) { String code = zone.getAttribute("nuts2_code"); Set<Zone> set = aggZones.get(code); if (set == null) { set = new HashSet<>(); aggZones.put(code, set); } set.add(zone); } Set<Zone> newZones = new HashSet<>(); for (Entry<String, Set<Zone>> entry : aggZones.entrySet()) { Set<Zone> set = entry.getValue(); Geometry refGeo = null; for (Zone zone : set) { if (refGeo != null) { Geometry geo2 = zone.getGeometry(); refGeo = refGeo.union(geo2); } else { refGeo = zone.getGeometry(); } } Zone zone = new Zone(refGeo); zone.setAttribute("nuts2_code", entry.getKey()); newZones.add(zone); } data = ZoneGeoJsonIO.toJson(newZones); Files.write( Paths.get("/home/johannes/gsv/gis/nuts/de.nuts2.gk3.geojson"), data.getBytes(), StandardOpenOption.CREATE); }