Skip to content

Commit

Permalink
Update to OMT 3.14 (#50)
Browse files Browse the repository at this point in the history
* initial update step: 3.13.1 bumped to 3.14

* automated update steps: regenerate-openmaptiles.sh v3.14 + mvn spotless:apply

* riverbank was removed from waterway -> replaced with dock un the unit test

* riverbank was removed from waterway -> testRiverbank() changed into testDock()

* riverbank was removed in OpenMapTiles v3.14

* parcel_locker (with brand, operator and/or ref) was added in OpenMapTiles v3.14

* bus_guideway was added in OpenMapTiles v3.14

* support for county seats (capital=6) was added in OpenMapTiles v3.14

* spotless:apply

* gn_ascii replaced with name_en

gn_ascii was removed from NE5 - see commit b14da2ea in OMT for more
details

* merging of buildings at Z13 replicated also for landuse from Z9 (or for some from Z6) to Z13 to match updates in OpenMapTiles v3.14

* landuse_merge_z9_to_z13 argument removed since it has negligible perf. overhead hence no need to have it

* cover a corner case for parcel_locker: no brand, no operator, just ref

* corrected landuse polygon merging to better match OpenMapTiles 3.14 (1)

* corrected landuse polygon merging to better match OpenMapTiles 3.14 (1): merge only landuse=residential

* clean-up: since evaluation in Landuse is simpler than in Landcover, streaming and Collectors.partitioningBy() used

* clean-up of naming: splitList -> splitLists

* land-use merging unit test adjusted and extended to match recent changes

* other unit tests adjusted to match recent changes

* spotless:apply

* clean-up: added comment, to match Landover

* 3.13.1 bumped to 3.14 (follow-up/fix for e26e13a)

* adjusted WOOD_OR_FOREST handling for Z8 to match change in OMT (osm_landcover_gen_z8)

* updated unit test to match adjusted WOOD_OR_FOREST handling for Z8

* clean-up: if-else replaced with switch

* clean-up: conditional grouped to make it more readable
  • Loading branch information
phanecak-maptiler committed Dec 28, 2022
1 parent d378521 commit c662ef2
Show file tree
Hide file tree
Showing 18 changed files with 400 additions and 146 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ script with the
OpenMapTiles release tag:

```bash
./scripts/regenerate-openmaptiles.sh v3.13.1
./scripts/regenerate-openmaptiles.sh v3.14
```

Then follow the instructions it prints for reformatting generated code.

If you want to regenerate from a different repository than the default openmaptiles, you can specify the url like this:

```bash
./scripts/regenerate-openmaptiles.sh v3.13.1 https://raw.githubusercontent.com/openmaptiles/openmaptiles/
./scripts/regenerate-openmaptiles.sh v3.14 https://raw.githubusercontent.com/openmaptiles/openmaptiles/
```

## License
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>org.openmaptiles</groupId>
<artifactId>planetiler-openmaptiles</artifactId>
<version>3.13.1</version>
<version>3.14.0</version>

<name>OpenMapTiles Vector Tile Schema implementation for Planetiler tool</name>

Expand Down
2 changes: 1 addition & 1 deletion scripts/regenerate-openmaptiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o errexit
set -o pipefail
set -o nounset

TAG="${1:-"v3.13.1"}"
TAG="${1:-"v3.14"}"
echo "tag=${TAG}"

BASE_URL="${2:-"https://raw.githubusercontent.com/openmaptiles/openmaptiles/"}"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/openmaptiles/Generate.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static JsonNode parseYaml(String string) {
public static void main(String[] args) throws IOException {
Arguments arguments = Arguments.fromArgsOrConfigFile(args);
PlanetilerConfig planetilerConfig = PlanetilerConfig.from(arguments);
String tag = arguments.getString("tag", "openmaptiles tag to use", "v3.13.1");
String tag = arguments.getString("tag", "openmaptiles tag to use", "v3.14.0");
String baseUrl = arguments.getString("base-url", "the url used to download the openmaptiles.yml",
"https://raw.githubusercontent.com/openmaptiles/openmaptiles/");
String base = baseUrl + tag + "/";
Expand Down
160 changes: 86 additions & 74 deletions src/main/java/org/openmaptiles/generated/OpenMapTilesSchema.java

Large diffs are not rendered by default.

69 changes: 39 additions & 30 deletions src/main/java/org/openmaptiles/generated/Tables.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

/**
* OSM element parsers generated from the <a href="https://github.com/omniscale/imposm3">imposm3</a> table definitions
* in the <a href="https://github.com/openmaptiles/openmaptiles/blob/v3.13.1/openmaptiles.yaml">OpenMapTiles vector tile
* in the <a href="https://github.com/openmaptiles/openmaptiles/blob/v3.14/openmaptiles.yaml">OpenMapTiles vector tile
* schema</a>.
*
* These filter and parse the raw OSM key/value attribute pairs on tags into records with fields that match the columns
Expand Down Expand Up @@ -106,10 +106,10 @@ public OsmWaterPolygon(SourceFeature source, String mappingKey) {
}

/** Imposm3 "mapping" to filter OSM elements that should appear in this "table". */
public static final Expression MAPPING =
and(or(matchAny("landuse", "reservoir", "basin", "salt_pond"), matchAny("leisure", "swimming_pool"),
matchAny("natural", "water", "bay", "spring"), matchAny("waterway", "riverbank", "dock"),
matchAny("water", "river")), not(matchAny("covered", "yes")), matchType("polygon"));
public static final Expression MAPPING = and(
or(matchAny("landuse", "reservoir", "basin", "salt_pond"), matchAny("leisure", "swimming_pool"),
matchAny("natural", "water", "bay", "spring"), matchAny("waterway", "dock"), matchAny("water", "river")),
not(matchAny("covered", "yes")), matchType("polygon"));

/**
* Interface for layer implementations to extend to subscribe to OSM elements filtered and parsed as
Expand Down Expand Up @@ -153,8 +153,8 @@ public OsmLandcoverPolygon(SourceFeature source, String mappingKey) {
public static final Expression MAPPING = and(or(
matchAny("landuse", "allotments", "farm", "farmland", "orchard", "plant_nursery", "vineyard", "grass",
"grassland", "meadow", "forest", "village_green", "recreation_ground"),
matchAny("natural", "wood", "wetland", "fell", "grassland", "heath", "scrub", "tundra", "glacier", "bare_rock",
"scree", "beach", "sand", "dune"),
matchAny("natural", "wood", "wetland", "fell", "grassland", "heath", "scrub", "shrubbery", "tundra", "glacier",
"bare_rock", "scree", "beach", "sand", "dune"),
matchAny("leisure", "park", "garden", "golf_course"), matchAny("wetland", "bog", "swamp", "wet_meadow", "marsh",
"reedbed", "saltern", "tidalflat", "saltmarsh", "mangrove")),
matchType("polygon"));
Expand All @@ -178,8 +178,8 @@ public OsmLandusePolygon(SourceFeature source, String mappingKey) {

/** Imposm3 "mapping" to filter OSM elements that should appear in this "table". */
public static final Expression MAPPING = and(or(
matchAny("landuse", "railway", "cemetery", "military", "residential", "commercial", "industrial", "garages",
"retail"),
matchAny("landuse", "railway", "cemetery", "military", "quarry", "residential", "commercial", "industrial",
"garages", "retail"),
matchAny("amenity", "bus_station", "school", "university", "kindergarten", "college", "library", "hospital",
"grave_yard"),
matchAny("leisure", "stadium", "pitch", "playground", "track"), matchAny("tourism", "theme_park", "zoo"),
Expand Down Expand Up @@ -345,7 +345,7 @@ public OsmHighwayLinestring(SourceFeature source, String mappingKey) {
matchAny("highway", "motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary",
"secondary_link", "tertiary", "tertiary_link", "unclassified", "residential", "living_street", "road",
"pedestrian", "path", "footway", "cycleway", "steps", "bridleway", "corridor", "service", "track", "raceway",
"busway", "construction"),
"busway", "bus_guideway", "construction"),
matchAny("public_transport", "platform"), matchAny("man_made", "pier"),
matchAny("service", "driveway", "parking_aisle")), matchType("linestring"));

Expand Down Expand Up @@ -690,17 +690,19 @@ public interface Handler {
/** An OSM element that would appear in the {@code osm_poi_point} table generated by imposm3. */
public record OsmPoiPoint(@Override String name, @Override String nameEn, @Override String nameDe,
@Override String subclass, @Override String mappingKey, @Override String station, @Override String funicular,
@Override String information, @Override String uicRef, @Override String religion, @Override long level,
@Override boolean indoor, @Override long layer, @Override String sport, @Override String operator,
@Override String network, @Override SourceFeature source) implements Row, WithName, WithNameEn, WithNameDe,
WithSubclass, WithMappingKey, WithStation, WithFunicular, WithInformation, WithUicRef, WithReligion, WithLevel,
WithIndoor, WithLayer, WithSport, WithOperator, WithNetwork, WithSource {
@Override String information, @Override String uicRef, @Override String ref, @Override String religion,
@Override long level, @Override boolean indoor, @Override long layer, @Override String sport,
@Override String operator, @Override String network, @Override String brand, @Override SourceFeature source)
implements Row, WithName, WithNameEn, WithNameDe, WithSubclass, WithMappingKey, WithStation, WithFunicular,
WithInformation, WithUicRef, WithRef, WithReligion, WithLevel, WithIndoor, WithLayer, WithSport, WithOperator,
WithNetwork, WithBrand, WithSource {
public OsmPoiPoint(SourceFeature source, String mappingKey) {
this(source.getString("name"), source.getString("name:en"), source.getString("name:de"),
source.getString(mappingKey), mappingKey, source.getString("station"), source.getString("funicular"),
source.getString("information"), source.getString("uic_ref"), source.getString("religion"),
source.getLong("level"), source.getBoolean("indoor"), source.getLong("layer"), source.getString("sport"),
source.getString("operator"), source.getString("network"), source);
source.getString("information"), source.getString("uic_ref"), source.getString("ref"),
source.getString("religion"), source.getLong("level"), source.getBoolean("indoor"), source.getLong("layer"),
source.getString("sport"), source.getString("operator"), source.getString("network"), source.getString("brand"),
source);
}

/** Imposm3 "mapping" to filter OSM elements that should appear in this "table". */
Expand All @@ -709,8 +711,8 @@ public OsmPoiPoint(SourceFeature source, String mappingKey) {
"bus_station", "cafe", "cinema", "clinic", "college", "community_centre", "courthouse", "dentist", "doctors",
"drinking_water", "fast_food", "ferry_terminal", "fire_station", "food_court", "fuel", "grave_yard", "hospital",
"ice_cream", "kindergarten", "library", "marketplace", "motorcycle_parking", "nightclub", "nursing_home",
"parking", "pharmacy", "place_of_worship", "police", "post_box", "post_office", "prison", "pub",
"public_building", "recycling", "restaurant", "school", "shelter", "swimming_pool", "taxi", "telephone",
"parking", "pharmacy", "place_of_worship", "police", "parcel_locker", "post_box", "post_office", "prison",
"pub", "public_building", "recycling", "restaurant", "school", "shelter", "swimming_pool", "taxi", "telephone",
"theatre", "toilets", "townhall", "university", "veterinary", "waste_basket"),
matchAny("barrier", "bollard", "border_control", "cycle_barrier", "gate", "lift_gate", "sally_port", "stile",
"toll_booth"),
Expand Down Expand Up @@ -758,17 +760,19 @@ public interface Handler {
/** An OSM element that would appear in the {@code osm_poi_polygon} table generated by imposm3. */
public record OsmPoiPolygon(@Override String name, @Override String nameEn, @Override String nameDe,
@Override String subclass, @Override String mappingKey, @Override String station, @Override String funicular,
@Override String information, @Override String uicRef, @Override String religion, @Override long level,
@Override boolean indoor, @Override long layer, @Override String sport, @Override String operator,
@Override String network, @Override SourceFeature source) implements Row, WithName, WithNameEn, WithNameDe,
WithSubclass, WithMappingKey, WithStation, WithFunicular, WithInformation, WithUicRef, WithReligion, WithLevel,
WithIndoor, WithLayer, WithSport, WithOperator, WithNetwork, WithSource {
@Override String information, @Override String uicRef, @Override String ref, @Override String religion,
@Override long level, @Override boolean indoor, @Override long layer, @Override String sport,
@Override String operator, @Override String network, @Override String brand, @Override SourceFeature source)
implements Row, WithName, WithNameEn, WithNameDe, WithSubclass, WithMappingKey, WithStation, WithFunicular,
WithInformation, WithUicRef, WithRef, WithReligion, WithLevel, WithIndoor, WithLayer, WithSport, WithOperator,
WithNetwork, WithBrand, WithSource {
public OsmPoiPolygon(SourceFeature source, String mappingKey) {
this(source.getString("name"), source.getString("name:en"), source.getString("name:de"),
source.getString(mappingKey), mappingKey, source.getString("station"), source.getString("funicular"),
source.getString("information"), source.getString("uic_ref"), source.getString("religion"),
source.getLong("level"), source.getBoolean("indoor"), source.getLong("layer"), source.getString("sport"),
source.getString("operator"), source.getString("network"), source);
source.getString("information"), source.getString("uic_ref"), source.getString("ref"),
source.getString("religion"), source.getLong("level"), source.getBoolean("indoor"), source.getLong("layer"),
source.getString("sport"), source.getString("operator"), source.getString("network"), source.getString("brand"),
source);
}

/** Imposm3 "mapping" to filter OSM elements that should appear in this "table". */
Expand All @@ -777,8 +781,8 @@ public OsmPoiPolygon(SourceFeature source, String mappingKey) {
"bus_station", "cafe", "cinema", "clinic", "college", "community_centre", "courthouse", "dentist", "doctors",
"drinking_water", "fast_food", "ferry_terminal", "fire_station", "food_court", "fuel", "grave_yard", "hospital",
"ice_cream", "kindergarten", "library", "marketplace", "motorcycle_parking", "nightclub", "nursing_home",
"parking", "pharmacy", "place_of_worship", "police", "post_box", "post_office", "prison", "pub",
"public_building", "recycling", "restaurant", "school", "shelter", "swimming_pool", "taxi", "telephone",
"parking", "pharmacy", "place_of_worship", "police", "parcel_locker", "post_box", "post_office", "prison",
"pub", "public_building", "recycling", "restaurant", "school", "shelter", "swimming_pool", "taxi", "telephone",
"theatre", "toilets", "townhall", "university", "veterinary", "waste_basket"),
matchAny("barrier", "bollard", "border_control", "cycle_barrier", "gate", "lift_gate", "sally_port", "stile",
"toll_booth"),
Expand Down Expand Up @@ -886,6 +890,11 @@ public interface WithBoundary {
String boundary();
}

/** Rows with a String brand attribute. */
public interface WithBrand {
String brand();
}

/** Rows with a String building attribute. */
public interface WithBuilding {
String building();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/openmaptiles/layers/Landcover.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
} else { // don't merge
result.add(item);
}
} else if (zoom == 9) {
} else if (zoom >= 8 && zoom <= 9) {
if (WOOD_OR_FOREST.contains(subclass)) {
attrs.put(tempGroupKey, numPoints < 300 ? "<300" : ">300");
toMerge.add(item);
} else { // don't merge
result.add(item);
}
} else { // zoom between 7 and 8
} else { // zoom 7
toMerge.add(item);
}
} else {
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/org/openmaptiles/layers/Landuse.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static org.openmaptiles.util.Utils.nullIfEmpty;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.reader.SourceFeature;
import com.onthegomap.planetiler.stats.Stats;
import com.onthegomap.planetiler.util.Parse;
import com.onthegomap.planetiler.util.Translations;
import com.onthegomap.planetiler.util.ZoomFunction;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.openmaptiles.OpenMapTilesProfile;
import org.openmaptiles.generated.OpenMapTilesSchema;
import org.openmaptiles.generated.Tables;
Expand All @@ -61,6 +66,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
public class Landuse implements
OpenMapTilesSchema.Landuse,
OpenMapTilesProfile.NaturalEarthProcessor,
OpenMapTilesProfile.FeaturePostProcessor,
Tables.OsmLandusePolygon.Handler {

private static final ZoomFunction<Number> MIN_PIXEL_SIZE_THRESHOLDS = ZoomFunction.fromMaxZoomThresholds(Map.of(
Expand Down Expand Up @@ -103,10 +109,36 @@ public void process(Tables.OsmLandusePolygon element, FeatureCollector features)
if ("grave_yard".equals(clazz)) {
clazz = FieldValues.CLASS_CEMETERY;
}
features.polygon(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
var feature = features.polygon(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.CLASS, clazz)
.setMinPixelSizeOverrides(MIN_PIXEL_SIZE_THRESHOLDS)
.setMinZoom(Z6_CLASSES.contains(clazz) ? 6 : 9);
if (FieldValues.CLASS_RESIDENTIAL.equals(clazz)) {
feature
.setMinPixelSize(0.1)
.setPixelTolerance(0.25);
} else {
feature
.setMinPixelSizeOverrides(MIN_PIXEL_SIZE_THRESHOLDS);
}
}
}

@Override
public List<VectorTile.Feature> postProcess(int zoom,
List<VectorTile.Feature> items) throws GeometryException {
if (zoom < 6 || zoom > 12) {
return items;
} else {
// merging only merges polygons with class "residential" for z6-z12
Map<Boolean, List<VectorTile.Feature>> splitLists =
items.stream().collect(Collectors.partitioningBy(
i -> FieldValues.CLASS_RESIDENTIAL.equals(i.attrs().get(Fields.CLASS)))
);
List<VectorTile.Feature> result = splitLists.get(Boolean.FALSE);
List<VectorTile.Feature> toMerge = splitLists.get(Boolean.TRUE);
var merged = FeatureMerge.mergeNearbyPolygons(toMerge, 1, 1, 0.1, 0.1);
result.addAll(merged);
return result;
}
}
}
14 changes: 9 additions & 5 deletions src/main/java/org/openmaptiles/layers/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void processNaturalEarth(String table, SourceFeature feature, FeatureColl
feature.getString("name"),
feature.getString("wikidataid"),
(int) feature.getLong("scalerank"),
Stream.of("name", "namealt", "meganame", "gn_ascii", "nameascii").map(feature::getString)
Stream.of("name", "namealt", "meganame", "name_en", "nameascii").map(feature::getString)
.filter(Objects::nonNull)
.map(s -> s.toLowerCase(Locale.ROOT))
.collect(Collectors.toSet())
Expand Down Expand Up @@ -356,10 +356,14 @@ public void process(Tables.OsmCityPoint element, FeatureCollector features) {
feature.setPointLabelGridLimit(LABEL_GRID_LIMITS);
}

if ("2".equals(capital) || "yes".equals(capital)) {
feature.setAttr(Fields.CAPITAL, 2);
} else if ("4".equals(capital)) {
feature.setAttr(Fields.CAPITAL, 4);
if (capital != null) { // with Java 18, we can handle that with "case null", see https://openjdk.org/jeps/420)
switch (capital) {
case "2", "yes" -> feature.setAttr(Fields.CAPITAL, 2);
case "3" -> feature.setAttr(Fields.CAPITAL, 3);
case "4" -> feature.setAttr(Fields.CAPITAL, 4);
case "5" -> feature.setAttr(Fields.CAPITAL, 5);
case "6" -> feature.setAttr(Fields.CAPITAL, 6);
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/openmaptiles/layers/Poi.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void process(Tables.OsmPoiPolygon element, FeatureCollector features) {
setupPoiFeature(element, features.centroidIfConvex(LAYER_NAME));
}

private <T extends Tables.WithSubclass & Tables.WithStation & Tables.WithFunicular & Tables.WithSport & Tables.WithInformation & Tables.WithReligion & Tables.WithMappingKey & Tables.WithName & Tables.WithIndoor & Tables.WithLayer & Tables.WithSource & Tables.WithOperator & Tables.WithNetwork> void setupPoiFeature(
private <T extends Tables.WithSubclass & Tables.WithStation & Tables.WithFunicular & Tables.WithSport & Tables.WithInformation & Tables.WithReligion & Tables.WithMappingKey & Tables.WithName & Tables.WithIndoor & Tables.WithLayer & Tables.WithSource & Tables.WithOperator & Tables.WithNetwork & Tables.WithBrand & Tables.WithRef> void setupPoiFeature(
T element, FeatureCollector.Feature output) {
String rawSubclass = element.subclass();
if ("station".equals(rawSubclass) && "subway".equals(element.station())) {
Expand All @@ -156,6 +156,18 @@ private <T extends Tables.WithSubclass & Tables.WithStation & Tables.WithFunicul
}
}

// Parcel locker without name: use either brand or operator and add ref if present
if ("parcel_locker".equals(rawSubclass) && nullOrEmpty(name)) {
name = coalesce(nullIfEmpty(element.brand()), nullIfEmpty(element.operator()));
String ref = nullIfEmpty(element.ref());
if (ref != null) {
name = name == null ? ref : (name + " " + ref);
}
if (name != null) {
tags.put("name", name);
}
}

String subclass = switch (rawSubclass) {
case "information" -> nullIfEmpty(element.information());
case "place_of_worship" -> nullIfEmpty(element.religion());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/openmaptiles/layers/Transportation.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public Transportation(Translations translations, PlanetilerConfig config, Stats
entry(FieldValues.CLASS_RACEWAY, 12),
entry(FieldValues.CLASS_TERTIARY, 11),
entry(FieldValues.CLASS_BUSWAY, 11),
entry(FieldValues.CLASS_BUS_GUIDEWAY, 11),
entry(FieldValues.CLASS_SECONDARY, 9),
entry(FieldValues.CLASS_PRIMARY, 7),
entry(FieldValues.CLASS_TRUNK, 5),
Expand Down

0 comments on commit c662ef2

Please sign in to comment.