Skip to content

Commit

Permalink
Merge pull request #55 from phanecak-maptiler/omt3_15-fix_z7-z4_roads
Browse files Browse the repository at this point in the history
Fix z7-z4 roads
  • Loading branch information
phanecak-maptiler authored Apr 25, 2024
2 parents 251bf40 + 29deac3 commit 1a71c15
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
67 changes: 58 additions & 9 deletions src/main/java/org/openmaptiles/layers/Transportation.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,23 @@ public class Transportation implements
private static final Set<String> ACCESS_NO_VALUES = Set.of(
"private", "no"
);
private static final Set<RouteNetwork> TRUNK_AS_MOTORWAY_BY_NETWORK = Set.of(
// ... and also Z4_MOTORWAY_NY_NETWORK, except those in Z5_MOTORWAYS_BY_NETWORK:
private static final Set<RouteNetwork> Z5_TRUNK_BY_NETWORK = Set.of(
RouteNetwork.CA_TRANSCANADA,
RouteNetwork.CA_PROVINCIAL_ARTERIAL,
RouteNetwork.US_INTERSTATE,
RouteNetwork.US_HIGHWAY,
RouteNetwork.GB_MOTORWAY,
RouteNetwork.GB_TRUNK,
RouteNetwork.IE_MOTORWAY,
RouteNetwork.IE_NATIONAL,
RouteNetwork.E_ROAD,
RouteNetwork.A_ROAD
);
private static final Set<RouteNetwork> Z5_MOTORWAYS_BY_NETWORK = Set.of(
RouteNetwork.GB_TRUNK,
RouteNetwork.US_HIGHWAY
);
private static final Set<String> CA_AB_PRIMARY_AS_ARTERIAL_BY_REF = Set.of(
"2", "3", "4"
);
Expand Down Expand Up @@ -194,7 +204,7 @@ public Transportation(Translations translations, PlanetilerConfig config, Stats
entry(FieldValues.CLASS_BUS_GUIDEWAY, 11),
entry(FieldValues.CLASS_SECONDARY, 9),
entry(FieldValues.CLASS_PRIMARY, 7),
entry(FieldValues.CLASS_TRUNK, 5),
entry(FieldValues.CLASS_TRUNK, 6),
entry(FieldValues.CLASS_MOTORWAY, 4)
);
}
Expand Down Expand Up @@ -245,6 +255,40 @@ private static boolean isResidentialOrUnclassified(String highway) {
return "residential".equals(highway) || "unclassified".equals(highway);
}

private static boolean isTrunkForZ5(String highway, List<RouteRelation> routeRelations) {
// Allow trunk roads that are part of a nation's most important route network to show at z5
if (!"trunk".equals(highway)) {
return false;
}
return routeRelations.stream()
.map(RouteRelation::networkType)
.filter(Objects::nonNull)
.anyMatch(Z5_TRUNK_BY_NETWORK::contains);
}

private static boolean isMotorwayWithNetworkForZ4(List<RouteRelation> routeRelations) {
// All roads in network included in osm_national_network except gb-trunk and us-highway
return routeRelations.stream()
.map(RouteRelation::networkType)
.filter(Objects::nonNull)
.filter(nt -> !Z5_MOTORWAYS_BY_NETWORK.contains(nt))
.anyMatch(Z5_TRUNK_BY_NETWORK::contains);
}

private static boolean isMotorwayWoNetworkForZ4(List<RouteRelation> routeRelations) {
// All motorways without network (e.g. EU, Asia, South America)
return routeRelations.stream()
.map(RouteRelation::networkType)
.noneMatch(Objects::nonNull);
}

private static boolean isMotorwayForZ4(List<RouteRelation> routeRelations) {
if (isMotorwayWoNetworkForZ4(routeRelations)) {
return true;
}
return isMotorwayWithNetworkForZ4(routeRelations);
}

private static boolean isDrivewayOrParkingAisle(String service) {
return FieldValues.SERVICE_PARKING_AISLE.equals(service) || FieldValues.SERVICE_DRIVEWAY.equals(service);
}
Expand Down Expand Up @@ -491,6 +535,7 @@ int getMinzoom(Tables.OsmHighwayLinestring element, String highwayClass) {
}
}
String highway = element.highway();
String construction = element.construction();

