Files
planetiler-openmaptiles/src/main/java/org/openmaptiles/layers/Poi.java
Peter Hanecak b66c89d441 OpenMapTiles 3.15.0 SNAPSHOT (2) (#144)
* version bumped from 3.14.0 to 3.15.0-SNAPSHOT

* regenerate-openmaptiles.sh 07f243c5d9efa558fa539d7a31b2ae50507aaa9d (to match content of OMT PR 1457)

* SQL -> Java re-implementation of OMT PR 1457

* version bumped from 3.14.0 to 3.15.0-SNAPSHOT

* WaterName.areaToMinZoom(): improved handling of rounding and precission + added unit tests

* mvn spotless:apply

* water label min. zoom calculation simplified

* comment adjusted to be hopefully more useful

* mvn spotless:apply

* minzoom for CA_TRANSCANADA and US_INTERSTATE trunk now 4 (to match OMT PR 1440)

* minzoom for some other Canada trunks now 4 (to match OMT PR 1446)

* equals() simplified + clean-up of comments

* regenerate-openmaptiles.sh 5f7b2c11b3224759a21133381ca7d959a1f3cf51 (to match content of OMT PR 1465)

* GB road relations processing adjusted to match OMT PR 1465, e.g. handle also primary and secondary roads

* regenerate-openmaptiles.sh edb42f2db3c2b0ec37045367720eed84d7bbd71f (to match content of OMT PR 1466)

* IE road relations processing adjusted to match OMT PR 1466, e.g. handle IE roates in similar way as GB routes

* fixed handling of networkType for secondary GB routes

* clean-up: case statements simplified

* mvn spotless:apply

* clazz calculation moved up so that minzoom can be set to 3 for only lakes (to match OMT PR 1475)

* unit tests adjusted + extended to cover 'minzoom=3 fore lakes' change

* fixed minor typo from previous PR

* render POIs for large universities at low zoom (to match OMT PR 1479)

* clean-up, to make the diff/PR smaller

* regenerate-openmaptiles.sh 5e9b7c475d53a5bd5ea394da361594d3f4ce2d66 (to match content of OMT PR 1485)

* handle 'grade1' and 'tracktype' as per OMT PR 1485

* added implementation of agg_stop

It is based on OMT PR 1480 (which contains latest the fix) and the rest of older code
(which was not worling properly until the fix).

* clean-up: mvn spotless:apply

* Long ferries (as per OMT PR 1486)

* regenerate-openmaptiles.sh b3d67ed5b327c9059aeea0b3304772c6b4c8c7e9  (to match content of OMT PR 1489)

* Add aboriginal lands (as per OMT PR 1489)

* handle duplicate route relations (to match OMT PR 1501)

* regenerate-openmaptiles.sh master, to match several OMT PRs which adjusted only YML

* URLs in comments adjusted to match OMT PR 1560

* Convert separated addresses to dashed addresses

* add brunnel (and layer) attributes only for certain zoomlevels, depending on feature size (matching OMT PR 1579)

* unit test testInterstateMotorway(): brunnel tag for test line no longer available at Z8

* unit test testInterstateMotorway() clean-up: Z13 was tested twice

* minor clean-up: fixed unit test naming

* partial fix for differences in transportation_name layer

The difference is between OpenMapTiles/master (OMT) and
planetiler-openmaptiles/omt_3_15_0 (PT-OMT) (e.g. development versions).

The point is, that while PT-OMT was using limit of "8km" for Z9-Z11, OMT
is using limit "ST_Length(geometry) > 8000 / POWER(2, zoom_level - 9)
AND zoom_level BETWEEN 9 AND 11".

Some further differences still visible, hence further commits expected.

* further adjustments to better match what is done with ferries in OMT

... (as per OMT PR 1486)

But FERRY_MIN_PIXEL_SIZE is "too much" in the contexct of Planetiler,
since it is applied within tiles, hence causes gaps in lines if a line
"strikes a little" certain tile. Hence we will need to divert a little.

* ferry minLength tweak + clean-up

* mvn spotless:apply

* fixed minor typo

* minor reformatting

* ferry line length filter replaced with min. zoom calculation

hence the results are much closer to what OMT is doing for Z4-Z9

* testFerry() adjusted to match previous commit

ferry test polygon with area 1 now qualifies for min. zoom 5

* clea-up of unused stuff + mvn spotless:apply

* mvn spotless:apply

* added TODO node for follow-up pull-request/simplification

* clean-up: common getMinZoom() code moved to Utils

* minzoom clipping for brunnel was adjusted do Z9-Z12 -> test adjusted too

* clean-up

* use same tolerance for all transportation items, like OSM does

* clean-up, since ferry and non-ferry procesing is now same

* we need regenerate to work with master branch for now

* first sub-class search for agg_stop simplified a little

* contains() used instead of indexOf() for better readability

* numbers as list, not array, so that getFirst() and getLast() can be used

* better trimming and filtring of housenumbers

* adjusted handling of large house numbers

* several unit tests collapsed to one with @ParameterizedTest + @CsvSource

* AGG_STOP_SUBCLASS_ORDER simplified from Map to List

* fixed major omission from previous commit

* clamp() used to replace min()&max() combo

* agg_stop now implemented

* fixed typo in the error message

* prepare IE and GB boundary geometry outside of synchronized{}

* fixed typo in the error message

* mvn spotless:apply

* switch statements for IE and GB route networks simplified

* avoid RouteNetwork->String mapping, not needed for anyMatch()

* fix: attr. brunnel optional based on size on Z4-Z11, attr. layer optional between Z9-Z11

* tolerance change in transportation reverted, added note to README as per why

* fix: monzoom for sea&co. is Z0-Z14 based on area, for the rest it is Z3-Z14 again based on area

* clean-up: avoid doing area->side->area, do just area

* regenerate-openmaptiles.sh 6c31841f4674f15e15afde346a060cf7c22e6cdd (to match content of OMT PR 1591)

* relevant process() functions adjusted to match changes in transportation/mapping.yaml

* regenerate-openmaptiles.sh master, instead of 6c31841f4674f15e15afde346a060cf7c22e6cdd (to match content of OMT PR 1591, in a cleaner way)

* introduce duplicate housenumber filtering (matching OMT PR 1391)

* (less related) clean-up: use isEmpty() instead if size check

* testContainsHousenumber UT adjusted, since duplicate housenumber filtering is reducing amount of house numbers

* use combination of uic_ref, name, network and operator as key for agg_stop sets

If we rely on only on `uic_ref` we group together also stations which are
too far apart (even different cities). With this combo results seem OK,
e.g. all grouped stations are within around 950m (1000 pixels at Z14) of
each other (1000 being used in `PARTITION BY LabelGrid(...` in
`layers/poi/poi.sql` in OpenMapTiles).

* agg_stop comparison made more explicit, since we want to match same exact one

* mvn spotless:apply

* name now important for agg_stop processing, hence name:es (ab)used for unit tests

* agg_stop: simplified processing of nearest station

Results still same, only ordering is different:
- previously: agg_stop=1 first
- now: FIFO

* agg_stop: forther code simplification

* fixed major typo introduced in previous merge

* setMinPixelSize() + setMinZoom() used instead of areaToMinZoom()

* clean-up: unused stuff removed

* mvn spotless:apply

* setAttrWithMinSize() used instead of getBrunnelMinzoom()

getFerryMinzoom() kept since we'd like to replicate `sql_filter: ST_Length(...` from OMT

* getMinZoomForLength() no longer used, hence removed

* MIN_LENGTH value halved, to partially counter the effect of Planetiler applying the limit before merging

* clean-up: LOG2 not used, hence removed

* Revert "MIN_LENGTH value halved, to partially counter the effect of Planetiler applying the limit before merging"

This reverts commit 8fb67075289f3028d31761dcc9564fc597adab36.

* use 256px as buffer pixel override instead of MIN_LENGTH

Make sure we have enough room (=whole next tile) when checking MIN_LENGTH,
to avoid pieces of otherwise "long enough" lines to be excluded (thus
creating "holes" or missing ends) in some tiles just because length in that
particular tile is bellow limit. Given that MIN_LENGTH values translated to
pixels are quite big (compared to {@code BUFFER_SIZE}), such missing pieces
would be quite noticeable.

This improves items mainly in Z12-Z13.

* added BY_TEMP_HAS_NAME comparator to avoid its repeated construction during run-time

* duplicate houcenumber processing simplified further

* clean-up: get(0) replaced with getFirst()

* clean-up: CPU-intensive prepare() moved out of synchronized block

* regenerate-openmaptiles.sh 3cf77e2a542d8a369bb08bf2538cdde0b3effb2b (to match content of OMT PR 1423)

* unit test adjusted for POI office class changes

* regenerate-openmaptiles.sh master (to match content of OMT PR 1544)

* added charging_station implementation matching OMT PR 1544

* use setMinPixelSizeBelowZoom() instead of uniAreaToMinZoom()

* use setMinPixelSizeBelowZoom() instead of getFerryMinzoom()

* fixed unit test, to match recent tweaks

* regenerate-openmaptiles.sh master (to match content of OMT PR 1605)

* Fix university office/amenity collision (to match OSM PR 1607)

* Remove expressway from ramps

* OsmMarinePoint+ne_10m_geography_marine_polys join via name limited to 50km distance

* regenerate-openmaptiles.sh master (to match content of OMT PR 1604)

* Revert "Add aboriginal lands (as per OMT PR 1489)"

This reverts commit 899a0c5718734d5a746cdd84df2e1308614954c0.

* added handling of aboriginal_lands/OsmBoundaryPolygon into Boundary and Place layers

* big islands can now get rank lower than 3

* Add e-road and a-road for transportation z4

* testPolishHighwayIssue165() adjusted: e-road now takes precendence

* regenerate-openmaptiles.sh master (to match content of OMT PR 1627)

* regenerate-openmaptiles.sh fff7110aeb61882abfafe22d1618fbe6181d96cb (to match content of OMT PR 1620)

* Expanded road route attributes (to match OMT PR 1620)

* unrelated clean-up: use getFirst()

* adjusted handling or null and empty ref

* regenerate-openmaptiles.sh master (to match content of OMT PR 1620)

* pointOnSurface() used instead of centroid() to make sure the point is within the boundary

* adjusted deduplication of route_<n>_<something> attributes

* clean-up of some previous adjustments of importantMarinePoints

* clean-up: removed unused imports

* mvn spotless:apply
2024-03-07 09:37:35 +01:00

341 lines
14 KiB
Java

/*
Copyright (c) 2021, MapTiler.com & OpenMapTiles contributors.
All rights reserved.
Code license: BSD 3-Clause License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Design license: CC-BY 4.0
See https://github.com/openmaptiles/openmaptiles/blob/master/LICENSE.md for details on usage
*/
package org.openmaptiles.layers;
import static java.util.Map.entry;
import static org.openmaptiles.util.Utils.coalesce;
import static org.openmaptiles.util.Utils.nullIfEmpty;
import static org.openmaptiles.util.Utils.nullIfLong;
import static org.openmaptiles.util.Utils.nullOrEmpty;
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;
import com.onthegomap.planetiler.expression.MultiExpression;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.reader.SimpleFeature;
import com.onthegomap.planetiler.stats.Stats;
import com.onthegomap.planetiler.util.Parse;
import com.onthegomap.planetiler.util.Translations;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.locationtech.jts.geom.Point;
import org.openmaptiles.OpenMapTilesProfile;
import org.openmaptiles.generated.OpenMapTilesSchema;
import org.openmaptiles.generated.Tables;
import org.openmaptiles.util.OmtLanguageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Defines the logic for generating map elements for things like shops, parks, and schools in the {@code poi} layer from
* source features.
* <p>
* This class is ported to Java from
* <a href="https://github.com/openmaptiles/openmaptiles/tree/master/layers/poi">OpenMapTiles poi sql files</a>.
*/
public class Poi implements
OpenMapTilesSchema.Poi,
Tables.OsmPoiPoint.Handler,
Tables.OsmPoiPolygon.Handler,
ForwardingProfile.FeaturePostProcessor,
OpenMapTilesProfile.FinishHandler {
/*
* process() creates the raw POI feature from OSM elements and postProcess()
* assigns the feature rank from order in the tile at render-time.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(Poi.class);
private static final Map<String, Integer> CLASS_RANKS = Map.ofEntries(
entry(FieldValues.CLASS_HOSPITAL, 20),
entry(FieldValues.CLASS_RAILWAY, 40),
entry(FieldValues.CLASS_BUS, 50),
entry(FieldValues.CLASS_ATTRACTION, 70),
entry(FieldValues.CLASS_HARBOR, 75),
entry(FieldValues.CLASS_COLLEGE, 80),
entry(FieldValues.CLASS_SCHOOL, 85),
entry(FieldValues.CLASS_STADIUM, 90),
entry("zoo", 95),
entry(FieldValues.CLASS_TOWN_HALL, 100),
entry(FieldValues.CLASS_CAMPSITE, 110),
entry(FieldValues.CLASS_CEMETERY, 115),
entry(FieldValues.CLASS_PARK, 120),
entry(FieldValues.CLASS_LIBRARY, 130),
entry("police", 135),
entry(FieldValues.CLASS_POST, 140),
entry(FieldValues.CLASS_GOLF, 150),
entry(FieldValues.CLASS_SHOP, 400),
entry(FieldValues.CLASS_GROCERY, 500),
entry(FieldValues.CLASS_FAST_FOOD, 600),
entry(FieldValues.CLASS_CLOTHING_STORE, 700),
entry(FieldValues.CLASS_BAR, 800)
);
private static final Set<String> UNIVERSITY_POI_SUBCLASSES = Set.of("university", "college");
private static final List<String> AGG_STOP_SUBCLASS_ORDER = List.of(
"subway",
"tram_stop",
"bus_station",
"bus_stop"
);
private static final Comparator<Tables.OsmPoiPoint> BY_SUBCLASS = Comparator
.comparingInt(s -> AGG_STOP_SUBCLASS_ORDER.indexOf(s.subclass()));
private static final Set<String> BRAND_OPERATOR_REF_SUBCLASSES = Set.of("charging_station", "parcel_locker");
private final MultiExpression.Index<String> classMapping;
private final Translations translations;
private final Stats stats;
private final Map<String, List<Tables.OsmPoiPoint>> aggStops = new HashMap<>();
public Poi(Translations translations, PlanetilerConfig config, Stats stats) {
this.classMapping = FieldMappings.Class.index();
this.translations = translations;
this.stats = stats;
}
static int poiClassRank(String clazz) {
return CLASS_RANKS.getOrDefault(clazz, 1_000);
}
private String poiClass(String subclass, String mappingKey) {
// Special case subclass collision between office=university and amenity=university
if ("amenity".equals(mappingKey) && "university".equals(subclass)) {
return FieldValues.CLASS_COLLEGE;
}
subclass = coalesce(subclass, "");
return classMapping.getOrElse(Map.of(
"subclass", subclass,
"mapping_key", coalesce(mappingKey, "")
), subclass);
}
private int minzoom(String subclass, String mappingKey) {
boolean lowZoom = ("station".equals(subclass) && "railway".equals(mappingKey)) ||
"halt".equals(subclass) || "ferry_terminal".equals(subclass);
return lowZoom ? 12 : 14;
}
@Override
public void release() {
aggStops.clear();
}
@Override
public void process(Tables.OsmPoiPoint element, FeatureCollector features) {
if (element.uicRef() != null && AGG_STOP_SUBCLASS_ORDER.contains(element.subclass())) {
// multiple threads may update this concurrently
String aggStopKey = element.uicRef()
.concat(coalesce(nullIfEmpty(element.name()), ""))
.concat(coalesce(nullIfEmpty(element.network()), ""))
.concat(coalesce(nullIfEmpty(element.operator()), ""));
synchronized (this) {
aggStops.computeIfAbsent(aggStopKey, key -> new ArrayList<>()).add(element);
}
} else {
setupPoiFeature(element, features.point(LAYER_NAME), null);
}
}
private void processAggStop(Tables.OsmPoiPoint element, FeatureCollector.Factory featureCollectors,
Consumer<FeatureCollector.Feature> emit, Integer aggStop) {
try {
var features =
featureCollectors.get(SimpleFeature.fromWorldGeometry(element.source().worldGeometry(), element.source().id()));
setupPoiFeature(element, features.point(LAYER_NAME), aggStop);
for (var feature : features) {
emit.accept(feature);
}
} catch (GeometryException e) {
e.log(stats, "agg_stop_geometry_2",
"Error getting geometry for the stop " + element.source().id() + " (agg_stop)");
}
}
/**
* We've put aside some stops for {@code agg_stop} processing and we do that processing here.
* <p>
* The main point is to group together stops with same {@code uid_ref} and then order them first based on subclass
* (see {@code AGG_STOP_ORDER}) and then based on distance from centroid (calculated from all the stops). The first
* one gets {@code agg_stop=1}, the rest will be "normal" (e.g. no {@code agg_stop} attribute).
* <p>
* ref: <a href=
* "https://github.com/openmaptiles/openmaptiles/blob/master/layers/poi/poi_stop_agg.sql#L26,L28">poi_stop_agg.sql</a>
*/
@Override
public void finish(String sourceName, FeatureCollector.Factory featureCollectors,
Consumer<FeatureCollector.Feature> emit) {
if (OpenMapTilesProfile.OSM_SOURCE.equals(sourceName)) {
var timer = stats.startStage("agg_stop");
LOGGER.info("Processing {} agg_stop sets", aggStops.size());
for (var aggStopSet : aggStops.values()) {
if (aggStopSet.size() == 1) {
processAggStop(aggStopSet.getFirst(), featureCollectors, emit, 1);
continue;
}
Tables.OsmPoiPoint nearest = null;
try {
// find most important stops based on subclass
var firstSubclass = aggStopSet.stream().min(BY_SUBCLASS).get().subclass();
var topAggStops =
aggStopSet.stream().filter(s -> firstSubclass.equals(s.subclass())).toArray(Tables.OsmPoiPoint[]::new);
// calculate the centroid and ...
List<Point> aggStopPoints = new ArrayList<>(aggStopSet.size());
for (var aggStop : aggStopSet) {
aggStopPoints.add(aggStop.source().worldGeometry().getCentroid());
}
var aggStopCentroid = GeoUtils.combinePoints(aggStopPoints).getCentroid();
// ... find one stop nearest to the centroid
double minDistance = Double.MAX_VALUE;
for (var aggStop : topAggStops) {
double distance = aggStopCentroid.distance(aggStop.source().worldGeometry());
if (distance < minDistance || nearest == null ||
(distance == minDistance && aggStop.source().id() < nearest.source().id())) {
minDistance = distance;
nearest = aggStop;
}
}
} catch (GeometryException e) {
e.log(stats, "agg_stop_geometry_1",
"Error getting geometry for some of the stops with UIC ref. " + aggStopSet.getFirst().uicRef() +
" (agg_stop)");
// we're not able to calculate agg_stop, so simply dump the stops as they are
nearest = null;
}
// now emit the stops
final Tables.OsmPoiPoint nearestFinal = nearest; // final needed for lambda
aggStopSet
.forEach(s -> processAggStop(s, featureCollectors, emit, s == nearestFinal ? 1 : null));
}
timer.stop();
}
}
@Override
public void process(Tables.OsmPoiPolygon element, FeatureCollector features) {
setupPoiFeature(element, features.centroidIfConvex(LAYER_NAME), null);
}
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, Integer aggStop) {
String rawSubclass = element.subclass();
if ("station".equals(rawSubclass) && "subway".equals(element.station())) {
rawSubclass = "subway";
}
if ("station".equals(rawSubclass) && "yes".equals(element.funicular())) {
rawSubclass = "halt";
}
// ATM names fall back to operator, or else network
String name = element.name();
var tags = element.source().tags();
if ("atm".equals(rawSubclass) && nullOrEmpty(name)) {
name = coalesce(nullIfEmpty(element.operator()), nullIfEmpty(element.network()));
if (name != null) {
tags.put("name", name);
}
}
// Parcel locker without name: use either brand or operator and add ref if present
if (BRAND_OPERATOR_REF_SUBCLASSES.contains(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());
case "pitch" -> nullIfEmpty(element.sport());
default -> rawSubclass;
};
String poiClass = poiClass(rawSubclass, element.mappingKey());
int poiClassRank = poiClassRank(poiClass);
int rankOrder = poiClassRank + ((nullOrEmpty(name)) ? 2000 : 0);
int minzoom = minzoom(element.subclass(), element.mappingKey());
if (UNIVERSITY_POI_SUBCLASSES.contains(rawSubclass)) {
// universities that are at least 10% of a tile may appear from Z10
output.setMinPixelSizeBelowZoom(13, 80); // 80x80px is ~10% of a 256x256px tile
minzoom = 10;
}
output.setBufferPixels(BUFFER_SIZE)
.setAttr(Fields.CLASS, poiClass)
.setAttr(Fields.SUBCLASS, subclass)
.setAttr(Fields.LAYER, nullIfLong(element.layer(), 0))
.setAttr(Fields.LEVEL, Parse.parseLongOrNull(element.source().getTag("level")))
.setAttr(Fields.INDOOR, element.indoor() ? 1 : null)
.setAttr(Fields.AGG_STOP, aggStop)
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
.setPointLabelGridPixelSize(14, 64)
.setSortKey(rankOrder)
.setMinZoom(minzoom);
}
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
// infer the "rank" field from the order of features within each label grid square
LongIntMap groupCounts = Hppc.newLongIntHashMap();
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);
}
}
return items;
}
}