use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.
the class CountryBoundaryMapArchiver method geometryForShard.
protected Geometry geometryForShard(final Rectangle shardBounds, final CountryBoundaryMap boundaryMap) {
final JtsMultiPolygonConverter multiPolyConverter = new JtsMultiPolygonConverter();
final JtsPolygonConverter polyConverter = new JtsPolygonConverter();
final GeometryFactory factory = new GeometryFactory();
final List<CountryBoundary> boundaries = boundaryMap.boundaries(shardBounds);
// jts version of the initial shard bounds
org.locationtech.jts.geom.Geometry shardPolyJts = polyConverter.convert(shardBounds);
// remove country boundaries from the ocean tile one by one
for (final CountryBoundary boundary : boundaries) {
final Set<Polygon> boundaryPolygons = multiPolyConverter.convert(boundary.getBoundary());
final org.locationtech.jts.geom.MultiPolygon countryGeometry = factory.createMultiPolygon(boundaryPolygons.toArray(new Polygon[boundaryPolygons.size()]));
shardPolyJts = shardPolyJts.difference(countryGeometry);
}
return shardPolyJts;
}
use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.
the class CountryBoundaryMapArchiver method generateOceanBoundaryMap.
protected CountryBoundaryMap generateOceanBoundaryMap(final CountryBoundaryMap boundaryMap, final Iterable<SlippyTile> allTiles) {
final CountryBoundaryMap finalBoundaryMap = new CountryBoundaryMap();
int oceanCountryCount = 0;
// add all ocean boundaries to the new boundary map
logger.info("Calculating ocean boundaries...");
for (final SlippyTile tile : allTiles) {
final Time start = Time.now();
final String countryCode = String.format("O%02d", oceanCountryCount);
final Geometry countryGeometry = geometryForShard(tile.bounds(), boundaryMap);
if (!countryGeometry.isEmpty()) {
if (countryGeometry instanceof Polygon) {
finalBoundaryMap.addCountry(countryCode, (Polygon) countryGeometry);
}
if (countryGeometry instanceof MultiPolygon) {
finalBoundaryMap.addCountry(countryCode, (MultiPolygon) countryGeometry);
}
logger.info("Added Ocean Country {} in {}", countryCode, start.elapsedSince());
oceanCountryCount++;
} else {
logger.info("Skipped Ocean Country {} in {}. It is land covered.", tile.getName(), start.elapsedSince());
}
}
// add all countries from the input boundary map to the new boundary map
logger.info("Adding back country boundaries to the new ocean boundary map");
final JtsMultiPolygonConverter multiPolyConverter = new JtsMultiPolygonConverter();
for (final String country : boundaryMap.allCountryNames()) {
for (final CountryBoundary countryBoundary : boundaryMap.countryBoundary(country)) {
final GeometryFactory factory = new GeometryFactory();
final Set<org.locationtech.jts.geom.Polygon> boundaryPolygons = multiPolyConverter.convert(countryBoundary.getBoundary());
final org.locationtech.jts.geom.MultiPolygon countryGeometry = factory.createMultiPolygon(boundaryPolygons.toArray(new Polygon[boundaryPolygons.size()]));
finalBoundaryMap.addCountry(country, countryGeometry);
}
}
return finalBoundaryMap;
}
use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.
the class MultiPolygonClipper method processMultiPolygon.
private MultiPolygon processMultiPolygon(final Geometry intersections) {
MultiPolygon result = new MultiPolygon(new MultiMap<>());
if (intersections instanceof GeometryCollection) {
final GeometryCollection collection = (GeometryCollection) intersections;
final int numGeometries = collection.getNumGeometries();
for (int n = 0; n < numGeometries; n++) {
final Geometry geometry = collection.getGeometryN(n);
result = result.merge(processMultiPolygon(geometry));
}
} else if (intersections instanceof org.locationtech.jts.geom.Polygon) {
final Set<org.locationtech.jts.geom.Polygon> set = new HashSet<>();
set.add((org.locationtech.jts.geom.Polygon) intersections);
result = result.merge(new JtsMultiPolygonConverter().backwardConvert(set));
}
return result;
}
use of org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter in project atlas by osmlab.
the class MultiPolygonClipper method runMultiPolygonClipping.
private MultiPolygon runMultiPolygonClipping(final MultiPolygon subject, final BiFunction<Geometry, Geometry, Geometry> application) {
MultiPolygon result = new MultiPolygon(new MultiMap<>());
final Set<org.locationtech.jts.geom.Polygon> jtsSubjects = new JtsMultiPolygonConverter().convert(subject);
for (final org.locationtech.jts.geom.Polygon jtsClipping : this.jtsClippings) {
for (final org.locationtech.jts.geom.Polygon jtsSubject : jtsSubjects) {
result = result.merge(processMultiPolygon(application.apply(jtsSubject, jtsClipping)));
}
}
return result;
}
Aggregations