in baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/function/RelationGeometryBuilder.java [56:101]
public void accept(Relation relation) {
try {
var start = System.currentTimeMillis();
Map<String, Object> tags = relation.getTags();
// Filter multipolygon geometries
if (!"multipolygon".equals(tags.get("type"))) {
return;
}
// Filter coastline geometries
if ("coastline".equals(tags.get("natural"))) {
return;
}
// Prepare outer and inner polygons
Set<Polygon> outerPolygons = createPolygons(relation, "outer");
Set<Polygon> innerPolygons = createPolygons(relation, "inner");
// Merge touching or overlapping inner polygons
innerPolygons = mergeInnerPolygons(innerPolygons);
// Do the line work
List<Polygon> polygons = mergeOuterAndInnerPolygons(outerPolygons, innerPolygons);
// Set the geometry of the relation
if (polygons.size() == 1) {
Polygon polygon = polygons.get(0);
relation.setGeometry(polygon);
} else if (polygons.size() > 1) {
MultiPolygon multiPolygon =
GEOMETRY_FACTORY_WGS84.createMultiPolygon(polygons.toArray(new Polygon[0]));
relation.setGeometry(multiPolygon);
}
var end = System.currentTimeMillis();
var duration = end - start;
if (duration > 60 * 1000) {
logger.debug("Relation #{} processed in {} ms", relation.id(), duration);
}
} catch (Exception e) {
logger.debug("Unable to build the geometry for relation #" + relation.id(), e);
relation.setGeometry(GEOMETRY_FACTORY_WGS84.createEmpty(0));
}
}