Deterministic IDs on SimpleFeatures (#791)

pull/796/head
Michael Barry 2024-01-15 06:22:30 -05:00 zatwierdzone przez GitHub
rodzic 902651fda8
commit 5a7757435d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 24 dodań i 13 usunięć

Wyświetl plik

@ -75,6 +75,7 @@ import vector_tile.VectorTileProto;
*/ */
@NotThreadSafe @NotThreadSafe
public class VectorTile { public class VectorTile {
public static final long NO_FEATURE_ID = 0;
private static final Logger LOGGER = LoggerFactory.getLogger(VectorTile.class); private static final Logger LOGGER = LoggerFactory.getLogger(VectorTile.class);
@ -534,7 +535,7 @@ public class VectorTile {
.setType(feature.geometry().geomType().asProtobufType()) .setType(feature.geometry().geomType().asProtobufType())
.addAllGeometry(Ints.asList(feature.geometry().commands())); .addAllGeometry(Ints.asList(feature.geometry().commands()));
if (feature.id >= 0) { if (feature.id != NO_FEATURE_ID) {
featureBuilder.setId(feature.id); featureBuilder.setId(feature.id);
} }

Wyświetl plik

@ -1,5 +1,6 @@
package com.onthegomap.planetiler.reader; package com.onthegomap.planetiler.reader;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.geo.GeoUtils; import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.reader.osm.OsmElement; import com.onthegomap.planetiler.reader.osm.OsmElement;
import com.onthegomap.planetiler.reader.osm.OsmReader; import com.onthegomap.planetiler.reader.osm.OsmReader;
@ -8,7 +9,6 @@ import com.onthegomap.planetiler.reader.osm.OsmSourceFeature;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Lineal; import org.locationtech.jts.geom.Lineal;
@ -21,14 +21,12 @@ import org.locationtech.jts.geom.Puntal;
*/ */
public class SimpleFeature extends SourceFeature { public class SimpleFeature extends SourceFeature {
private static final AtomicLong idGenerator = new AtomicLong(0);
private final Map<String, Object> tags; private final Map<String, Object> tags;
private Geometry worldGeometry; private Geometry worldGeometry;
private Geometry latLonGeometry; private Geometry latLonGeometry;
private SimpleFeature(Geometry latLonGeometry, Geometry worldGeometry, Map<String, Object> tags, String source, private SimpleFeature(Geometry latLonGeometry, Geometry worldGeometry, Map<String, Object> tags, String source,
String sourceLayer, String sourceLayer, long id, List<OsmReader.RelationMember<OsmRelationInfo>> relations) {
long id, List<OsmReader.RelationMember<OsmRelationInfo>> relations) {
super(tags, source, sourceLayer, relations, id); super(tags, source, sourceLayer, relations, id);
assert latLonGeometry == null || worldGeometry == null : "Cannot specify both a world and lat/lon geometry"; assert latLonGeometry == null || worldGeometry == null : "Cannot specify both a world and lat/lon geometry";
this.latLonGeometry = latLonGeometry; this.latLonGeometry = latLonGeometry;
@ -53,29 +51,39 @@ public class SimpleFeature extends SourceFeature {
} }
/** Returns a new feature with no tags and a geometry specified in latitude/longitude coordinates. */ /** Returns a new feature with no tags and a geometry specified in latitude/longitude coordinates. */
public static SimpleFeature fromLatLonGeometry(Geometry latLonGeometry) { public static SimpleFeature fromLatLonGeometry(Geometry latLonGeometry, long id) {
return new SimpleFeature(latLonGeometry, null, Map.of(), null, null, idGenerator.incrementAndGet(), null); return new SimpleFeature(latLonGeometry, null, Map.of(), null, null, id, null);
}
/** Alias for {@link #fromLatLonGeometry(Geometry, long)} with no ID set. */
public static SimpleFeature fromLatLonGeometry(Geometry worldGeometry) {
return fromLatLonGeometry(worldGeometry, VectorTile.NO_FEATURE_ID);
} }
/** /**
* Returns a new feature with no tags and a geometry specified in world web mercator coordinates where (0,0) is the * Returns a new feature with no tags and a geometry specified in world web mercator coordinates where (0,0) is the
* northwest and (1,1) is the southeast corner of the planet. * northwest and (1,1) is the southeast corner of the planet.
*/ */
public static SimpleFeature fromWorldGeometry(Geometry worldGeometry) { public static SimpleFeature fromWorldGeometry(Geometry worldGeometry, long id) {
return new SimpleFeature(null, worldGeometry, Map.of(), null, null, idGenerator.incrementAndGet(), null); return new SimpleFeature(null, worldGeometry, Map.of(), null, null, id, null);
} }
/** Returns a new feature with empty geometry and no tags. */ /** Alias for {@link #fromWorldGeometry(Geometry, long)} with no ID set. */
public static SimpleFeature empty() { public static SimpleFeature fromWorldGeometry(Geometry worldGeometry) {
return fromWorldGeometry(GeoUtils.JTS_FACTORY.createGeometryCollection()); return fromWorldGeometry(worldGeometry, VectorTile.NO_FEATURE_ID);
} }
/** /**
* Returns a new feature without source information if you need a {@code SimpleFeature} but don't plan on passing it * Returns a new feature without source information if you need a {@code SimpleFeature} but don't plan on passing it
* to a profile. * to a profile.
*/ */
public static SimpleFeature create(Geometry latLonGeometry, Map<String, Object> tags, long id) {
return new SimpleFeature(latLonGeometry, null, tags, null, null, id, null);
}
/** Alias for {@link #create(Geometry, Map, long)} with no ID set. */
public static SimpleFeature create(Geometry latLonGeometry, Map<String, Object> tags) { public static SimpleFeature create(Geometry latLonGeometry, Map<String, Object> tags) {
return new SimpleFeature(latLonGeometry, null, tags, null, null, idGenerator.incrementAndGet(), null); return create(latLonGeometry, tags, VectorTile.NO_FEATURE_ID);
} }
private static class SimpleOsmFeature extends SimpleFeature implements OsmSourceFeature { private static class SimpleOsmFeature extends SimpleFeature implements OsmSourceFeature {

Wyświetl plik

@ -223,8 +223,10 @@ public class CompareArchives {
} }
} }
}); });
Format format = Format.defaultInstance();
ProgressLoggers loggers = ProgressLoggers.create() ProgressLoggers loggers = ProgressLoggers.create()
.addRateCounter("tiles", total) .addRateCounter("tiles", total)
.add(() -> " diffs: [ " + format.numeric(diffs, true) + " ]")
.newLine() .newLine()
.addPipelineStats(pipeline) .addPipelineStats(pipeline)
.newLine() .newLine()