Verified Commit aebb4908 authored by Martin Raifer's avatar Martin Raifer
Browse files

fix code style issues

parent 30acfb5b
......@@ -59,6 +59,7 @@ import org.wololo.jts2geojson.GeoJSONReader;
import org.wololo.jts2geojson.GeoJSONWriter;
public class CreateH2Extract {
@SuppressWarnings("MissingJavadocMethod")
public static void main(String[] args) throws Exception {
CmdArgsConfig cmdArgs = new CmdArgsConfig();
JCommander coms = JCommander.newBuilder().addObject(cmdArgs).build();
......@@ -79,11 +80,14 @@ public class CreateH2Extract {
List<Double> bboxCoords = Arrays.stream(cmdArgs.bbox.split(","))
.map(Double::parseDouble).collect(Collectors.toList());
OSHDBBoundingBox bbox = new OSHDBBoundingBox(bboxCoords.get(0), bboxCoords.get(1), bboxCoords.get(2), bboxCoords.get(3));
OSHDBBoundingBox bbox = new OSHDBBoundingBox(
bboxCoords.get(0), bboxCoords.get(1), bboxCoords.get(2), bboxCoords.get(3));
Class.forName("org.h2.Driver");
try (Connection destination = DriverManager.getConnection("jdbc:h2:" + cmdArgs.outputH2, "sa", "")) {
RunScript.execute(destination, new InputStreamReader(ClassLoader.getSystemClassLoader().getResourceAsStream("empty.oshdb.sql")));
try (Connection destination =
DriverManager.getConnection("jdbc:h2:" + cmdArgs.outputH2, "sa", "")) {
RunScript.execute(destination, new InputStreamReader(
ClassLoader.getSystemClassLoader().getResourceAsStream("empty.oshdb.sql")));
System.out.println("> done preparing tables");
}
......@@ -94,17 +98,26 @@ public class CreateH2Extract {
keytableSettings.get(1),
keytableSettings.get(2),
keytableSettings.get(3));
OSHDBIgnite source = new OSHDBIgnite(cmdArgs.igniteConfig)
.prefix(cmdArgs.inPrefix);
Connection destination = DriverManager.getConnection("jdbc:h2:" + cmdArgs.outputH2, "sa", "");
PreparedStatement insertNodes = destination.prepareStatement("insert into " + TableNames.T_NODES.toString(cmdArgs.outPrefix) + " (level,id,data) values (?,?,?)");
PreparedStatement insertWays = destination.prepareStatement("insert into " + TableNames.T_WAYS.toString(cmdArgs.outPrefix) + " (level,id,data) values (?,?,?)");
PreparedStatement insertRelations = destination.prepareStatement("insert into " + TableNames.T_RELATIONS.toString(cmdArgs.outPrefix) + " (level,id,data) values (?,?,?)");
PreparedStatement insertKey = destination.prepareStatement("insert into key (id,txt) values (?,?)");
PreparedStatement insertTag = destination.prepareStatement("insert into keyvalue (keyid,valueid,txt) values (?,?,?)");
PreparedStatement insertRole = destination.prepareStatement("insert into role (id,txt) values (?,?)");
PreparedStatement selectMetadata = keytables.getConnection().prepareStatement("select key, value from metadata");
PreparedStatement insertMetadata = destination.prepareStatement("insert into metadata (key,value) values (?,?)")
OSHDBIgnite source = new OSHDBIgnite(cmdArgs.igniteConfig).prefix(cmdArgs.inPrefix);
Connection destination =
DriverManager.getConnection("jdbc:h2:" + cmdArgs.outputH2, "sa", "");
PreparedStatement insertNodes = destination.prepareStatement("insert into "
+ TableNames.T_NODES.toString(cmdArgs.outPrefix) + " (level,id,data) values (?,?,?)");
PreparedStatement insertWays = destination.prepareStatement("insert into "
+ TableNames.T_WAYS.toString(cmdArgs.outPrefix) + " (level,id,data) values (?,?,?)");
PreparedStatement insertRelations = destination.prepareStatement("insert into "
+ TableNames.T_RELATIONS.toString(cmdArgs.outPrefix)
+ " (level,id,data) values (?,?,?)");
PreparedStatement insertKey = destination.prepareStatement(
"insert into key (id,txt) values (?,?)");
PreparedStatement insertTag = destination.prepareStatement(
"insert into keyvalue (keyid,valueid,txt) values (?,?,?)");
PreparedStatement insertRole = destination.prepareStatement(
"insert into role (id,txt) values (?,?)");
PreparedStatement selectMetadata = keytables.getConnection().prepareStatement(
"select key, value from metadata");
PreparedStatement insertMetadata = destination.prepareStatement(
"insert into metadata (key,value) values (?,?)")
) {
if (!cmdArgs.skipExtractRegionCheck) {
Geometry extractRegion = (new GeoJSONReader()).read(keytables.metadata("extract.region"));
......@@ -128,7 +141,8 @@ public class CreateH2Extract {
Set<OSHDBTag> tags = new HashSet<>();
Set<OSHDBRole> roles = new HashSet<>();
TagTranslator tt = new TagTranslator(keytables.getConnection());
FilterExpression filter = (new FilterParser(tt)).parse(cmdArgs.filter != null ? cmdArgs.filter : "type:node or type:way or type:relation");
FilterExpression filter = (new FilterParser(tt)).parse(cmdArgs.filter != null
? cmdArgs.filter : "type:node or type:way or type:relation");
ScanQuery<Long, GridOSHEntity> scanQuery = new ScanQuery<>((key, cell) -> {
CellId cellId = CellId.fromLevelId(key);
......@@ -145,7 +159,8 @@ public class CreateH2Extract {
return cellIdRange.getStart().getId() <= id && cellIdRange.getEnd().getId() >= id;
});
try (
IgniteCache<Long, GridOSHEntity> cache = source.getIgnite().cache(TableNames.T_NODES.toString(cmdArgs.inPrefix));
IgniteCache<Long, GridOSHEntity> cache = source.getIgnite().cache(
TableNames.T_NODES.toString(cmdArgs.inPrefix));
QueryCursor<GridOSHEntity> cursor = cache.query(scanQuery, cacheEntry -> {
GridOSHEntity gridEntry = cacheEntry.getValue();
try {
......@@ -174,7 +189,8 @@ public class CreateH2Extract {
}
System.out.println("> nodes done");
try (
IgniteCache<Long, GridOSHEntity> cache = source.getIgnite().cache(TableNames.T_WAYS.toString(cmdArgs.inPrefix));
IgniteCache<Long, GridOSHEntity> cache = source.getIgnite()
.cache(TableNames.T_WAYS.toString(cmdArgs.inPrefix));
QueryCursor<GridOSHEntity> cursor = cache.query(scanQuery, cacheEntry -> {
GridOSHEntity gridEntry = cacheEntry.getValue();
try {
......@@ -220,8 +236,8 @@ public class CreateH2Extract {
.map(x -> (OSHRelation) x)
.filter(osh -> osh.getBoundingBox().intersects(bbox))
.filter(filter::applyOSH)
.filter(oshRel -> !cmdArgs.skipLargeRelations ||
StreamSupport.stream(oshRel.getVersions().spliterator(), false)
.filter(oshRel -> !cmdArgs.skipLargeRelations
|| StreamSupport.stream(oshRel.getVersions().spliterator(), false)
.flatMap(osmrel -> Arrays.stream(osmrel.getMembers()))
.map(OSMMember::getEntity)
.filter(Objects::nonNull)
......@@ -281,7 +297,8 @@ public class CreateH2Extract {
String metadataValue = metadata.getString(2);
insertMetadata.setString(1, metadataKey);
if (metadataKey.equalsIgnoreCase("extract.region")) {
metadataValue = (new GeoJSONWriter()).write(OSHDBGeometryBuilder.getGeometry(bbox)).toString();
metadataValue = (new GeoJSONWriter())
.write(OSHDBGeometryBuilder.getGeometry(bbox)).toString();
}
if (metadataKey.startsWith("data.")) {
// ignore raw data statistics
......@@ -301,7 +318,9 @@ public class CreateH2Extract {
}
}
private static void writeEntity(GridOSHEntity gridCell, PreparedStatement insert, Set<OSHDBTagKey> tagKeys, Set<OSHDBTag> tags, Set<OSHDBRole> roles, CmdArgsConfig cmdArgs) throws SQLException, IOException {
private static void writeEntity(GridOSHEntity gridCell, PreparedStatement insert,
Set<OSHDBTagKey> tagKeys, Set<OSHDBTag> tags, Set<OSHDBRole> roles, CmdArgsConfig cmdArgs
) throws SQLException, IOException {
// grid cell
insert.setInt(1, gridCell.getLevel());
insert.setLong(2, gridCell.getId());
......@@ -338,22 +357,31 @@ public class CreateH2Extract {
}
private static class CmdArgsConfig {
@Parameter(names = {"-i", "--ignite", "--ignite-config"}, description = "Path ot ignite-config.xml", required = true, order = 1)
@Parameter(names = {"-i", "--ignite", "--ignite-config"},
description = "Path ot ignite-config.xml", required = true, order = 1)
public File igniteConfig;
@Parameter(names = {"--input-prefix"}, description = "input cache prefix", required = false)
public String inPrefix;
@Parameter(names = {"-k", "--input-keytables"}, description = "input keytables connection, pipe separated: \"<JDBC class>|<JDBC connection string>|<DB username>|<DB password>\"", required = true, order = 2)
@Parameter(names = {"-k", "--input-keytables"},
description = "input keytables connection, pipe separated: "
+ "\"<JDBC class>|<JDBC connection string>|<DB username>|<DB password>\"",
required = true, order = 2)
public String inKeytables;
@Parameter(names = {"-b", "--bbox"}, description = "bounding box to cut out; list of 4 coordinate endpoints: min-lon, min-lat, max-lon, max-lat", required = true, order = 3)
@Parameter(names = {"-b", "--bbox"},
description = "bounding box to cut out; list of 4 coordinate endpoints: "
+ "min-lon, min-lat, max-lon, max-lat", required = true, order = 3)
public String bbox;
@Parameter(names = {"-f", "--filter"}, description = "filter to check against every osh entity. N.B. geometry-based filters will not have an effect on the output.", required = false, order = 4)
@Parameter(names = {"-f", "--filter"},
description = "filter to check against every osh entity. N.B. geometry-based filters"
+ "will not have an effect on the output.", required = false, order = 4)
public String filter;
@Parameter(names = {"-o", "--output"}, description = "Path to output H2 file", required = true, order = 5)
@Parameter(names = {"-o", "--output"},
description = "Path to output H2 file", required = true, order = 5)
public File outputH2;
//@Parameter(names = {"--output-prefix"}, description = "output table prefix", required = false)
......@@ -368,10 +396,14 @@ public class CreateH2Extract {
@Parameter(names = {"--skip-relations"}, description = "skip relations", required = false)
public boolean skipRelations = false;
@Parameter(names = {"-s", "--skip-large-relations"}, description = "skip non-intersecting relations; useful for small extracts where large relations are not needed; recommended option", required = false)
@Parameter(names = {"-s", "--skip-large-relations"},
description = "skip non-intersecting relations; useful for small extracts where "
+ "large relations are not needed; recommended option", required = false)
public boolean skipLargeRelations = false;
@Parameter(names = {"--skip-bbox-check"}, description = "skip check that tests whether the requested bounding box lies fully in the input data set; use this option with care", required = false)
@Parameter(names = {"--skip-bbox-check"},
description = "skip check that tests whether the requested bounding box lies "
+ "fully in the input data set; use this option with care", required = false)
public boolean skipExtractRegionCheck = false;
@Parameter(names = {"--help", "-h"}, help = true, order = 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment