Skip to content

Commit

Permalink
Address warnings and deprecations (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Jun 17, 2024
1 parent 3c7e26d commit 4469a50
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 66 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/openmaptiles/Generate.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,16 +604,16 @@ private static List<OsmTableField> parseTableFields(Imposm3Table tableDefinition
* "class") based on the "field mapping" defined in the layer schema definition.
*/
static MultiExpression<String> generateFieldMapping(JsonNode valuesNode) {
MultiExpression<String> mapping = MultiExpression.of(new ArrayList<>());
List<MultiExpression.Entry<String>> mappings = new ArrayList<>();
valuesNode.fields().forEachRemaining(entry -> {
String field = entry.getKey();
JsonNode node = entry.getValue();
Expression expression = or(parseFieldMappingExpression(node).toList()).simplify();
if (!expression.equals(or()) && !expression.equals(and())) {
mapping.expressions().add(MultiExpression.entry(field, expression));
mappings.add(MultiExpression.entry(field, expression));
}
});
return mapping;
return MultiExpression.of(mappings);
}

private static Stream<Expression> parseFieldMappingExpression(JsonNode node) {
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/org/openmaptiles/OpenMapTilesProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* </ul>
* Layers can also subscribe to notifications when we finished processing an input source by implementing
* {@link FinishHandler} or post-process features in that layer before rendering the output tile by implementing
* {@link FeaturePostProcessor}.
* {@link LayerPostProcesser}.
*/
public class OpenMapTilesProfile extends ForwardingProfile {

Expand Down Expand Up @@ -133,7 +133,7 @@ public OpenMapTilesProfile(Translations translations, PlanetilerConfig config, S
registerSourceHandler(OSM_SOURCE, (source, features) -> {
for (var match : getTableMatches(source)) {
RowDispatch rowDispatch = match.match();
var row = rowDispatch.constructor.create(source, match.keys().get(0));
var row = rowDispatch.constructor.create(source, match.keys().getFirst());
for (Tables.RowHandler<Tables.Row> handler : rowDispatch.handlers()) {
handler.process(row, features);
}
Expand All @@ -150,16 +150,13 @@ public List<MultiExpression.Match<RowDispatch>> getTableMatches(SourceFeature in
@Override
public boolean caresAboutWikidataTranslation(OsmElement elem) {
var tags = elem.tags();
if (elem instanceof OsmElement.Node) {
return wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POINT, tags), false);
} else if (elem instanceof OsmElement.Way) {
return wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POLYGON, tags), false) ||
return switch (elem) {
case OsmElement.Node ignored -> wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POINT, tags), false);
case OsmElement.Way ignored -> wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POLYGON, tags), false) ||
wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_LINE, tags), false);
} else if (elem instanceof OsmElement.Relation) {
return wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POLYGON, tags), false);
} else {
return false;
}
case OsmElement.Relation ignored -> wikidataMappings.getOrElse(SimpleFeature.create(EMPTY_POLYGON, tags), false);
default -> false;
};
}

/*
Expand Down Expand Up @@ -265,7 +262,7 @@ public interface OsmAllProcessor {
*/
public interface IgnoreWikidata {}

private record RowDispatch(
public record RowDispatch(
Tables.Constructor constructor,
List<Tables.RowHandler<Tables.Row>> handlers
) {}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/openmaptiles/layers/Boundary.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.carrotsearch.hppc.LongObjectMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
Expand Down Expand Up @@ -95,11 +96,11 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
public class Boundary implements
OpenMapTilesSchema.Boundary,
OpenMapTilesProfile.NaturalEarthProcessor,
OpenMapTilesProfile.OsmRelationPreprocessor,
ForwardingProfile.OsmRelationPreprocessor,
OpenMapTilesProfile.OsmAllProcessor,
Tables.OsmBoundaryPolygon.Handler,
OpenMapTilesProfile.FeaturePostProcessor,
OpenMapTilesProfile.FinishHandler {
ForwardingProfile.LayerPostProcesser,
ForwardingProfile.FinishHandler {

/*
* Uses natural earth at lower zoom levels and OpenStreetMap at higher zoom levels.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/openmaptiles/layers/Building.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeometryException;
Expand All @@ -53,7 +54,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.openmaptiles.OpenMapTilesProfile;
import org.openmaptiles.generated.OpenMapTilesSchema;
import org.openmaptiles.generated.Tables;

Expand All @@ -67,8 +67,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
public class Building implements
OpenMapTilesSchema.Building,
Tables.OsmBuildingPolygon.Handler,
OpenMapTilesProfile.FeaturePostProcessor,
OpenMapTilesProfile.OsmRelationPreprocessor {
ForwardingProfile.LayerPostProcesser,
ForwardingProfile.OsmRelationPreprocessor {

/*
* Emit all buildings from OSM data at z14.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/openmaptiles/layers/Housenumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
public class Housenumber implements
OpenMapTilesSchema.Housenumber,
Tables.OsmHousenumberPoint.Handler,
ForwardingProfile.FeaturePostProcessor {
ForwardingProfile.LayerPostProcesser {

private static final Logger LOGGER = LoggerFactory.getLogger(Housenumber.class);
private static final String OSM_SEPARATOR = ";";
Expand All @@ -75,7 +75,7 @@ public class Housenumber implements
private static final String TEMP_PARTITION = "_partition";
private static final String TEMP_HAS_NAME = "_has_name";
private static final Comparator<VectorTile.Feature> BY_TEMP_HAS_NAME = Comparator
.comparing(i -> (Boolean) i.attrs().get(TEMP_HAS_NAME), Boolean::compare);
.comparing(i -> (Boolean) i.tags().get(TEMP_HAS_NAME), Boolean::compare);
private final Stats stats;

public Housenumber(Translations translations, PlanetilerConfig config, Stats stats) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public void process(Tables.OsmHousenumberPoint element, FeatureCollector feature
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> list) throws GeometryException {
// remove duplicate house numbers, features without name tag are prioritized
var items = list.stream()
.collect(Collectors.groupingBy(f -> f.attrs().get(TEMP_PARTITION)))
.collect(Collectors.groupingBy(f -> f.tags().get(TEMP_PARTITION)))
.values().stream()
.flatMap(
g -> g.stream().min(BY_TEMP_HAS_NAME).stream()
Expand All @@ -153,8 +153,8 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> l

// remove temporary attributes
for (var item : items) {
item.attrs().remove(TEMP_HAS_NAME);
item.attrs().remove(TEMP_PARTITION);
item.tags().remove(TEMP_HAS_NAME);
item.tags().remove(TEMP_PARTITION);
}

// reduces the size of some heavy z14 tiles with many repeated housenumber values by 60% or more
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/openmaptiles/layers/Landcover.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.expression.MultiExpression;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class Landcover implements
OpenMapTilesSchema.Landcover,
OpenMapTilesProfile.NaturalEarthProcessor,
Tables.OsmLandcoverPolygon.Handler,
OpenMapTilesProfile.FeaturePostProcessor {
ForwardingProfile.LayerPostProcesser {

/*
* Large ice areas come from natural earth and the rest come from OpenStreetMap at higher zoom
Expand Down Expand Up @@ -138,7 +139,7 @@ public void process(Tables.OsmLandcoverPolygon element, FeatureCollector feature
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) throws GeometryException {
if (zoom < 7 || zoom > 13) {
for (var item : items) {
item.attrs().remove(TEMP_NUM_POINTS_ATTR);
item.tags().remove(TEMP_NUM_POINTS_ATTR);
}
return items;
} else { // z7-13
Expand Down Expand Up @@ -176,7 +177,7 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
}
var merged = FeatureMerge.mergeOverlappingPolygons(toMerge, 4);
for (var item : merged) {
item.attrs().remove(tempGroupKey);
item.tags().remove(tempGroupKey);
}
result.addAll(merged);
return result;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/openmaptiles/layers/Landuse.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.geo.GeometryException;
Expand Down Expand Up @@ -67,7 +68,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,
ForwardingProfile.LayerPostProcesser,
Tables.OsmLandusePolygon.Handler {

private static final ZoomFunction<Number> MIN_PIXEL_SIZE_THRESHOLDS = ZoomFunction.fromMaxZoomThresholds(Map.of(
Expand Down Expand Up @@ -137,7 +138,7 @@ public List<VectorTile.Feature> postProcess(int zoom,
List<VectorTile.Feature> toMerge = new ArrayList<>();
List<VectorTile.Feature> result = new ArrayList<>();
for (var item : items) {
if (FieldValues.CLASS_RESIDENTIAL.equals(item.attrs().get(Fields.CLASS))) {
if (FieldValues.CLASS_RESIDENTIAL.equals(item.tags().get(Fields.CLASS))) {
toMerge.add(item);
} else {
result.add(item);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/openmaptiles/layers/MountainPeak.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import com.carrotsearch.hppc.LongIntMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
Expand Down Expand Up @@ -74,7 +75,7 @@ public class MountainPeak implements
OpenMapTilesSchema.MountainPeak,
Tables.OsmPeakPoint.Handler,
Tables.OsmMountainLinestring.Handler,
OpenMapTilesProfile.FeaturePostProcessor {
ForwardingProfile.LayerPostProcesser {

/*
* Mountain peaks come from OpenStreetMap data and are ranked by importance (based on if they
Expand Down Expand Up @@ -180,8 +181,8 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
// now that we have accurate ranks, remove anything outside the desired buffer
if (!insideTileBuffer(feature)) {
items.set(i, null);
} else if (!feature.attrs().containsKey(Fields.RANK)) {
feature.attrs().put(Fields.RANK, gridrank);
} else if (!feature.tags().containsKey(Fields.RANK)) {
feature.tags().put(Fields.RANK, gridrank);
}
}
return items;
Expand All @@ -196,7 +197,7 @@ private boolean insideTileBuffer(VectorTile.Feature feature) {
Geometry geom = feature.geometry().decode();
return !(geom instanceof Point point) || (insideTileBuffer(point.getX()) && insideTileBuffer(point.getY()));
} catch (GeometryException e) {
e.log(stats, "mountain_peak_decode_point", "Error decoding mountain peak point: " + feature.attrs());
e.log(stats, "mountain_peak_decode_point", "Error decoding mountain peak point: " + feature.tags());
return false;
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/openmaptiles/layers/Park.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.carrotsearch.hppc.LongIntMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
Expand All @@ -53,7 +54,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.onthegomap.planetiler.util.Translations;
import java.util.List;
import java.util.Locale;
import org.openmaptiles.OpenMapTilesProfile;
import org.openmaptiles.generated.OpenMapTilesSchema;
import org.openmaptiles.generated.Tables;
import org.openmaptiles.util.OmtLanguageUtils;
Expand All @@ -68,17 +68,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
public class Park implements
OpenMapTilesSchema.Park,
Tables.OsmParkPolygon.Handler,
OpenMapTilesProfile.FeaturePostProcessor {

// constants for packing the minimum zoom ordering of park labels into the sort-key field
private static final int PARK_NATIONAL_PARK_BOOST = 1 << (SORT_KEY_BITS - 1);
private static final int PARK_WIKIPEDIA_BOOST = 1 << (SORT_KEY_BITS - 2);
ForwardingProfile.LayerPostProcesser {

// constants for determining the minimum zoom level for a park label based on its area
private static final double WORLD_AREA_FOR_70K_SQUARE_METERS =
Math.pow(GeoUtils.metersToPixelAtEquator(0, Math.sqrt(70_000)) / 256d, 2);
private static final double LOG2 = Math.log(2);
private static final int PARK_AREA_RANGE = 1 << (SORT_KEY_BITS - 3);
private static final double SMALLEST_PARK_WORLD_AREA = Math.pow(4, -26); // 2^14 tiles, 2^12 pixels per tile

private final Translations translations;
Expand Down Expand Up @@ -149,7 +144,7 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
for (VectorTile.Feature feature : items) {
if (feature.geometry().geomType() == GeometryType.POINT && feature.hasGroup()) {
int count = counts.getOrDefault(feature.group(), 0) + 1;
feature.attrs().put("rank", count);
feature.tags().put("rank", count);
counts.put(feature.group(), count);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/openmaptiles/layers/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import com.carrotsearch.hppc.LongIntMap;
import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.config.PlanetilerConfig;
Expand Down Expand Up @@ -89,7 +90,7 @@ public class Place implements
Tables.OsmIslandPolygon.Handler,
Tables.OsmCityPoint.Handler,
Tables.OsmBoundaryPolygon.Handler,
OpenMapTilesProfile.FeaturePostProcessor {
ForwardingProfile.LayerPostProcesser {

/*
* Place labels locations and names come from OpenStreetMap, but we also join with natural
Expand Down Expand Up @@ -396,8 +397,8 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
for (VectorTile.Feature feature : items) {
int gridrank = groupCounts.getOrDefault(feature.group(), 1);
groupCounts.put(feature.group(), gridrank + 1);
if (!feature.attrs().containsKey(Fields.RANK)) {
feature.attrs().put(Fields.RANK, 10 + gridrank);
if (!feature.tags().containsKey(Fields.RANK)) {
feature.tags().put(Fields.RANK, 10 + gridrank);
}
}
return items;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/openmaptiles/layers/Poi.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public class Poi implements
OpenMapTilesSchema.Poi,
Tables.OsmPoiPoint.Handler,
Tables.OsmPoiPolygon.Handler,
ForwardingProfile.FeaturePostProcessor,
OpenMapTilesProfile.FinishHandler {
ForwardingProfile.LayerPostProcesser,
ForwardingProfile.FinishHandler {

/*
* process() creates the raw POI feature from OSM elements and postProcess()
Expand Down Expand Up @@ -331,8 +331,8 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
for (VectorTile.Feature feature : items) {
int gridrank = groupCounts.getOrDefault(feature.group(), 1);
groupCounts.put(feature.group(), gridrank + 1);
if (!feature.attrs().containsKey(Fields.RANK)) {
feature.attrs().put(Fields.RANK, gridrank);
if (!feature.tags().containsKey(Fields.RANK)) {
feature.tags().put(Fields.RANK, gridrank);
}
}
return items;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/openmaptiles/layers/Transportation.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.config.PlanetilerConfig;
import com.onthegomap.planetiler.expression.MultiExpression;
Expand Down Expand Up @@ -93,8 +94,8 @@ public class Transportation implements
Tables.OsmShipwayLinestring.Handler,
Tables.OsmHighwayPolygon.Handler,
OpenMapTilesProfile.NaturalEarthProcessor,
OpenMapTilesProfile.FeaturePostProcessor,
OpenMapTilesProfile.OsmRelationPreprocessor,
ForwardingProfile.LayerPostProcesser,
ForwardingProfile.OsmRelationPreprocessor,
OpenMapTilesProfile.IgnoreWikidata {

/*
Expand Down Expand Up @@ -676,16 +677,16 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
// TODO merge preserving oneway instead ignoring
int onewayId = 1;
for (var item : items) {
var oneway = item.attrs().get(Fields.ONEWAY);
var oneway = item.tags().get(Fields.ONEWAY);
if (oneway instanceof Number n && ONEWAY_VALUES.contains(n.intValue())) {
item.attrs().put(LIMIT_MERGE_TAG, onewayId++);
item.tags().put(LIMIT_MERGE_TAG, onewayId++);
}
}

var merged = FeatureMerge.mergeLineStrings(items, minLength, tolerance, BUFFER_SIZE);

for (var item : merged) {
item.attrs().remove(LIMIT_MERGE_TAG);
item.tags().remove(LIMIT_MERGE_TAG);
}
return merged;
}
Expand Down
Loading

0 comments on commit 4469a50

Please sign in to comment.