kopia lustrzana https://github.com/onthegomap/planetiler
add layer to shapefile
rodzic
89de82244e
commit
2544e4d1a1
|
@ -37,10 +37,12 @@ public class ShapefileReader extends SimpleReader<SimpleFeature> {
|
||||||
private final FeatureCollection<SimpleFeatureType, org.opengis.feature.simple.SimpleFeature> inputSource;
|
private final FeatureCollection<SimpleFeatureType, org.opengis.feature.simple.SimpleFeature> inputSource;
|
||||||
private final String[] attributeNames;
|
private final String[] attributeNames;
|
||||||
private final ShapefileDataStore dataStore;
|
private final ShapefileDataStore dataStore;
|
||||||
|
private final String layer;
|
||||||
private MathTransform transformToLatLon;
|
private MathTransform transformToLatLon;
|
||||||
|
|
||||||
public ShapefileReader(String sourceProjection, String sourceName, Path input) {
|
public ShapefileReader(String sourceProjection, String sourceName, Path input) {
|
||||||
super(sourceName);
|
super(sourceName);
|
||||||
|
this.layer = input.getFileName().toString().replaceAll("\\.shp$", "");
|
||||||
dataStore = open(input);
|
dataStore = open(input);
|
||||||
try {
|
try {
|
||||||
String typeName = dataStore.getTypeNames()[0];
|
String typeName = dataStore.getTypeNames()[0];
|
||||||
|
@ -119,7 +121,7 @@ public class ShapefileReader extends SimpleReader<SimpleFeature> {
|
||||||
}
|
}
|
||||||
if (latLonGeometry != null) {
|
if (latLonGeometry != null) {
|
||||||
SimpleFeature geom = SimpleFeature.create(latLonGeometry, new HashMap<>(attributeNames.length),
|
SimpleFeature geom = SimpleFeature.create(latLonGeometry, new HashMap<>(attributeNames.length),
|
||||||
sourceName, null, ++id);
|
sourceName, layer, ++id);
|
||||||
for (int i = 1; i < attributeNames.length; i++) {
|
for (int i = 1; i < attributeNames.length; i++) {
|
||||||
geom.setTag(attributeNames[i], feature.getAttribute(i));
|
geom.setTag(attributeNames[i], feature.getAttribute(i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1697,7 +1697,8 @@ class PlanetilerTests {
|
||||||
public void processFeature(SourceFeature source, FeatureCollector features) {
|
public void processFeature(SourceFeature source, FeatureCollector features) {
|
||||||
features.point("stations")
|
features.point("stations")
|
||||||
.setZoomRange(0, 14)
|
.setZoomRange(0, 14)
|
||||||
.setAttr("source", source.getSource());
|
.setAttr("source", source.getSource())
|
||||||
|
.setAttr("layer", source.getSourceLayer());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Match *.shp within [shapefile.zip, shapefile-copy.zip]
|
// Match *.shp within [shapefile.zip, shapefile-copy.zip]
|
||||||
|
@ -1715,7 +1716,7 @@ class PlanetilerTests {
|
||||||
for (var tile : tileMap.values()) {
|
for (var tile : tileMap.values()) {
|
||||||
for (var feature : tile) {
|
for (var feature : tile) {
|
||||||
feature.geometry().validate();
|
feature.geometry().validate();
|
||||||
|
assertEquals("stations", feature.attrs().get("layer"));
|
||||||
switch ((String) feature.attrs().get("source")) {
|
switch ((String) feature.attrs().get("source")) {
|
||||||
case "shapefile" -> fileCount++;
|
case "shapefile" -> fileCount++;
|
||||||
case "shapefile-glob" -> globCount++;
|
case "shapefile-glob" -> globCount++;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.onthegomap.planetiler.reader;
|
package com.onthegomap.planetiler.reader;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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 static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import com.onthegomap.planetiler.TestUtils;
|
import com.onthegomap.planetiler.TestUtils;
|
||||||
|
@ -47,7 +46,7 @@ class ShapefileReaderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testReadShapefile(Path path) {
|
private static void testReadShapefile(Path path) {
|
||||||
var reader = new ShapefileReader(null, "test", path);
|
try (var reader = new ShapefileReader(null, "test", path)) {
|
||||||
|
|
||||||
for (int i = 1; i <= 2; i++) {
|
for (int i = 1; i <= 2; i++) {
|
||||||
assertEquals(86, reader.getFeatureCount());
|
assertEquals(86, reader.getFeatureCount());
|
||||||
|
@ -60,7 +59,7 @@ class ShapefileReaderTest {
|
||||||
.sinkToConsumer("counter", 1, elem -> {
|
.sinkToConsumer("counter", 1, elem -> {
|
||||||
assertTrue(elem.getTag("name") instanceof String);
|
assertTrue(elem.getTag("name") instanceof String);
|
||||||
assertEquals("test", elem.getSource());
|
assertEquals("test", elem.getSource());
|
||||||
assertNull(elem.getSourceLayer());
|
assertEquals("stations", elem.getSourceLayer());
|
||||||
points.add(elem.latLonGeometry());
|
points.add(elem.latLonGeometry());
|
||||||
names.add(elem.getTag("name").toString());
|
names.add(elem.getTag("name").toString());
|
||||||
}).await();
|
}).await();
|
||||||
|
@ -72,4 +71,5 @@ class ShapefileReaderTest {
|
||||||
assertEquals(38.9119684, centroid.getY(), 5, "iter " + i);
|
assertEquals(38.9119684, centroid.getY(), 5, "iter " + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue