OpenMapTiles 3.15.0 SNAPSHOT (2) (#144)

* version bumped from 3.14.0 to 3.15.0-SNAPSHOT

* regenerate-openmaptiles.sh 07f243c5d9efa558fa539d7a31b2ae50507aaa9d (to match content of OMT PR 1457)

* SQL -> Java re-implementation of OMT PR 1457

* version bumped from 3.14.0 to 3.15.0-SNAPSHOT

* WaterName.areaToMinZoom(): improved handling of rounding and precission + added unit tests

* mvn spotless:apply

* water label min. zoom calculation simplified

* comment adjusted to be hopefully more useful

* mvn spotless:apply

* minzoom for CA_TRANSCANADA and US_INTERSTATE trunk now 4 (to match OMT PR 1440)

* minzoom for some other Canada trunks now 4 (to match OMT PR 1446)

* equals() simplified + clean-up of comments

* regenerate-openmaptiles.sh 5f7b2c11b3224759a21133381ca7d959a1f3cf51 (to match content of OMT PR 1465)

* GB road relations processing adjusted to match OMT PR 1465, e.g. handle also primary and secondary roads

* regenerate-openmaptiles.sh edb42f2db3c2b0ec37045367720eed84d7bbd71f (to match content of OMT PR 1466)

* IE road relations processing adjusted to match OMT PR 1466, e.g. handle IE roates in similar way as GB routes

* fixed handling of networkType for secondary GB routes

* clean-up: case statements simplified

* mvn spotless:apply

* clazz calculation moved up so that minzoom can be set to 3 for only lakes (to match OMT PR 1475)

* unit tests adjusted + extended to cover 'minzoom=3 fore lakes' change

* fixed minor typo from previous PR

* render POIs for large universities at low zoom (to match OMT PR 1479)

* clean-up, to make the diff/PR smaller

* regenerate-openmaptiles.sh 5e9b7c475d53a5bd5ea394da361594d3f4ce2d66 (to match content of OMT PR 1485)

* handle 'grade1' and 'tracktype' as per OMT PR 1485

* added implementation of agg_stop

It is based on OMT PR 1480 (which contains latest the fix) and the rest of older code
(which was not worling properly until the fix).

* clean-up: mvn spotless:apply

* Long ferries (as per OMT PR 1486)

* regenerate-openmaptiles.sh b3d67ed5b327c9059aeea0b3304772c6b4c8c7e9  (to match content of OMT PR 1489)

* Add aboriginal lands (as per OMT PR 1489)

* handle duplicate route relations (to match OMT PR 1501)

* regenerate-openmaptiles.sh master, to match several OMT PRs which adjusted only YML

* URLs in comments adjusted to match OMT PR 1560

* Convert separated addresses to dashed addresses

* add brunnel (and layer) attributes only for certain zoomlevels, depending on feature size (matching OMT PR 1579)

* unit test testInterstateMotorway(): brunnel tag for test line no longer available at Z8

* unit test testInterstateMotorway() clean-up: Z13 was tested twice

* minor clean-up: fixed unit test naming

* partial fix for differences in transportation_name layer

The difference is between OpenMapTiles/master (OMT) and
planetiler-openmaptiles/omt_3_15_0 (PT-OMT) (e.g. development versions).

The point is, that while PT-OMT was using limit of "8km" for Z9-Z11, OMT
is using limit "ST_Length(geometry) > 8000 / POWER(2, zoom_level - 9)
AND zoom_level BETWEEN 9 AND 11".

Some further differences still visible, hence further commits expected.

* further adjustments to better match what is done with ferries in OMT

... (as per OMT PR 1486)

But FERRY_MIN_PIXEL_SIZE is "too much" in the contexct of Planetiler,
since it is applied within tiles, hence causes gaps in lines if a line
"strikes a little" certain tile. Hence we will need to divert a little.

* ferry minLength tweak + clean-up

* mvn spotless:apply

* fixed minor typo

* minor reformatting

* ferry line length filter replaced with min. zoom calculation

hence the results are much closer to what OMT is doing for Z4-Z9

* testFerry() adjusted to match previous commit

ferry test polygon with area 1 now qualifies for min. zoom 5

* clea-up of unused stuff + mvn spotless:apply

* mvn spotless:apply

* added TODO node for follow-up pull-request/simplification

* clean-up: common getMinZoom() code moved to Utils

* minzoom clipping for brunnel was adjusted do Z9-Z12 -> test adjusted too

* clean-up

* use same tolerance for all transportation items, like OSM does

* clean-up, since ferry and non-ferry procesing is now same

* we need regenerate to work with master branch for now

* first sub-class search for agg_stop simplified a little

* contains() used instead of indexOf() for better readability

* numbers as list, not array, so that getFirst() and getLast() can be used

* better trimming and filtring of housenumbers

* adjusted handling of large house numbers

* several unit tests collapsed to one with @ParameterizedTest + @CsvSource

* AGG_STOP_SUBCLASS_ORDER simplified from Map to List

* fixed major omission from previous commit

* clamp() used to replace min()&max() combo

* agg_stop now implemented

* fixed typo in the error message

* prepare IE and GB boundary geometry outside of synchronized{}

* fixed typo in the error message

* mvn spotless:apply

* switch statements for IE and GB route networks simplified

* avoid RouteNetwork->String mapping, not needed for anyMatch()

* fix: attr. brunnel optional based on size on Z4-Z11, attr. layer optional between Z9-Z11

* tolerance change in transportation reverted, added note to README as per why

* fix: monzoom for sea&co. is Z0-Z14 based on area, for the rest it is Z3-Z14 again based on area

* clean-up: avoid doing area->side->area, do just area

* regenerate-openmaptiles.sh 6c31841f4674f15e15afde346a060cf7c22e6cdd (to match content of OMT PR 1591)

* relevant process() functions adjusted to match changes in transportation/mapping.yaml

* regenerate-openmaptiles.sh master, instead of 6c31841f4674f15e15afde346a060cf7c22e6cdd (to match content of OMT PR 1591, in a cleaner way)

* introduce duplicate housenumber filtering (matching OMT PR 1391)

* (less related) clean-up: use isEmpty() instead if size check

* testContainsHousenumber UT adjusted, since duplicate housenumber filtering is reducing amount of house numbers

* use combination of uic_ref, name, network and operator as key for agg_stop sets

If we rely on only on `uic_ref` we group together also stations which are
too far apart (even different cities). With this combo results seem OK,
e.g. all grouped stations are within around 950m (1000 pixels at Z14) of
each other (1000 being used in `PARTITION BY LabelGrid(...` in
`layers/poi/poi.sql` in OpenMapTiles).

* agg_stop comparison made more explicit, since we want to match same exact one

* mvn spotless:apply

* name now important for agg_stop processing, hence name:es (ab)used for unit tests

* agg_stop: simplified processing of nearest station

Results still same, only ordering is different:
- previously: agg_stop=1 first
- now: FIFO

* agg_stop: forther code simplification

* fixed major typo introduced in previous merge

* setMinPixelSize() + setMinZoom() used instead of areaToMinZoom()

* clean-up: unused stuff removed

* mvn spotless:apply

* setAttrWithMinSize() used instead of getBrunnelMinzoom()

getFerryMinzoom() kept since we'd like to replicate `sql_filter: ST_Length(...` from OMT

* getMinZoomForLength() no longer used, hence removed

* MIN_LENGTH value halved, to partially counter the effect of Planetiler applying the limit before merging

* clean-up: LOG2 not used, hence removed

* Revert "MIN_LENGTH value halved, to partially counter the effect of Planetiler applying the limit before merging"

This reverts commit 8fb67075289f3028d31761dcc9564fc597adab36.

* use 256px as buffer pixel override instead of MIN_LENGTH

Make sure we have enough room (=whole next tile) when checking MIN_LENGTH,
to avoid pieces of otherwise "long enough" lines to be excluded (thus
creating "holes" or missing ends) in some tiles just because length in that
particular tile is bellow limit. Given that MIN_LENGTH values translated to
pixels are quite big (compared to {@code BUFFER_SIZE}), such missing pieces
would be quite noticeable.

This improves items mainly in Z12-Z13.

* added BY_TEMP_HAS_NAME comparator to avoid its repeated construction during run-time

* duplicate houcenumber processing simplified further

* clean-up: get(0) replaced with getFirst()

* clean-up: CPU-intensive prepare() moved out of synchronized block

* regenerate-openmaptiles.sh 3cf77e2a542d8a369bb08bf2538cdde0b3effb2b (to match content of OMT PR 1423)

* unit test adjusted for POI office class changes

* regenerate-openmaptiles.sh master (to match content of OMT PR 1544)

* added charging_station implementation matching OMT PR 1544

* use setMinPixelSizeBelowZoom() instead of uniAreaToMinZoom()

* use setMinPixelSizeBelowZoom() instead of getFerryMinzoom()

* fixed unit test, to match recent tweaks

* regenerate-openmaptiles.sh master (to match content of OMT PR 1605)

* Fix university office/amenity collision (to match OSM PR 1607)

* Remove expressway from ramps

* OsmMarinePoint+ne_10m_geography_marine_polys join via name limited to 50km distance

* regenerate-openmaptiles.sh master (to match content of OMT PR 1604)

* Revert "Add aboriginal lands (as per OMT PR 1489)"

This reverts commit 899a0c5718734d5a746cdd84df2e1308614954c0.

* added handling of aboriginal_lands/OsmBoundaryPolygon into Boundary and Place layers

* big islands can now get rank lower than 3

* Add e-road and a-road for transportation z4

* testPolishHighwayIssue165() adjusted: e-road now takes precendence

* regenerate-openmaptiles.sh master (to match content of OMT PR 1627)

* regenerate-openmaptiles.sh fff7110aeb61882abfafe22d1618fbe6181d96cb (to match content of OMT PR 1620)

* Expanded road route attributes (to match OMT PR 1620)

* unrelated clean-up: use getFirst()

* adjusted handling or null and empty ref

* regenerate-openmaptiles.sh master (to match content of OMT PR 1620)

* pointOnSurface() used instead of centroid() to make sure the point is within the boundary

* adjusted deduplication of route_<n>_<something> attributes

* clean-up of some previous adjustments of importantMarinePoints

* clean-up: removed unused imports

* mvn spotless:apply
This commit is contained in:
Peter Hanecak
2024-03-07 09:37:35 +01:00
committed by GitHub
parent 075d90e565
commit b66c89d441
13 changed files with 607 additions and 226 deletions

View File

@@ -79,6 +79,8 @@ import org.locationtech.jts.operation.linemerge.LineMerger;
import org.locationtech.jts.operation.polygonize.Polygonizer;
import org.openmaptiles.OpenMapTilesProfile;
import org.openmaptiles.generated.OpenMapTilesSchema;
import org.openmaptiles.generated.Tables;
import org.openmaptiles.util.OmtLanguageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,6 +97,7 @@ public class Boundary implements
OpenMapTilesProfile.NaturalEarthProcessor,
OpenMapTilesProfile.OsmRelationPreprocessor,
OpenMapTilesProfile.OsmAllProcessor,
Tables.OsmBoundaryPolygon.Handler,
OpenMapTilesProfile.FeaturePostProcessor,
OpenMapTilesProfile.FinishHandler {
@@ -127,6 +130,7 @@ public class Boundary implements
private final Map<Long, List<Geometry>> regionGeometries = new HashMap<>();
private final Map<CountryBoundaryComponent, List<Geometry>> boundariesToMerge = new HashMap<>();
private final PlanetilerConfig config;
private final Translations translations;
public Boundary(Translations translations, PlanetilerConfig config, Stats stats) {
this.config = config;
@@ -141,6 +145,7 @@ public class Boundary implements
false
);
this.stats = stats;
this.translations = translations;
}
private static boolean isDisputed(Map<String, Object> tags) {
@@ -306,6 +311,15 @@ public class Boundary implements
}
}
@Override
public void process(Tables.OsmBoundaryPolygon element, FeatureCollector features) {
features.polygon(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(OpenMapTilesSchema.Boundary.Fields.CLASS, element.boundary())
.setMinPixelSizeBelowZoom(13, 4) // for Z4: `sql_filter: area>power(ZRES3,2)`, etc.
.setMinZoom(4);
}
@Override
public void finish(String sourceName, FeatureCollector.Factory featureCollectors,
Consumer<FeatureCollector.Feature> emit) {

View File

@@ -91,20 +91,15 @@ public class Park implements
@Override
public void process(Tables.OsmParkPolygon element, FeatureCollector features) {
String clazz;
if ("aboriginal_lands".equals(element.boundary())) {
clazz = "aboriginal_lands";
} else {
String protectionTitle = element.protectionTitle();
if (protectionTitle != null) {
protectionTitle = protectionTitle.replace(' ', '_').toLowerCase(Locale.ROOT);
}
clazz = coalesce(
nullIfEmpty(protectionTitle),
nullIfEmpty(element.boundary()),
nullIfEmpty(element.leisure())
);
String protectionTitle = element.protectionTitle();
if (protectionTitle != null) {
protectionTitle = protectionTitle.replace(' ', '_').toLowerCase(Locale.ROOT);
}
String clazz = coalesce(
nullIfEmpty(protectionTitle),
nullIfEmpty(element.boundary()),
nullIfEmpty(element.leisure())
);
// park shape
var outline = features.polygon(LAYER_NAME).setBufferPixels(BUFFER_SIZE)

View File

@@ -88,6 +88,7 @@ public class Place implements
Tables.OsmIslandPoint.Handler,
Tables.OsmIslandPolygon.Handler,
Tables.OsmCityPoint.Handler,
Tables.OsmBoundaryPolygon.Handler,
OpenMapTilesProfile.FeaturePostProcessor {
/*
@@ -96,8 +97,10 @@ public class Place implements
* and minimum zoom level to use for those points.
*/
private static final TreeMap<Double, Integer> ISLAND_AREA_RANKS = new TreeMap<>(Map.of(
Double.MAX_VALUE, 3,
private static final TreeMap<Double, Integer> AREA_RANKS = new TreeMap<>(Map.of(
Double.MAX_VALUE, 1,
squareMetersToWorldArea(640_000_000), 2,
squareMetersToWorldArea(160_000_000), 3,
squareMetersToWorldArea(40_000_000), 4,
squareMetersToWorldArea(15_000_000), 5,
squareMetersToWorldArea(1_000_000), 6
@@ -282,7 +285,7 @@ public class Place implements
public void process(Tables.OsmIslandPolygon element, FeatureCollector features) {
try {
double area = element.source().area();
int rank = ISLAND_AREA_RANKS.ceilingEntry(area).getValue();
int rank = AREA_RANKS.ceilingEntry(area).getValue();
int minzoom = rank <= 3 ? 8 : rank <= 4 ? 9 : 10;
features.pointOnSurface(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
@@ -369,6 +372,23 @@ public class Place implements
}
}
@Override
public void process(Tables.OsmBoundaryPolygon element, FeatureCollector features) {
try {
int rank = AREA_RANKS.ceilingEntry(element.source().area()).getValue();
int minzoom = rank <= 4 ? rank + 5 : 10;
features.pointOnSurface(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(OpenMapTilesSchema.Boundary.Fields.CLASS, element.boundary())
.setAttr(Fields.RANK, rank)
.setMinZoom(minzoom);
} catch (GeometryException e) {
e.log(stats, "omt_boundary_poly",
"Unable to get point for OSM boundary polygon " + element.source().id());
}
}
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
// infer the rank field from ordering of the place labels with each label grid square

View File

@@ -139,6 +139,11 @@ public class Poi implements
}
private String poiClass(String subclass, String mappingKey) {
// Special case subclass collision between office=university and amenity=university
if ("amenity".equals(mappingKey) && "university".equals(subclass)) {
return FieldValues.CLASS_COLLEGE;
}
subclass = coalesce(subclass, "");
return classMapping.getOrElse(Map.of(
"subclass", subclass,

View File

@@ -142,7 +142,9 @@ public class Transportation implements
private static final Set<RouteNetwork> TRUNK_AS_MOTORWAY_BY_NETWORK = Set.of(
RouteNetwork.CA_TRANSCANADA,
RouteNetwork.CA_PROVINCIAL_ARTERIAL,
RouteNetwork.US_INTERSTATE
RouteNetwork.US_INTERSTATE,
RouteNetwork.E_ROAD,
RouteNetwork.A_ROAD
);
private static final Set<String> CA_AB_PRIMARY_AS_ARTERIAL_BY_REF = Set.of(
"2", "3", "4"
@@ -290,8 +292,15 @@ public class Transportation implements
RouteNetwork networkType = null;
String network = relation.getString("network");
String ref = relation.getString("ref");
String name = nullIfEmpty(relation.getString("name"));
String colour = coalesce(
nullIfEmpty(relation.getString("colour")), nullIfEmpty(relation.getString("ref:colour")));
if ("US:I".equals(network)) {
if ("e-road".equals(network)) {
networkType = RouteNetwork.E_ROAD;
} else if ("AsianHighway".equals(network)) {
networkType = RouteNetwork.A_ROAD;
} else if ("US:I".equals(network)) {
networkType = RouteNetwork.US_INTERSTATE;
} else if ("US:US".equals(network)) {
networkType = RouteNetwork.US_HIGHWAY;
@@ -328,7 +337,8 @@ public class Transportation implements
};
if (network != null || rank < 3) {
return List.of(new RouteRelation(coalesce(ref, ""), network, networkType, (byte) rank, relation.id()));
return List
.of(new RouteRelation(coalesce(ref, ""), network, name, colour, networkType, (byte) rank, relation.id()));
}
}
return null;
@@ -366,6 +376,7 @@ public class Transportation implements
};
result.add(new RouteRelation(refMatcher.group(),
networkType == null ? null : networkType.network,
null, null,
networkType, (byte) -1, 0));
}
} catch (GeometryException e) {
@@ -391,7 +402,9 @@ public class Transportation implements
case "trunk", "primary" -> RouteNetwork.IE_NATIONAL;
default -> RouteNetwork.IE_REGIONAL;
};
result.add(new RouteRelation(refMatcher.group(), networkType.network, networkType, (byte) -1, 0));
result.add(new RouteRelation(refMatcher.group(),
networkType.network, null, null,
networkType, (byte) -1, 0));
}
} catch (GeometryException e) {
e.log(stats, "omt_transportation_name_ie_test",
@@ -406,7 +419,7 @@ public class Transportation implements
RouteRelation getRouteRelation(Tables.OsmHighwayLinestring element) {
List<RouteRelation> all = getRouteRelations(element);
return all.isEmpty() ? null : all.get(0);
return all.isEmpty() ? null : all.getFirst();
}
@Override
@@ -436,6 +449,8 @@ public class Transportation implements
Integer rampAboveZ12 = (highwayRamp || element.isRamp()) ? 1 : null;
Integer rampBelowZ12 = highwayRamp ? 1 : null;
boolean expressway = element.expressway() && !"motorway".equals(highway) && !(element.isRamp() || highwayRamp);
FeatureCollector.Feature feature = features.line(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
// main attributes at all zoom levels (used for grouping <= z8)
.setAttr(Fields.CLASS, highwayClass)
@@ -443,7 +458,7 @@ public class Transportation implements
.setAttr(Fields.NETWORK, networkType != null ? networkType.name : null)
.setAttrWithMinSize(Fields.BRUNNEL, brunnel(element.isBridge(), element.isTunnel(), element.isFord()), 4, 4, 12)
// z8+
.setAttrWithMinzoom(Fields.EXPRESSWAY, element.expressway() && !"motorway".equals(highway) ? 1 : null, 8)
.setAttrWithMinzoom(Fields.EXPRESSWAY, expressway ? 1 : null, 8)
// z9+
.setAttrWithMinSize(Fields.LAYER, nullIfLong(element.layer(), 0), 4, 9, 12)
.setAttrWithMinzoom(Fields.BICYCLE, nullIfEmpty(element.bicycle()), 9)
@@ -643,7 +658,9 @@ public class Transportation implements
GB_PRIMARY("gb-primary", "omt-gb-primary"),
IE_MOTORWAY("ie-motorway", "omt-ie-motorway"),
IE_NATIONAL("ie-national", "omt-ie-national"),
IE_REGIONAL("ie-regional", "omt-ie-regional");
IE_REGIONAL("ie-regional", "omt-ie-regional"),
E_ROAD("e-road", null),
A_ROAD("a-road", null);
final String name;
final String network;
@@ -658,6 +675,8 @@ public class Transportation implements
record RouteRelation(
String ref,
String network,
String name,
String colour,
RouteNetwork networkType,
byte rank,
@Override long id
@@ -669,6 +688,8 @@ public class Transportation implements
MemoryEstimator.estimateSize(rank) +
POINTER_BYTES + estimateSize(ref) +
POINTER_BYTES + estimateSize(network) +
POINTER_BYTES + estimateSize(name) +
POINTER_BYTES + estimateSize(colour) +
POINTER_BYTES + // networkType
MemoryEstimator.estimateSizeLong(id);
}

View File

@@ -113,6 +113,11 @@ public class TransportationName implements
.put(9, 8_000)
.put(10, 4_000)
.put(11, 2_000);
private static final ZoomFunction<Number> BUFFER_PIXEL_OVERRIDES =
ZoomFunction.fromMaxZoomThresholds(Map.of(
13, 256,
6, 256
));
private final boolean brunnel;
private final boolean sizeForShield;
private final boolean limitMerge;
@@ -255,7 +260,7 @@ public class TransportationName implements
FeatureCollector.Feature feature = features.line(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setBufferPixelOverrides(MIN_LENGTH)
.setBufferPixelOverrides(BUFFER_PIXEL_OVERRIDES)
// TODO abbreviate road names - can't port osml10n because it is AGPL
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(Fields.REF, ref)
@@ -269,12 +274,20 @@ public class TransportationName implements
.setSortKey(element.zOrder())
.setMinZoom(minzoom);
// populate route_1, route_2, ... route_n tags and remove duplicates
// populate route_1_<something>, route_2_<something>, ... route_n_<something> tags and remove duplicates
Set<String> routes = new HashSet<>();
for (var route : relations) {
String routeString = route.network() + "=" + coalesce(route.ref(), "");
String routeString = route.network() + "=" +
coalesce(route.ref(), "") + "=" +
coalesce(route.name(), "") + "=" +
coalesce(route.colour(), "");
if (routes.add(routeString)) {
feature.setAttr("route_" + routes.size(), routeString);
String keyPrefix = "route_" + routes.size() + "_";
feature.setAttr(keyPrefix + "network", route.network());
feature.setAttr(keyPrefix + "ref", nullIfEmpty(route.ref()));
feature.setAttr(keyPrefix + "name", route.name());
feature.setAttr(keyPrefix + "colour", route.colour());
}
}
@@ -308,7 +321,7 @@ public class TransportationName implements
if (!nullOrEmpty(element.name())) {
features.line(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setBufferPixelOverrides(MIN_LENGTH)
.setBufferPixelOverrides(BUFFER_PIXEL_OVERRIDES)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(Fields.CLASS, "aerialway")
.setAttr(Fields.SUBCLASS, element.aerialway())
@@ -323,7 +336,7 @@ public class TransportationName implements
if (!nullOrEmpty(element.name())) {
features.line(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setBufferPixelOverrides(MIN_LENGTH)
.setBufferPixelOverrides(BUFFER_PIXEL_OVERRIDES)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(Fields.CLASS, element.shipway())
.setMinPixelSize(0)

View File

@@ -83,11 +83,13 @@ public class WaterName implements
private static final Logger LOGGER = LoggerFactory.getLogger(WaterName.class);
private static final Set<String> SEA_OR_OCEAN_PLACE = Set.of("sea", "ocean");
private static final double IMPORTANT_MARINE_REGIONS_JOIN_DISTANCE =
GeoUtils.metersToPixelAtEquator(0, 50_000) / 256d;
private final Translations translations;
// need to synchronize updates from multiple threads
private final LongObjectMap<Geometry> lakeCenterlines = Hppc.newLongObjectHashMap();
// may be updated concurrently by multiple threads
private final ConcurrentSkipListMap<String, Integer> importantMarinePoints = new ConcurrentSkipListMap<>();
private final ConcurrentSkipListMap<String, NaturalEarthRegion> importantMarinePoints = new ConcurrentSkipListMap<>();
private final Stats stats;
public WaterName(Translations translations, PlanetilerConfig config, Stats stats) {
@@ -133,11 +135,49 @@ public class WaterName implements
Integer scalerank = Parse.parseIntOrNull(feature.getTag("scalerank"));
if (name != null && scalerank != null) {
name = name.replaceAll("\\s+", " ").trim().toLowerCase();
importantMarinePoints.put(name, scalerank);
try {
importantMarinePoints.put(name, new NaturalEarthRegion(feature.worldGeometry(), scalerank));
} catch (GeometryException e) {
e.log(stats, "ne_marine_polys",
"Error getting geometry for natural earth feature " + table + " " + feature.getTag("ogc_fid"));
}
}
}
}
private NaturalEarthRegion getImportantMarineRegion(Tables.OsmMarinePoint element) {
var source = element.source();
String name = element.name().toLowerCase();
NaturalEarthRegion result = importantMarinePoints.get(name);
if (result == null) {
result = importantMarinePoints.get(source.getString("name:en", "").toLowerCase());
}
if (result == null) {
result = importantMarinePoints.get(source.getString("name:es", "").toLowerCase());
}
if (result == null) {
Map.Entry<String, NaturalEarthRegion> next = importantMarinePoints.ceilingEntry(name);
if (next != null && next.getKey().startsWith(name)) {
result = next.getValue();
}
}
if (result == null) {
return null;
}
try {
double distance = result.geometry.distance(source.worldGeometry());
if (distance <= IMPORTANT_MARINE_REGIONS_JOIN_DISTANCE) {
return result;
}
} catch (GeometryException e) {
e.log(stats, "osm_marine_point",
"Error getting geometry for OSM marine point " + element.source().id());
}
return null;
}
@Override
public void process(Tables.OsmMarinePoint element, FeatureCollector features) {
if (!element.name().isBlank()) {
@@ -148,29 +188,14 @@ public class WaterName implements
var source = element.source();
// use name from OSM, but get min zoom from natural earth based on fuzzy name match...
Integer rank = Parse.parseIntOrNull(source.getTag("rank"));
String name = element.name().toLowerCase();
Integer nerank;
if ((nerank = importantMarinePoints.get(name)) != null) {
rank = nerank;
} else if ((nerank = importantMarinePoints.get(source.getString("name:en", "").toLowerCase())) != null) {
rank = nerank;
} else if ((nerank = importantMarinePoints.get(source.getString("name:es", "").toLowerCase())) != null) {
rank = nerank;
} else {
Map.Entry<String, Integer> next = importantMarinePoints.ceilingEntry(name);
if (next != null && next.getKey().startsWith(name)) {
rank = next.getValue();
}
NaturalEarthRegion neRegion = getImportantMarineRegion(element);
if (neRegion != null) {
rank = neRegion.scalerank;
}
int minZoom;
if ("ocean".equals(element.place())) {
minZoom = 0;
} else if (rank != null) {
// FIXME: While this looks like matching properly stuff in https://github.com/openmaptiles/openmaptiles/pull/1457/files#diff-201daa1c61c99073fe3280d440c9feca5ed2236b251ad454caa14cc203f952d1R74 ,
// it includes not just https://www.openstreetmap.org/relation/13360255 but also https://www.openstreetmap.org/node/1385157299 (and some others).
// Hence check how that OpenMapTiles code works for "James Bay" and:
// a) if same as here then, fix there and then here
// b) if OK (while here NOK), fix only here
minZoom = rank;
} else if ("bay".equals(element.natural())) {
minZoom = 13;
@@ -220,4 +245,9 @@ public class WaterName implements
.setMinZoom(minzoom);
}
}
private record NaturalEarthRegion(
Geometry geometry,
int scalerank
) {}
}