kopia lustrzana https://github.com/onthegomap/planetiler
close tweaks
rodzic
adcb6576d9
commit
1235d155e7
|
@ -15,7 +15,6 @@ import java.util.zip.ZipFile;
|
||||||
import org.geotools.data.FeatureSource;
|
import org.geotools.data.FeatureSource;
|
||||||
import org.geotools.data.shapefile.ShapefileDataStore;
|
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||||
import org.geotools.feature.FeatureCollection;
|
import org.geotools.feature.FeatureCollection;
|
||||||
import org.geotools.feature.FeatureIterator;
|
|
||||||
import org.geotools.geometry.jts.JTS;
|
import org.geotools.geometry.jts.JTS;
|
||||||
import org.geotools.referencing.CRS;
|
import org.geotools.referencing.CRS;
|
||||||
import org.locationtech.jts.geom.Geometry;
|
import org.locationtech.jts.geom.Geometry;
|
||||||
|
@ -29,7 +28,6 @@ import org.opengis.referencing.operation.MathTransform;
|
||||||
public class ShapefileReader extends Reader implements Closeable {
|
public class ShapefileReader extends Reader implements Closeable {
|
||||||
|
|
||||||
private final FeatureCollection<SimpleFeatureType, SimpleFeature> inputSource;
|
private final FeatureCollection<SimpleFeatureType, SimpleFeature> inputSource;
|
||||||
final FeatureIterator<SimpleFeature> featureIterator;
|
|
||||||
private String[] attributeNames;
|
private String[] attributeNames;
|
||||||
private final ShapefileDataStore dataStore;
|
private final ShapefileDataStore dataStore;
|
||||||
private MathTransform transform;
|
private MathTransform transform;
|
||||||
|
@ -66,7 +64,6 @@ public class ShapefileReader extends Reader implements Closeable {
|
||||||
for (int i = 0; i < attributeNames.length; i++) {
|
for (int i = 0; i < attributeNames.length; i++) {
|
||||||
attributeNames[i] = inputSource.getSchema().getDescriptor(i).getLocalName();
|
attributeNames[i] = inputSource.getSchema().getDescriptor(i).getLocalName();
|
||||||
}
|
}
|
||||||
this.featureIterator = inputSource.features();
|
|
||||||
} catch (IOException | FactoryException e) {
|
} catch (IOException | FactoryException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -113,20 +110,22 @@ public class ShapefileReader extends Reader implements Closeable {
|
||||||
@Override
|
@Override
|
||||||
public SourceStep<SourceFeature> read() {
|
public SourceStep<SourceFeature> read() {
|
||||||
return next -> {
|
return next -> {
|
||||||
while (featureIterator.hasNext()) {
|
try (var iter = inputSource.features()) {
|
||||||
SimpleFeature feature = featureIterator.next();
|
while (iter.hasNext()) {
|
||||||
Geometry source = (Geometry) feature.getDefaultGeometry();
|
SimpleFeature feature = iter.next();
|
||||||
Geometry transformed = source;
|
Geometry source = (Geometry) feature.getDefaultGeometry();
|
||||||
if (transform != null) {
|
Geometry transformed = source;
|
||||||
transformed = JTS.transform(source, transform);
|
if (transform != null) {
|
||||||
}
|
transformed = JTS.transform(source, transform);
|
||||||
if (transformed != null) {
|
}
|
||||||
SourceFeature geom = new ReaderFeature(transformed);
|
if (transformed != null) {
|
||||||
// TODO
|
SourceFeature geom = new ReaderFeature(transformed);
|
||||||
// for (int i = 1; i < attributeNames.length; i++) {
|
// TODO
|
||||||
// geom.setTag(attributeNames[i], feature.getAttribute(i));
|
// for (int i = 1; i < attributeNames.length; i++) {
|
||||||
// }
|
// geom.setTag(attributeNames[i], feature.getAttribute(i));
|
||||||
next.accept(geom);
|
// }
|
||||||
|
next.accept(geom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -134,7 +133,6 @@ public class ShapefileReader extends Reader implements Closeable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
featureIterator.close();
|
|
||||||
dataStore.dispose();
|
dataStore.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package com.onthegomap.flatmap.worker;
|
package com.onthegomap.flatmap.worker;
|
||||||
|
|
||||||
import com.onthegomap.flatmap.monitoring.Stats;
|
import com.onthegomap.flatmap.monitoring.Stats;
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
@ -15,7 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class WorkQueue<T> implements Closeable, Supplier<T>, Consumer<T> {
|
public class WorkQueue<T> implements AutoCloseable, Supplier<T>, Consumer<T> {
|
||||||
|
|
||||||
private final ThreadLocal<Queue<T>> itemWriteBatchProvider = new ThreadLocal<>();
|
private final ThreadLocal<Queue<T>> itemWriteBatchProvider = new ThreadLocal<>();
|
||||||
private final ThreadLocal<Queue<T>> itemReadBatchProvider = new ThreadLocal<>();
|
private final ThreadLocal<Queue<T>> itemReadBatchProvider = new ThreadLocal<>();
|
||||||
|
@ -25,7 +21,6 @@ public class WorkQueue<T> implements Closeable, Supplier<T>, Consumer<T> {
|
||||||
private final int pendingBatchesCapacity;
|
private final int pendingBatchesCapacity;
|
||||||
private volatile boolean hasIncomingData = true;
|
private volatile boolean hasIncomingData = true;
|
||||||
private final AtomicInteger pendingCount = new AtomicInteger(0);
|
private final AtomicInteger pendingCount = new AtomicInteger(0);
|
||||||
private final List<Closeable> closeables = new ArrayList<>();
|
|
||||||
|
|
||||||
public WorkQueue(String name, int capacity, int maxBatch, Stats stats) {
|
public WorkQueue(String name, int capacity, int maxBatch, Stats stats) {
|
||||||
this.pendingBatchesCapacity = capacity / maxBatch;
|
this.pendingBatchesCapacity = capacity / maxBatch;
|
||||||
|
@ -42,10 +37,7 @@ public class WorkQueue<T> implements Closeable, Supplier<T>, Consumer<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasIncomingData = false;
|
hasIncomingData = false;
|
||||||
for (Closeable closeable : closeables) {
|
} catch (Exception e) {
|
||||||
closeable.close();
|
|
||||||
}
|
|
||||||
} catch (InterruptedException | IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,9 +115,5 @@ public class WorkQueue<T> implements Closeable, Supplier<T>, Consumer<T> {
|
||||||
public int getCapacity() {
|
public int getCapacity() {
|
||||||
return pendingBatchesCapacity * batchSize;
|
return pendingBatchesCapacity * batchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alsoClose(Closeable toClose) {
|
|
||||||
closeables.add(toClose);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,21 +31,23 @@ public class ShapefileReaderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Timeout(30)
|
@Timeout(30)
|
||||||
public void testReadShapefile() {
|
public void testReadShapefileTwice() {
|
||||||
Map<String, Integer> counts = new TreeMap<>();
|
for (int i = 1; i <= 2; i++) {
|
||||||
List<Geometry> points = new ArrayList<>();
|
Map<String, Integer> counts = new TreeMap<>();
|
||||||
Topology.start("test", new InMemory())
|
List<Geometry> points = new ArrayList<>();
|
||||||
.fromGenerator("shapefile", reader.read())
|
Topology.start("test", new InMemory())
|
||||||
.addBuffer("reader_queue", 100, 1)
|
.fromGenerator("shapefile", reader.read())
|
||||||
.sinkToConsumer("counter", 1, elem -> {
|
.addBuffer("reader_queue", 100, 1)
|
||||||
String type = elem.getGeometry().getGeometryType();
|
.sinkToConsumer("counter", 1, elem -> {
|
||||||
counts.put(type, counts.getOrDefault(type, 0) + 1);
|
String type = elem.getGeometry().getGeometryType();
|
||||||
points.add(elem.getGeometry());
|
counts.put(type, counts.getOrDefault(type, 0) + 1);
|
||||||
}).await();
|
points.add(elem.getGeometry());
|
||||||
assertEquals(86, points.size());
|
}).await();
|
||||||
var gc = GeoUtils.gf.createGeometryCollection(points.toArray(new Geometry[0]));
|
assertEquals(86, points.size());
|
||||||
var centroid = gc.getCentroid();
|
var gc = GeoUtils.gf.createGeometryCollection(points.toArray(new Geometry[0]));
|
||||||
assertEquals(-77.0297995, centroid.getX(), 5);
|
var centroid = gc.getCentroid();
|
||||||
assertEquals(38.9119684, centroid.getY(), 5);
|
assertEquals(-77.0297995, centroid.getX(), 5, "iter " + i);
|
||||||
|
assertEquals(38.9119684, centroid.getY(), 5, "iter " + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue