Handle more than one centerline for a lake (#139)

This commit is contained in:
Michael Barry
2022-03-19 15:16:11 -04:00
committed by GitHub
parent 79576f33d7
commit 6ef91a1e19
2 changed files with 58 additions and 1 deletions

View File

@@ -111,7 +111,13 @@ public class WaterName implements
try { try {
// multiple threads call this concurrently // multiple threads call this concurrently
synchronized (this) { synchronized (this) {
lakeCenterlines.put(osmId, feature.worldGeometry()); // if we already have a centerline for this OSM_ID, then merge the existing one with this one
var newGeometry = feature.worldGeometry();
var oldGeometry = lakeCenterlines.get(osmId);
if (oldGeometry != null) {
newGeometry = GeoUtils.combine(oldGeometry, newGeometry);
}
lakeCenterlines.put(osmId, newGeometry);
} }
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "omt_water_name_lakeline", "Bad lake centerline: " + feature); e.log(stats, "omt_water_name_lakeline", "Bad lake centerline: " + feature);

View File

@@ -13,6 +13,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Geometry;
public class WaterNameTest extends AbstractLayerTest { public class WaterNameTest extends AbstractLayerTest {
@@ -89,6 +90,56 @@ public class WaterNameTest extends AbstractLayerTest {
))); )));
} }
@Test
public void testWaterNameMultipleLakelines() {
assertFeatures(11, List.of(), process(SimpleFeature.create(
newLineString(0, 0, 1, 1),
new HashMap<>(Map.<String, Object>of(
"OSM_ID", -10
)),
LAKE_CENTERLINE_SOURCE,
null,
0
)));
assertFeatures(11, List.of(), process(SimpleFeature.create(
newLineString(2, 2, 3, 3),
new HashMap<>(Map.<String, Object>of(
"OSM_ID", -10
)),
LAKE_CENTERLINE_SOURCE,
null,
0
)));
assertFeatures(10, List.of(Map.of(
"_layer", "water"
), Map.of(
"name", "waterway",
"name:es", "waterway es",
"_layer", "water_name",
"_geom",
new TestUtils.NormGeometry(
GeoUtils.latLonToWorldCoords(GeoUtils.JTS_FACTORY.createGeometryCollection(new Geometry[]{
newLineString(0, 0, 1, 1),
newLineString(2, 2, 3, 3)
}))),
"_minzoom", 9,
"_maxzoom", 14,
"_minpixelsize", "waterway".length() * 6d
)), process(SimpleFeature.create(
GeoUtils.worldToLatLonCoords(rectangle(0, Math.sqrt(1))),
new HashMap<>(Map.<String, Object>of(
"name", "waterway",
"name:es", "waterway es",
"natural", "water",
"water", "pond"
)),
OSM_SOURCE,
null,
10
)));
}
@Test @Test
public void testMarinePoint() { public void testMarinePoint() {
assertFeatures(11, List.of(), process(SimpleFeature.create( assertFeatures(11, List.of(), process(SimpleFeature.create(