Skip to content

Commit

Permalink
Merge 8897c6a into db0af42
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon authored Mar 15, 2023
2 parents db0af42 + 8897c6a commit c7085f9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public final class Feature {
private final Geometry geom;
private final Map<String, Object> attrs = new TreeMap<>();
private final GeometryType geometryType;
private final long sourceId;
private long id;

private int sortKey = 0;

Expand All @@ -228,16 +228,21 @@ public final class Feature {

private String numPointsAttr = null;

private Feature(String layer, Geometry geom, long sourceId) {
private Feature(String layer, Geometry geom, long id) {
this.layer = layer;
this.geom = geom;
this.geometryType = GeometryType.typeOf(geom);
this.sourceId = sourceId;
this.id = id;
}

/** Returns the original ID of the source feature that this feature came from (i.e. OSM node/way ID). */
public long getSourceId() {
return sourceId;
public long getId() {
return id;
}

public Feature setId(long id) {
this.id = id;
return this;
}

GeometryType getGeometryType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
Expand All @@ -39,9 +38,6 @@
* profile (like zoom range, min pixel size, output attributes and their zoom ranges).
*/
public class FeatureRenderer implements Consumer<FeatureCollector.Feature>, Closeable {

// generate globally-unique IDs shared by all vector tile features representing the same source feature
private static final AtomicLong idGenerator = new AtomicLong(0);
private static final Logger LOGGER = LoggerFactory.getLogger(FeatureRenderer.class);
private static final VectorTile.VectorGeometry FILL = VectorTile.encodeGeometry(GeoUtils.JTS_FACTORY
.createPolygon(GeoUtils.JTS_FACTORY.createLinearRing(new PackedCoordinateSequence.Double(new double[]{
Expand Down Expand Up @@ -95,7 +91,6 @@ private void renderGeometry(Geometry geom, FeatureCollector.Feature feature) {
}

private void renderPoint(FeatureCollector.Feature feature, Coordinate... origCoords) {
long id = idGenerator.incrementAndGet();
boolean hasLabelGrid = feature.hasLabelGrid();
Coordinate[] coords = new Coordinate[origCoords.length];
for (int i = 0; i < origCoords.length; i++) {
Expand Down Expand Up @@ -132,7 +127,7 @@ private void renderPoint(FeatureCollector.Feature feature, Coordinate... origCoo
TileCoord tile = entry.getKey();
List<List<CoordinateSequence>> result = entry.getValue();
Geometry geom = GeometryCoordinateSequences.reassemblePoints(result);
encodeAndEmitFeature(feature, id, attrs, tile, geom, groupInfo, 0);
encodeAndEmitFeature(feature, feature.getId(), attrs, tile, geom, groupInfo, 0);
emitted++;
}
stats.emittedFeatures(zoom, feature.getLayer(), emitted);
Expand Down Expand Up @@ -173,7 +168,6 @@ private void renderPoint(FeatureCollector.Feature feature, MultiPoint points) {
}

private void renderLineOrPolygon(FeatureCollector.Feature feature, Geometry input) {
long id = idGenerator.incrementAndGet();
boolean area = input instanceof Polygonal;
double worldLength = (area || input.getNumGeometries() > 1) ? 0 : input.getLength();
String numPointsAttr = feature.getNumPointsAttr();
Expand Down Expand Up @@ -217,7 +211,7 @@ private void renderLineOrPolygon(FeatureCollector.Feature feature, Geometry inpu
attrs = new HashMap<>(attrs);
attrs.put(numPointsAttr, geom.getNumPoints());
}
writeTileFeatures(z, id, feature, sliced, attrs);
writeTileFeatures(z, feature.getId(), feature, sliced, attrs);
}

stats.processedElement(area ? "polygon" : "line", feature.getLayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void testPoint() {
.setAttr("attr1", 2)
.setBufferPixels(10d)
.setBufferPixelOverrides(ZoomFunction.maxZoom(12, 100d))
.setPointLabelGridSizeAndLimit(12, 100, 10);
.setPointLabelGridSizeAndLimit(12, 100, 10)
.setId(123456789);
assertFeatures(14, List.of(
Map.of(
"_layer", "layername",
Expand All @@ -69,16 +70,19 @@ void testPoint() {
"_labelgrid_limit", 0,
"attr1", 2,
"_type", "point",
"_buffer", 10d
"_buffer", 10d,
"_id", 123456789L
)
), collector);
assertFeatures(12, List.of(
Map.of(
"_labelgrid_size", 100d,
"_labelgrid_limit", 10,
"_buffer", 100d
"_buffer", 100d,
"_id", 123456789L
)
), collector);

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ public static ComparableFeature feature(Geometry geom, Map<String, Object> attrs
public static Map<String, Object> toMap(FeatureCollector.Feature feature, int zoom) {
TreeMap<String, Object> result = new TreeMap<>(feature.getAttrsAtZoom(zoom));
Geometry geom = feature.getGeometry();
result.put("_id", feature.getId());
result.put("_minzoom", feature.getMinZoom());
result.put("_maxzoom", feature.getMaxZoom());
result.put("_buffer", feature.getBufferPixelsAtZoom(zoom));
Expand Down

0 comments on commit c7085f9

Please sign in to comment.