Skip to content

Commit

Permalink
reduce process buffer when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 24, 2023
1 parent 6d37b7e commit ba60ac4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/openmaptiles/layers/AerodromeLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@ public class AerodromeLabel implements

private final MultiExpression.Index<String> classLookup;
private final Translations translations;
private final double pointBuffer;

public AerodromeLabel(Translations translations, PlanetilerConfig config, Stats stats) {
this.classLookup = FieldMappings.Class.index();
this.translations = translations;
this.pointBuffer = Math.min(config.maxPointBuffer(), BUFFER_SIZE);
}

@Override
public void process(Tables.OsmAerodromeLabelPoint element, FeatureCollector features) {
String clazz = classLookup.getOrElse(element.source(), FieldValues.CLASS_OTHER);
boolean important = !nullOrEmpty(element.iata()) && FieldValues.CLASS_INTERNATIONAL.equals(clazz);
features.centroid(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setBufferPixels(pointBuffer)
.setMinZoom(important ? 8 : 10)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.putAttrs(Utils.elevationTags(element.ele()))
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/openmaptiles/layers/Housenumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ public class Housenumber implements
Tables.OsmHousenumberPoint.Handler,
ForwardingProfile.FeaturePostProcessor {

public Housenumber(Translations translations, PlanetilerConfig config, Stats stats) {}
private final double pointBuffer;

public Housenumber(Translations translations, PlanetilerConfig config, Stats stats) {
this.pointBuffer = Math.min(config.maxPointBuffer(), BUFFER_SIZE);
}

@Override
public void process(Tables.OsmHousenumberPoint element, FeatureCollector features) {
features.centroidIfConvex(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setBufferPixels(pointBuffer)
.setAttr(Fields.HOUSENUMBER, element.housenumber())
.setMinZoom(14);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/openmaptiles/layers/Park.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void process(Tables.OsmParkPolygon element, FeatureCollector features) {

outline.putAttrsWithMinzoom(names, 5);

// can't reduce point buffer to maxPointBuffer because it's needed or label grid
features.pointOnSurface(LAYER_NAME).setBufferPixels(256)
.setAttr(Fields.CLASS, clazz)
.putAttrs(names)
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/openmaptiles/layers/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class Place implements
), 0);
private final Translations translations;
private final Stats stats;
private final double pointBuffer;
// spatial indexes for joining natural earth place labels with their corresponding points
// from openstreetmap
private PolygonIndex<NaturalEarthRegion> countries = PolygonIndex.create();
Expand All @@ -124,6 +125,7 @@ public class Place implements
public Place(Translations translations, PlanetilerConfig config, Stats stats) {
this.translations = translations;
this.stats = stats;
this.pointBuffer = Math.min(config.maxPointBuffer(), BUFFER_SIZE);
}

/** Returns the portion of the world that {@code squareMeters} covers where 1 is the entire planet. */
Expand Down Expand Up @@ -199,7 +201,7 @@ public void processNaturalEarth(String table, SourceFeature feature, FeatureColl
@Override
public void process(Tables.OsmContinentPoint element, FeatureCollector features) {
if (!nullOrEmpty(element.name())) {
features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
features.point(LAYER_NAME).setBufferPixels(pointBuffer)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(Fields.CLASS, FieldValues.CLASS_CONTINENT)
.setAttr(Fields.RANK, 1)
Expand Down Expand Up @@ -237,7 +239,7 @@ public void process(Tables.OsmCountryPoint element, FeatureCollector features) {

rank = Math.max(1, Math.min(6, rank));

features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
features.point(LAYER_NAME).setBufferPixels(pointBuffer)
.putAttrs(names)
.setAttr(Fields.ISO_A2, isoA2)
.setAttr(Fields.CLASS, FieldValues.CLASS_COUNTRY)
Expand All @@ -263,7 +265,7 @@ public void process(Tables.OsmStatePoint element, FeatureCollector features) {
}
int rank = Math.min(6, Math.max(1, state.rank));

features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
features.point(LAYER_NAME).setBufferPixels(pointBuffer)
.putAttrs(names)
.setAttr(Fields.CLASS, element.place())
.setAttr(Fields.RANK, rank)
Expand All @@ -285,7 +287,7 @@ public void process(Tables.OsmIslandPolygon element, FeatureCollector features)
int rank = ISLAND_AREA_RANKS.ceilingEntry(area).getValue();
int minzoom = rank <= 3 ? 8 : rank <= 4 ? 9 : 10;

features.pointOnSurface(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
features.pointOnSurface(LAYER_NAME).setBufferPixels(pointBuffer)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(Fields.CLASS, "island")
.setAttr(Fields.RANK, rank)
Expand All @@ -299,7 +301,7 @@ public void process(Tables.OsmIslandPolygon element, FeatureCollector features)

@Override
public void process(Tables.OsmIslandPoint element, FeatureCollector features) {
features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
features.point(LAYER_NAME).setBufferPixels(pointBuffer)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(Fields.CLASS, "island")
.setAttr(Fields.RANK, 7)
Expand Down Expand Up @@ -346,6 +348,7 @@ public void process(Tables.OsmCityPoint element, FeatureCollector features) {
placeType.ordinal() <= PlaceType.VILLAGE.ordinal() ? 8 :
placeType.ordinal() <= PlaceType.SUBURB.ordinal() ? 11 : 14;

// can't reduce point buffer to maxPointBuffer because it's needed or label grid
var feature = features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setAttr(Fields.CLASS, element.place())
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/openmaptiles/layers/Poi.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private <T extends Tables.WithSubclass & Tables.WithStation & Tables.WithFunicul
int poiClassRank = poiClassRank(poiClass);
int rankOrder = poiClassRank + ((nullOrEmpty(name)) ? 2000 : 0);

// can't reduce point buffer bcause it uses label grid
output.setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.CLASS, poiClass)
.setAttr(Fields.SUBCLASS, subclass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public class TransportationName implements
private final boolean limitMerge;
private final PlanetilerConfig config;
private final boolean minorRefs;
private final double pointBuffer;
private Transportation transportation;
private final LongByteMap motorwayJunctionHighwayClasses = Hppc.newLongByteHashMap();
private final LongSet motorwayJunctionNodes = new LongHashSet();
Expand All @@ -150,6 +151,7 @@ public TransportationName(Translations translations, PlanetilerConfig config, St
"transportation_name layer: include name and refs from minor road networks if not present on a way",
false
);
this.pointBuffer = Math.min(config.maxPointBuffer(), BUFFER_SIZE);
}

public void needsTransportationLayer(Transportation transportation) {
Expand Down Expand Up @@ -200,7 +202,7 @@ public void process(Tables.OsmHighwayPoint element, FeatureCollector features) {
String ref = element.ref();

features.point(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setBufferPixels(pointBuffer)
.putAttrs(OmtLanguageUtils.getNamesWithoutTranslations(element.source().tags()))
.setAttr(Fields.REF, ref)
.setAttr(Fields.REF_LENGTH, ref != null ? ref.length() : null)
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/openmaptiles/layers/WaterName.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public class WaterName implements
// may be updated concurrently by multiple threads
private final ConcurrentSkipListMap<String, Integer> importantMarinePoints = new ConcurrentSkipListMap<>();
private final Stats stats;
private final double pointBuffer;

public WaterName(Translations translations, PlanetilerConfig config, Stats stats) {
this.translations = translations;
this.stats = stats;
this.pointBuffer = Math.min(config.maxPointBuffer(), BUFFER_SIZE);
}

@Override
Expand Down Expand Up @@ -161,7 +163,7 @@ public void process(Tables.OsmMarinePoint element, FeatureCollector features) {
}
int minZoom = "ocean".equals(place) ? 0 : rank != null ? rank : 8;
features.point(LAYER_NAME)
.setBufferPixels(BUFFER_SIZE)
.setBufferPixels(pointBuffer)
.putAttrs(OmtLanguageUtils.getNames(source.tags(), translations))
.setAttr(Fields.CLASS, place)
.setAttr(Fields.INTERMITTENT, element.isIntermittent() ? 1 : 0)
Expand Down

0 comments on commit ba60ac4

Please sign in to comment.