Skip to content

Commit

Permalink
Merge pull request #47 from govlt/road-reference-numbers
Browse files Browse the repository at this point in the history
Transport reference numbers
  • Loading branch information
vycius authored Apr 15, 2024
2 parents 5c33dbf + 6209caf commit 42df546
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
22 changes: 2 additions & 20 deletions vector/src/main/java/lt/lrv/basemap/layers/Transportation.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ public void processFeature(SourceFeature sf, FeatureCollector features) {

public void addTransportationFeature(String clazz, String subclass, int minZoom, SourceFeature sf, FeatureCollector features) {
var level = (int) sf.getLong("LYGMUO");
var name = nullIfEmpty(sf.getString("VARDAS"));

var expressway = clazz.equals(FieldValues.CLASS_MOTORWAY);

var ref = expressway ? nullIfEmpty(sf.getString("NUMERIS")) : null;
var refLength = ref != null ? ref.length() : null;
var expressway = "AM".equals(sf.getString("KATEGOR"));
var surface = PAVED_VALUES.contains(sf.getString("DANGA")) ? "paved" : "unpaved";

var brunnel = switch (level) {
Expand All @@ -103,21 +99,7 @@ public void addTransportationFeature(String clazz, String subclass, int minZoom,
.setMinPixelSize(0.0)
.setPixelTolerance(0.0);

// TODO transportation_name building should be moved to TransportationName class once Transportation layer becomes stable
if (ref != null || name != null) {
features.line(OpenMapTilesSchema.TransportationName.LAYER_NAME)
.setBufferPixels(OpenMapTilesSchema.TransportationName.BUFFER_SIZE)
.putAttrs(LanguageUtils.getNames(sf.tags()))
.setAttr(OpenMapTilesSchema.TransportationName.Fields.CLASS, clazz)
.setAttr(OpenMapTilesSchema.TransportationName.Fields.SUBCLASS, subclass)
.setAttr(OpenMapTilesSchema.TransportationName.Fields.REF, ref)
.setAttr(OpenMapTilesSchema.TransportationName.Fields.REF_LENGTH, refLength)
.setAttr(OpenMapTilesSchema.TransportationName.Fields.BRUNNEL, brunnel)
.setAttr(OpenMapTilesSchema.TransportationName.Fields.LEVEL, level)
.setMinPixelSize(0.0)
.setPixelTolerance(0.0)
.setMinZoom(Math.min(minZoom + 2, 14));
}
TransportationName.addFeature(clazz, subclass, brunnel, level, minZoom, sf, features);
}

@Override
Expand Down
46 changes: 46 additions & 0 deletions vector/src/main/java/lt/lrv/basemap/layers/TransportationName.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,62 @@
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.reader.SourceFeature;
import lt.lrv.basemap.openmaptiles.OpenMapTilesSchema;
import lt.lrv.basemap.utils.LanguageUtils;
import lt.lrv.basemap.utils.Utils;

import java.util.List;

import static com.onthegomap.planetiler.util.LanguageUtils.nullIfEmpty;

public class TransportationName implements OpenMapTilesSchema.TransportationName, ForwardingProfile.FeaturePostProcessor {

@Override
public void processFeature(SourceFeature sf, FeatureCollector features) {
// Currently TransportationName processFeature is handled inside Transportation
}

public static void addFeature(String clazz, String subclass, String brunnel, int level, int transportMinZoom, SourceFeature sf, FeatureCollector features) {
var name = nullIfEmpty(sf.getString("VARDAS"));
var rawRef = Utils.coalesce(nullIfEmpty(sf.getString("ENUMERIS")), nullIfEmpty(sf.getString("NUMERIS")));

if (Utils.coalesce(name, rawRef) == null) {
return;
}

var feature = features.line(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.CLASS, clazz)
.setAttr(Fields.SUBCLASS, subclass)
.setAttr(Fields.BRUNNEL, brunnel)
.setAttr(Fields.LEVEL, level)
.setMinPixelSize(0.0)
.setPixelTolerance(0.0);

if (rawRef != null) {
// Handle cases like E67/E272 by getting first road number
var ref = rawRef.contains("/") ? rawRef.split("/")[0] : rawRef;
var minZoom = getRefMinZoom(rawRef);

feature.setAttr(Fields.REF, ref)
.setAttr(Fields.REF_LENGTH, ref.length())
.setMinZoom(getRefMinZoom(rawRef))
.setSortKeyDescending(minZoom);
} else {
feature.putAttrs(LanguageUtils.getNames(sf.tags()))
.setMinZoom(Math.min(transportMinZoom + 2, 14));
}
}

private static int getRefMinZoom(String ref) {
if (ref.startsWith("E")) {
return 8;
} else if (ref.startsWith("A")) {
return 9;
} else {
return 11;
}
}

@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
if (zoom >= 14) {
Expand Down
10 changes: 10 additions & 0 deletions vector/src/main/java/lt/lrv/basemap/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lt.lrv.basemap.utils;

public class Utils {
private Utils() {
}

public static <T> T coalesce(T a, T b) {
return a != null ? a : b;
}
}

0 comments on commit 42df546

Please sign in to comment.