kopia lustrzana https://github.com/onthegomap/planetiler
static imports 5
rodzic
2d3dfa9577
commit
cca7c868ed
|
@ -42,7 +42,7 @@
|
|||
</JSCodeStyleSettings>
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="5" />
|
||||
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
|
||||
<value />
|
||||
</option>
|
||||
|
|
|
@ -9,11 +9,13 @@ import org.locationtech.jts.geom.Lineal;
|
|||
public abstract class SourceFeature {
|
||||
|
||||
private final Map<String, Object> properties;
|
||||
private String source;
|
||||
private String sourceLayer;
|
||||
private final String source;
|
||||
private final String sourceLayer;
|
||||
|
||||
protected SourceFeature(Map<String, Object> properties) {
|
||||
protected SourceFeature(Map<String, Object> properties, String source, String sourceLayer) {
|
||||
this.properties = properties;
|
||||
this.source = source;
|
||||
this.sourceLayer = sourceLayer;
|
||||
}
|
||||
|
||||
public abstract Geometry latLonGeometry() throws GeometryException;
|
||||
|
@ -118,12 +120,4 @@ public abstract class SourceFeature {
|
|||
public String getSourceLayer() {
|
||||
return sourceLayer;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public void setSourceLayer(String sourceLayer) {
|
||||
this.sourceLayer = sourceLayer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package com.onthegomap.flatmap.monitoring;
|
||||
|
||||
import static com.onthegomap.flatmap.Format.formatNumeric;
|
||||
import static com.onthegomap.flatmap.Format.formatPercent;
|
||||
import static com.onthegomap.flatmap.Format.formatStorage;
|
||||
import static com.onthegomap.flatmap.Format.padLeft;
|
||||
import static com.onthegomap.flatmap.Format.padRight;
|
||||
import static com.onthegomap.flatmap.Format.*;
|
||||
|
||||
import com.graphhopper.util.Helper;
|
||||
import com.onthegomap.flatmap.Format;
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
|
|||
public class NaturalEarthReader extends Reader {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NaturalEarthReader.class);
|
||||
|
||||
private final Connection conn;
|
||||
private Path extracted;
|
||||
|
||||
|
@ -38,8 +37,8 @@ public class NaturalEarthReader extends Reader {
|
|||
}
|
||||
}
|
||||
|
||||
public NaturalEarthReader(Path input, Path tmpDir, Profile profile, Stats stats) {
|
||||
super(profile, stats);
|
||||
public NaturalEarthReader(String sourceName, Path input, Path tmpDir, Profile profile, Stats stats) {
|
||||
super(profile, stats, sourceName);
|
||||
try {
|
||||
conn = open(input, tmpDir);
|
||||
} catch (IOException | SQLException e) {
|
||||
|
@ -47,10 +46,10 @@ public class NaturalEarthReader extends Reader {
|
|||
}
|
||||
}
|
||||
|
||||
public static void process(String name, Path input, Path tmpDir, FeatureGroup writer, CommonParams config,
|
||||
public static void process(String sourceName, Path input, Path tmpDir, FeatureGroup writer, CommonParams config,
|
||||
Profile profile, Stats stats) {
|
||||
try (var reader = new NaturalEarthReader(input, tmpDir, profile, stats)) {
|
||||
reader.process(name, writer, config);
|
||||
try (var reader = new NaturalEarthReader(sourceName, input, tmpDir, profile, stats)) {
|
||||
reader.process(writer, config);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,8 +127,7 @@ public class NaturalEarthReader extends Reader {
|
|||
continue;
|
||||
}
|
||||
Geometry latLonGeometry = GeoUtils.wkbReader.read(geometry);
|
||||
ReaderFeature readerGeometry = new ReaderFeature(latLonGeometry, column.length - 1);
|
||||
readerGeometry.setSourceLayer(table);
|
||||
ReaderFeature readerGeometry = new ReaderFeature(latLonGeometry, column.length - 1, sourceName, table);
|
||||
for (int c = 0; c < column.length; c++) {
|
||||
if (c != geometryColumn) {
|
||||
Object value = rs.getObject(c + 1);
|
||||
|
|
|
@ -218,7 +218,7 @@ public class OpenStreetMapReader implements Closeable, MemoryEstimator.HasEstima
|
|||
private final boolean point;
|
||||
|
||||
public ProxyFeature(ReaderElement elem, boolean point, boolean line, boolean polygon) {
|
||||
super(ReaderElementUtils.getProperties(elem));
|
||||
super(ReaderElementUtils.getProperties(elem), null, null);
|
||||
this.point = point;
|
||||
this.line = line;
|
||||
this.polygon = polygon;
|
||||
|
|
|
@ -13,28 +13,27 @@ import com.onthegomap.flatmap.worker.Topology;
|
|||
import java.io.Closeable;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.locationtech.jts.geom.Envelope;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class Reader implements Closeable {
|
||||
|
||||
protected final Stats stats;
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
|
||||
private final Profile profile;
|
||||
protected final String sourceName;
|
||||
|
||||
public Reader(Profile profile, Stats stats) {
|
||||
public Reader(Profile profile, Stats stats, String sourceName) {
|
||||
this.stats = stats;
|
||||
this.profile = profile;
|
||||
this.sourceName = sourceName;
|
||||
}
|
||||
|
||||
public final void process(String name, FeatureGroup writer, CommonParams config) {
|
||||
public final void process(FeatureGroup writer, CommonParams config) {
|
||||
long featureCount = getCount();
|
||||
int threads = config.threads();
|
||||
Envelope latLonBounds = config.latLonBounds();
|
||||
AtomicLong featuresRead = new AtomicLong(0);
|
||||
AtomicLong featuresWritten = new AtomicLong(0);
|
||||
|
||||
var topology = Topology.start(name, stats)
|
||||
var topology = Topology.start(sourceName, stats)
|
||||
.fromGenerator("read", read())
|
||||
.addBuffer("read_queue", 1000)
|
||||
.<FeatureSort.Entry>addWorker("process", threads, (prev, next) -> {
|
||||
|
@ -47,7 +46,6 @@ public abstract class Reader implements Closeable {
|
|||
);
|
||||
while ((sourceFeature = prev.get()) != null) {
|
||||
featuresRead.incrementAndGet();
|
||||
sourceFeature.setSource(name);
|
||||
FeatureCollector features = featureCollectors.get(sourceFeature);
|
||||
if (sourceFeature.latLonGeometry().getEnvelopeInternal().intersects(latLonBounds)) {
|
||||
profile.processFeature(sourceFeature, features);
|
||||
|
@ -63,7 +61,7 @@ public abstract class Reader implements Closeable {
|
|||
writer.accept(item);
|
||||
});
|
||||
|
||||
var loggers = new ProgressLoggers(name)
|
||||
var loggers = new ProgressLoggers(sourceName)
|
||||
.addRatePercentCounter("read", featureCount, featuresRead)
|
||||
.addRateCounter("write", featuresWritten)
|
||||
.addFileSize(writer::getStorageSize)
|
||||
|
|
|
@ -15,13 +15,17 @@ public class ReaderFeature extends SourceFeature {
|
|||
private final Map<String, Object> properties;
|
||||
|
||||
public ReaderFeature(Geometry latLonGeometry, Map<String, Object> properties) {
|
||||
super(properties);
|
||||
this(latLonGeometry, properties, null, null);
|
||||
}
|
||||
|
||||
public ReaderFeature(Geometry latLonGeometry, Map<String, Object> properties, String source, String sourceLayer) {
|
||||
super(properties, source, sourceLayer);
|
||||
this.latLonGeometry = latLonGeometry;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public ReaderFeature(Geometry latLonGeometry, int numProperties) {
|
||||
this(latLonGeometry, new HashMap<>(numProperties));
|
||||
public ReaderFeature(Geometry latLonGeometry, int numProperties, String source, String sourceLayer) {
|
||||
this(latLonGeometry, new HashMap<>(numProperties), source, sourceLayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,20 +31,21 @@ public class ShapefileReader extends Reader implements Closeable {
|
|||
private final ShapefileDataStore dataStore;
|
||||
private MathTransform transformToLatLon;
|
||||
|
||||
public static void process(String sourceProjection, String name, Path input, FeatureGroup writer, CommonParams config,
|
||||
public static void process(String sourceProjection, String sourceName, Path input, FeatureGroup writer,
|
||||
CommonParams config,
|
||||
Profile profile, Stats stats) {
|
||||
try (var reader = new ShapefileReader(sourceProjection, input, profile, stats)) {
|
||||
reader.process(name, writer, config);
|
||||
try (var reader = new ShapefileReader(sourceName, sourceProjection, input, profile, stats)) {
|
||||
reader.process(writer, config);
|
||||
}
|
||||
}
|
||||
|
||||
public static void process(String name, Path input, FeatureGroup writer, CommonParams config, Profile profile,
|
||||
public static void process(String sourceName, Path input, FeatureGroup writer, CommonParams config, Profile profile,
|
||||
Stats stats) {
|
||||
process(null, name, input, writer, config, profile, stats);
|
||||
process(null, sourceName, input, writer, config, profile, stats);
|
||||
}
|
||||
|
||||
public ShapefileReader(String sourceProjection, Path input, Profile profile, Stats stats) {
|
||||
super(profile, stats);
|
||||
public ShapefileReader(String sourceProjection, String sourceName, Path input, Profile profile, Stats stats) {
|
||||
super(profile, stats, sourceName);
|
||||
dataStore = decode(input);
|
||||
try {
|
||||
String typeName = dataStore.getTypeNames()[0];
|
||||
|
@ -92,8 +93,8 @@ public class ShapefileReader extends Reader implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
public ShapefileReader(Path input, Profile profile, Stats stats) {
|
||||
this(null, input, profile, stats);
|
||||
public ShapefileReader(String name, Path input, Profile profile, Stats stats) {
|
||||
this(null, name, input, profile, stats);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,7 +114,7 @@ public class ShapefileReader extends Reader implements Closeable {
|
|||
latLonGeometry = JTS.transform(source, transformToLatLon);
|
||||
}
|
||||
if (latLonGeometry != null) {
|
||||
ReaderFeature geom = new ReaderFeature(latLonGeometry, attributeNames.length);
|
||||
ReaderFeature geom = new ReaderFeature(latLonGeometry, attributeNames.length, sourceName, null);
|
||||
for (int i = 1; i < attributeNames.length; i++) {
|
||||
geom.setTag(attributeNames[i], feature.getAttribute(i));
|
||||
}
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
package com.onthegomap.flatmap;
|
||||
|
||||
import static com.onthegomap.flatmap.TestUtils.assertSubmap;
|
||||
import static com.onthegomap.flatmap.TestUtils.newCoordinateList;
|
||||
import static com.onthegomap.flatmap.TestUtils.newLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangle;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangleCoordList;
|
||||
import static com.onthegomap.flatmap.TestUtils.round;
|
||||
import static com.onthegomap.flatmap.TestUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
|
|
@ -1,25 +1,6 @@
|
|||
package com.onthegomap.flatmap;
|
||||
|
||||
import static com.onthegomap.flatmap.TestUtils.assertSameJson;
|
||||
import static com.onthegomap.flatmap.TestUtils.assertSubmap;
|
||||
import static com.onthegomap.flatmap.TestUtils.feature;
|
||||
import static com.onthegomap.flatmap.TestUtils.newCoordinateList;
|
||||
import static com.onthegomap.flatmap.TestUtils.newLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangle;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangleCoordList;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileBottom;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileBottomLeft;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileBottomRight;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileFill;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileLeft;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileRight;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileTop;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileTopLeft;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileTopRight;
|
||||
import static com.onthegomap.flatmap.TestUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
@ -74,7 +55,7 @@ public class FlatMapTest {
|
|||
|
||||
private void processReaderFeatures(FeatureGroup featureGroup, Profile profile, CommonParams config,
|
||||
List<? extends SourceFeature> features) {
|
||||
new Reader(profile, stats) {
|
||||
new Reader(profile, stats, "test") {
|
||||
|
||||
@Override
|
||||
public long getCount() {
|
||||
|
@ -89,9 +70,7 @@ public class FlatMapTest {
|
|||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}.process(
|
||||
"test", featureGroup, config
|
||||
);
|
||||
}.process(featureGroup, config);
|
||||
}
|
||||
|
||||
private FlatMapResults runWithReaderFeatures(
|
||||
|
|
|
@ -18,13 +18,7 @@
|
|||
****************************************************************/
|
||||
package com.onthegomap.flatmap;
|
||||
|
||||
import static com.onthegomap.flatmap.TestUtils.TRANSFORM_TO_TILE;
|
||||
import static com.onthegomap.flatmap.TestUtils.decodeSilently;
|
||||
import static com.onthegomap.flatmap.TestUtils.newGeometryCollection;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.*;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.JTS_FACTORY;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
|
|
|
@ -1,19 +1,7 @@
|
|||
package com.onthegomap.flatmap.geo;
|
||||
|
||||
import static com.onthegomap.flatmap.TestUtils.newLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangle;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangleCoordList;
|
||||
import static com.onthegomap.flatmap.TestUtils.round;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.ProjectWorldCoords;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.decodeWorldX;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.decodeWorldY;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.encodeFlatLocation;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.getWorldX;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.getWorldY;
|
||||
import static com.onthegomap.flatmap.TestUtils.*;
|
||||
import static com.onthegomap.flatmap.geo.GeoUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -25,7 +25,7 @@ public class NaturalEarthReaderTest {
|
|||
@Timeout(30)
|
||||
public void testReadNaturalEarth(String filename, @TempDir Path tempDir) {
|
||||
var path = Path.of("src", "test", "resources", filename);
|
||||
try (var reader = new NaturalEarthReader(path, tempDir, new Profile.NullProfile(), new Stats.InMemory())) {
|
||||
try (var reader = new NaturalEarthReader("test", path, tempDir, new Profile.NullProfile(), new Stats.InMemory())) {
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
assertEquals(19, reader.getCount(), "iter " + i);
|
||||
|
||||
|
@ -36,6 +36,8 @@ public class NaturalEarthReaderTest {
|
|||
.sinkToConsumer("counter", 1, elem -> {
|
||||
Object elevation = elem.getTag("elevation");
|
||||
assertTrue(elevation instanceof Double, Objects.toString(elevation));
|
||||
assertEquals("test", elem.getSource());
|
||||
assertEquals("ne_110m_geography_regions_elevation_points", elem.getSourceLayer());
|
||||
points.add(elem.latLonGeometry());
|
||||
}).await();
|
||||
assertEquals(19, points.size());
|
||||
|
|
|
@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
|
||||
import com.graphhopper.reader.ReaderElement;
|
||||
import com.onthegomap.flatmap.monitoring.Stats;
|
||||
import com.onthegomap.flatmap.read.OsmInputFile;
|
||||
import com.onthegomap.flatmap.worker.Topology;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.onthegomap.flatmap.Profile;
|
||||
|
@ -18,6 +19,7 @@ import org.locationtech.jts.geom.Geometry;
|
|||
public class ShapefileReaderTest {
|
||||
|
||||
private ShapefileReader reader = new ShapefileReader(
|
||||
"test",
|
||||
Path.of("src", "test", "resources", "shapefile.zip"),
|
||||
new Profile.NullProfile(),
|
||||
new Stats.InMemory()
|
||||
|
@ -44,6 +46,8 @@ public class ShapefileReaderTest {
|
|||
.addBuffer("reader_queue", 100, 1)
|
||||
.sinkToConsumer("counter", 1, elem -> {
|
||||
assertTrue(elem.getTag("name") instanceof String);
|
||||
assertEquals("test", elem.getSource());
|
||||
assertNull(elem.getSourceLayer());
|
||||
points.add(elem.latLonGeometry());
|
||||
}).await();
|
||||
assertEquals(86, points.size());
|
||||
|
|
|
@ -1,26 +1,6 @@
|
|||
package com.onthegomap.flatmap.render;
|
||||
|
||||
import static com.onthegomap.flatmap.TestUtils.assertExactSameFeatures;
|
||||
import static com.onthegomap.flatmap.TestUtils.assertSameNormalizedFeatures;
|
||||
import static com.onthegomap.flatmap.TestUtils.decodeSilently;
|
||||
import static com.onthegomap.flatmap.TestUtils.emptyGeometry;
|
||||
import static com.onthegomap.flatmap.TestUtils.newLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiLineString;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newMultiPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPoint;
|
||||
import static com.onthegomap.flatmap.TestUtils.newPolygon;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangle;
|
||||
import static com.onthegomap.flatmap.TestUtils.rectangleCoordList;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileBottom;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileBottomLeft;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileBottomRight;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileFill;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileLeft;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileRight;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileTop;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileTopLeft;
|
||||
import static com.onthegomap.flatmap.TestUtils.tileTopRight;
|
||||
import static com.onthegomap.flatmap.TestUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
@ -55,7 +35,7 @@ public class FeatureRendererTest {
|
|||
|
||||
private FeatureCollector collector(Geometry worldGeom) {
|
||||
var latLonGeom = GeoUtils.worldToLatLonCoords(worldGeom);
|
||||
return new FeatureCollector.Factory(config).get(new ReaderFeature(latLonGeom, 0));
|
||||
return new FeatureCollector.Factory(config).get(new ReaderFeature(latLonGeom, 0, null, null));
|
||||
}
|
||||
|
||||
private Map<TileCoord, Collection<Geometry>> renderGeometry(FeatureCollector.Feature feature) {
|
||||
|
|
Ładowanie…
Reference in New Issue