int minzoom;
if ("pier".equals(element.manMade())) {
Expand All @@ -504,18 +549,22 @@ int getMinzoom(Tables.OsmHighwayLinestring element, String highwayClass) {
case FieldValues.CLASS_TRACK, FieldValues.CLASS_PATH -> routeRank == 1 ? 12 :
(z13Paths || !nullOrEmpty(element.name()) || routeRank <= 2 || !nullOrEmpty(element.sacScale())) ? 13 : 14;
case FieldValues.CLASS_TRUNK -> {
// trunks in some networks to have same min. zoom as highway = "motorway"
String clazz = routeRelations.stream()
.map(RouteRelation::networkType)
.filter(Objects::nonNull)
.anyMatch(TRUNK_AS_MOTORWAY_BY_NETWORK::contains) ? FieldValues.CLASS_MOTORWAY : FieldValues.CLASS_TRUNK;
yield MINZOOMS.getOrDefault(clazz, Integer.MAX_VALUE);
boolean z5trunk = isTrunkForZ5(highway, routeRelations);
// and if it is good for Z5, it may be good also for Z4 (see CLASS_MOTORWAY bellow):
String clazz = FieldValues.CLASS_TRUNK;
if (z5trunk && isMotorwayWithNetworkForZ4(routeRelations)) {
clazz = FieldValues.CLASS_MOTORWAY;
z5trunk = false;
}
yield (z5trunk) ? 5 : MINZOOMS.getOrDefault(clazz, Integer.MAX_VALUE);
}
case FieldValues.CLASS_MOTORWAY -> isMotorwayForZ4(routeRelations) ?
MINZOOMS.getOrDefault(FieldValues.CLASS_MOTORWAY, Integer.MAX_VALUE) : 5;
default -> MINZOOMS.getOrDefault(baseClass, Integer.MAX_VALUE);
};
}

if (isLink(highway)) {
if (isLink(highway) || isLink(construction)) {
minzoom = Math.max(minzoom, 9);
}
return minzoom;
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/org/openmaptiles/layers/TransportationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void testDuplicateRoute() {
"_layer", "transportation",
"class", "trunk",
"network", "us-state",
"_minzoom", 5
"_minzoom", 6
), Map.of(
"_layer", "transportation_name",
"class", "trunk",
Expand Down Expand Up @@ -1174,7 +1174,7 @@ void testTransCanadaProvincialCaOnPrimaryRefOther() {
"_layer", "transportation",
"class", "trunk",
"network", "ca-provincial",
"_minzoom", 5
"_minzoom", 6
), Map.of(
"_layer", "transportation_name",
"class", "trunk",
Expand Down Expand Up @@ -1228,7 +1228,7 @@ void testTransCanadaProvincialCaMbPthRefOther() {
"_layer", "transportation",
"class", "trunk",
"network", "ca-provincial",
"_minzoom", 5
"_minzoom", 6
), Map.of(
"_layer", "transportation_name",
"class", "trunk",
Expand Down Expand Up @@ -1282,7 +1282,7 @@ void testTransCanadaProvincialCaAbPrimaryRefOther() {
"_layer", "transportation",
"class", "trunk",
"network", "ca-provincial",
"_minzoom", 5
"_minzoom", 6
), Map.of(
"_layer", "transportation_name",
"class", "trunk",
Expand Down Expand Up @@ -1336,7 +1336,7 @@ void testTransCanadaProvincialCaBcRefOther() {
"_layer", "transportation",
"class", "trunk",
"network", "ca-provincial",
"_minzoom", 5
"_minzoom", 6
), Map.of(
"_layer", "transportation_name",
"class", "trunk",
Expand All @@ -1361,7 +1361,7 @@ void testTransCanadaProvincialCaOther() {
assertFeatures(13, List.of(Map.of(
"_layer", "transportation",
"class", "trunk",
"_minzoom", 5
"_minzoom", 6
)), features);
boolean caProvPresent = StreamSupport.stream(features.spliterator(), false)
.flatMap(f -> f.getAttrsAtZoom(13).entrySet().stream())
Expand Down Expand Up @@ -1647,7 +1647,7 @@ void testIrelandTrunk() {
assertFeatures(13, List.of(Map.of(
"_layer", "transportation",
"class", "trunk",
"_minzoom", 5
"_minzoom", 4
), Map.of(
"_layer", "transportation_name",
"class", "trunk",
Expand Down Expand Up @@ -2149,7 +2149,7 @@ void testARoad() {
assertFeatures(13, List.of(Map.of(
"_layer", "transportation",
"class", "trunk",
"_minzoom", 5
"_minzoom", 6
), Map.of(
"_layer", "transportation_name",
"class", "trunk",
Expand Down

0 comments on commit 1a71c15

Please sign in to comment.