Skip to content

Commit

Permalink
Encode whether a vector tile feature comes from an OSM node, way, or …
Browse files Browse the repository at this point in the history
…relation in the feature ID according to the formula `{vector tile feature id} = {osm id} * 10 + {1 for node, 2 for way, 3 for relation}`. See onthegomap#824

Implements featureID() to be based on id(), but not always equal to it, depending on the OSM element type.
  • Loading branch information
zstadler committed May 30, 2024
1 parent c8c4cb7 commit 4846046
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.onthegomap.planetiler.reader.SourceFeature;
import com.onthegomap.planetiler.reader.osm.OsmElement;
import com.onthegomap.planetiler.reader.osm.OsmInputFile;
import com.onthegomap.planetiler.reader.osm.OsmReader;
import com.onthegomap.planetiler.stats.ProgressLoggers;
import com.onthegomap.planetiler.stats.Stats;
import com.onthegomap.planetiler.util.Translations;
Expand Down Expand Up @@ -48,6 +49,12 @@ public Geometry worldGeometry() {
return null;
}

@Override
public long featureId() {
int offset = element.type().ordinal();
return (element.id() * 10) + offset;
}

@Override
public boolean isPoint() {
return element instanceof OsmElement.Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public OsmElement originalElement() {
return new OsmElement() {
@Override
public long id() {
return SimpleOsmFeature.this.id();
return id();
}

@Override
Expand Down Expand Up @@ -186,6 +186,11 @@ public Geometry worldGeometry() {
(worldGeometry = GeoUtils.sortPolygonsByAreaDescending(GeoUtils.latLonToWorldCoords(latLonGeometry)));
}

@Override
public long featureId() {
return id();
}

@Override
public Map<String, Object> tags() {
return tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ public final long id() {
return id;
}

/** Returns the ID for this element from the input data source (i.e. OSM element ID). */
public abstract long featureId();


/** Returns true if this element has any OSM relation info. */
public boolean hasRelationInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface OsmElement extends WithTags {
Type type();

enum Type {
OTHER,
NODE,
WAY,
RELATION
Expand All @@ -46,7 +47,7 @@ public int cost() {

@Override
public Type type() {
return null;
return Type.OTHER;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,12 @@ public boolean canBePolygon() {
public OsmElement originalElement() {
return originalElement;
}

@Override
public long featureId() {
int offset = originalElement().type().ordinal();
return (id() * 10) + offset;
}
}

/** A {@link Point} created from an OSM node. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public Geometry worldGeometry() {
);
}

@Override
public long featureId() {
int offset = originalElement().type().ordinal();
return (id() * 10) + offset;
}

@Override
public boolean isPoint() {
return true;
Expand Down

0 comments on commit 4846046

Please sign in to comment.