kopia lustrzana https://github.com/onthegomap/planetiler
refactoring
rodzic
7688ef111b
commit
c1b5418452
|
@ -0,0 +1,29 @@
|
|||
package com.onthegomap.flatmap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
private FileUtils() {
|
||||
}
|
||||
|
||||
public static Stream<Path> walkFileSystem(FileSystem fileSystem) {
|
||||
return StreamSupport.stream(fileSystem.getRootDirectories().spliterator(), false)
|
||||
.flatMap(rootDirectory -> {
|
||||
try {
|
||||
return Files.walk(rootDirectory);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Unable to walk " + rootDirectory + " in " + fileSystem, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean hasExtension(Path path, String extension) {
|
||||
return path.toString().toLowerCase().endsWith("." + extension.toLowerCase());
|
||||
}
|
||||
}
|
|
@ -4,9 +4,11 @@ import com.onthegomap.flatmap.collections.FeatureGroup;
|
|||
import com.onthegomap.flatmap.collections.FeatureSort;
|
||||
import com.onthegomap.flatmap.collections.LongLongMap;
|
||||
import com.onthegomap.flatmap.profiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.flatmap.reader.NaturalEarthReader;
|
||||
import com.onthegomap.flatmap.reader.OpenStreetMapReader;
|
||||
import com.onthegomap.flatmap.reader.ShapefileReader;
|
||||
import com.onthegomap.flatmap.read.NaturalEarthReader;
|
||||
import com.onthegomap.flatmap.read.OpenStreetMapReader;
|
||||
import com.onthegomap.flatmap.read.OsmInputFile;
|
||||
import com.onthegomap.flatmap.read.ShapefileReader;
|
||||
import com.onthegomap.flatmap.write.MbtilesWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.onthegomap.flatmap;
|
||||
|
||||
import com.graphhopper.reader.ReaderRelation;
|
||||
import com.onthegomap.flatmap.reader.OpenStreetMapReader;
|
||||
import com.onthegomap.flatmap.read.OpenStreetMapReader;
|
||||
import java.util.List;
|
||||
|
||||
public interface Profile {
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.graphhopper.reader.ReaderElement;
|
|||
import com.graphhopper.util.StopWatch;
|
||||
import com.onthegomap.flatmap.monitoring.ProgressLoggers;
|
||||
import com.onthegomap.flatmap.monitoring.Stats;
|
||||
import com.onthegomap.flatmap.read.OsmInputFile;
|
||||
import com.onthegomap.flatmap.worker.Topology;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.onthegomap.flatmap.monitoring;
|
||||
|
||||
import com.graphhopper.util.StopWatch;
|
||||
import com.onthegomap.flatmap.Mbtiles;
|
||||
import com.onthegomap.flatmap.write.Mbtiles;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.onthegomap.flatmap.Profile;
|
|||
import com.onthegomap.flatmap.RenderableFeatures;
|
||||
import com.onthegomap.flatmap.SourceFeature;
|
||||
import com.onthegomap.flatmap.VectorTileEncoder;
|
||||
import com.onthegomap.flatmap.reader.OpenStreetMapReader;
|
||||
import com.onthegomap.flatmap.read.OpenStreetMapReader;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package com.onthegomap.flatmap.reader;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import com.onthegomap.flatmap.FileUtils;
|
||||
import com.onthegomap.flatmap.Profile;
|
||||
import com.onthegomap.flatmap.SourceFeature;
|
||||
import com.onthegomap.flatmap.geo.GeoUtils;
|
||||
import com.onthegomap.flatmap.monitoring.Stats;
|
||||
import com.onthegomap.flatmap.worker.Topology;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
@ -17,7 +18,6 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipFile;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -44,17 +44,16 @@ public class NaturalEarthReader extends Reader {
|
|||
|
||||
private Connection open(Path path, Path tmpLocation) throws IOException, SQLException {
|
||||
String uri = "jdbc:sqlite:" + path.toAbsolutePath();
|
||||
if (path.toString().toLowerCase().endsWith(".zip")) {
|
||||
if (FileUtils.hasExtension(path, "zip")) {
|
||||
Path toOpen = tmpLocation == null ? Files.createTempFile("sqlite", "natearth") : tmpLocation;
|
||||
extracted = toOpen;
|
||||
File file = path.toFile();
|
||||
try (ZipFile zipFile = new ZipFile(file)) {
|
||||
var zipEntry = zipFile.stream()
|
||||
.filter(entry -> entry.getName().endsWith(".sqlite"))
|
||||
try (var zipFs = FileSystems.newFileSystem(path)) {
|
||||
var zipEntry = FileUtils.walkFileSystem(zipFs)
|
||||
.filter(entry -> FileUtils.hasExtension(entry, "sqlite"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("No .sqlite file found inside " + file.getName()));
|
||||
.orElseThrow(() -> new IllegalArgumentException("No .sqlite file found inside " + path));
|
||||
LOGGER.info("unzipping " + path.toAbsolutePath() + " to " + extracted);
|
||||
Files.copy(zipFile.getInputStream(zipEntry), extracted, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.copy(Files.newInputStream(zipEntry), extracted, StandardCopyOption.REPLACE_EXISTING);
|
||||
extracted.toFile().deleteOnExit();
|
||||
}
|
||||
uri = "jdbc:sqlite:" + toOpen.toAbsolutePath();
|
|
@ -1,4 +1,4 @@
|
|||
package com.onthegomap.flatmap.reader;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import com.carrotsearch.hppc.LongHashSet;
|
||||
import com.graphhopper.coll.GHLongHashSet;
|
||||
|
@ -10,7 +10,6 @@ import com.graphhopper.reader.ReaderRelation;
|
|||
import com.graphhopper.reader.ReaderWay;
|
||||
import com.onthegomap.flatmap.CommonParams;
|
||||
import com.onthegomap.flatmap.FeatureRenderer;
|
||||
import com.onthegomap.flatmap.OsmInputFile;
|
||||
import com.onthegomap.flatmap.Profile;
|
||||
import com.onthegomap.flatmap.RenderableFeature;
|
||||
import com.onthegomap.flatmap.RenderableFeatures;
|
|
@ -1,10 +1,11 @@
|
|||
package com.onthegomap.flatmap;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.graphhopper.reader.ReaderElement;
|
||||
import com.graphhopper.reader.osm.pbf.PbfDecoder;
|
||||
import com.graphhopper.reader.osm.pbf.PbfStreamSplitter;
|
||||
import com.graphhopper.reader.osm.pbf.Sink;
|
||||
import com.onthegomap.flatmap.BoundsProvider;
|
||||
import com.onthegomap.flatmap.worker.Topology;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
|
@ -1,4 +1,4 @@
|
|||
package com.onthegomap.flatmap.reader;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import com.onthegomap.flatmap.CommonParams;
|
||||
import com.onthegomap.flatmap.FeatureRenderer;
|
|
@ -1,4 +1,4 @@
|
|||
package com.onthegomap.flatmap.reader;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import com.onthegomap.flatmap.SourceFeature;
|
||||
import java.util.HashMap;
|
|
@ -1,7 +1,8 @@
|
|||
package com.onthegomap.flatmap.reader;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import com.onthegomap.flatmap.CommonParams;
|
||||
import com.onthegomap.flatmap.FeatureRenderer;
|
||||
import com.onthegomap.flatmap.FileUtils;
|
||||
import com.onthegomap.flatmap.Profile;
|
||||
import com.onthegomap.flatmap.SourceFeature;
|
||||
import com.onthegomap.flatmap.collections.FeatureGroup;
|
||||
|
@ -10,9 +11,8 @@ import com.onthegomap.flatmap.worker.Topology;
|
|||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import org.geotools.data.FeatureSource;
|
||||
import org.geotools.data.shapefile.ShapefileDataStore;
|
||||
import org.geotools.feature.FeatureCollection;
|
||||
|
@ -75,16 +75,15 @@ public class ShapefileReader extends Reader implements Closeable {
|
|||
|
||||
URI uri;
|
||||
|
||||
if (path.toString().toLowerCase().endsWith(".zip")) {
|
||||
try (ZipFile zip = new ZipFile(path.toFile())) {
|
||||
String shapeFileInZip = zip.stream()
|
||||
.map(ZipEntry::getName)
|
||||
.filter(z -> z.endsWith(".shp"))
|
||||
if (FileUtils.hasExtension(path, "zip")) {
|
||||
try (var zipFs = FileSystems.newFileSystem(path)) {
|
||||
Path shapeFileInZip = FileUtils.walkFileSystem(zipFs)
|
||||
.filter(z -> FileUtils.hasExtension(z, "shp"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("No .shp file found inside " + path));
|
||||
uri = URI.create("jar:file:" + path.toAbsolutePath() + "!/" + shapeFileInZip);
|
||||
uri = shapeFileInZip.toUri();
|
||||
}
|
||||
} else if (path.toString().toLowerCase().endsWith(".shp")) {
|
||||
} else if (FileUtils.hasExtension(path, "shp")) {
|
||||
uri = path.toUri();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid shapefile input: " + path + " must be zip or shp");
|
|
@ -1,4 +1,4 @@
|
|||
package com.onthegomap.flatmap;
|
||||
package com.onthegomap.flatmap.write;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@ -1,5 +1,8 @@
|
|||
package com.onthegomap.flatmap;
|
||||
package com.onthegomap.flatmap.write;
|
||||
|
||||
import com.onthegomap.flatmap.CommonParams;
|
||||
import com.onthegomap.flatmap.Profile;
|
||||
import com.onthegomap.flatmap.VectorTileEncoder;
|
||||
import com.onthegomap.flatmap.collections.FeatureGroup;
|
||||
import com.onthegomap.flatmap.geo.TileCoord;
|
||||
import com.onthegomap.flatmap.monitoring.ProgressLoggers;
|
|
@ -1,5 +0,0 @@
|
|||
package com.onthegomap.flatmap;
|
||||
|
||||
public class MbtilesTest {
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package com.onthegomap.flatmap;
|
||||
|
||||
public class MbtilesWriterTest {
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.onthegomap.flatmap.reader;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
@ -1,9 +1,10 @@
|
|||
package com.onthegomap.flatmap;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
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,4 +1,4 @@
|
|||
package com.onthegomap.flatmap.reader;
|
||||
package com.onthegomap.flatmap.read;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
@ -0,0 +1,5 @@
|
|||
package com.onthegomap.flatmap.write;
|
||||
|
||||
public class MbtilesTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.onthegomap.flatmap.write;
|
||||
|
||||
public class MbtilesWriterTest {
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue