From 670320717a69604b08a4a493514c122a02e12ff1 Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Sun, 9 Jun 2019 18:16:01 +0200 Subject: [PATCH 1/3] Add cmd line options --tileServer and --roadClass --- README.md | 4 ++- .../barefoot/roadmap/RoadMap.java | 11 +++++-- .../sharedstreets/matcher/BatchMatcher.java | 29 +++++++++++++++++-- .../matcher/input/SharedStreetsReader.java | 6 ++-- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4d84aac..14fbcd7 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,9 @@ Run map matching system java -jar [path/to]/sharedstreets-matcher-1.1.jar --input ./event_data --output ./output_tiles --debug ./debug ``` -SharedStreets map tiles will be downloaded and cached as the matcher runs. By default tiles will be cached in `/tmp/shst_tiles/` but this path can be overriden by using the `--tmpTilePath /path/to/tmp/tiles/` option. by default tiles will be sourced from the `osm/planet-2018430` build of SharedStreets data, but source and be overridden using the `--tileSource [shst-source-id]` option. +SharedStreets map tiles will be downloaded and cached as the matcher runs. By default tiles will be cached in `/tmp/shst_tiles/` but this path can be overriden by using the `--tmpTilePath /path/to/tmp/tiles/` option. By default tiles will be sourced from the `osm/planet-2018430` build of SharedStreets data, but source and be overridden using the `--tileSource [shst-source-id]` option. +By default tiles will be loaded from server `https://tiles.sharedstreets.io/` but the server can be overridden by using the `--tileServer https://mytileserver.org/` option. +By default tiles detail level will include roads upto road class 6 (Unclassified), but, e.g. to match bike trips, this can be overriden using the `--roadClass 8` option (Note that these tiles currently are not available from the official SharedStreets tiles erver but must be custom built using sharedstreets-builder. Open debug trace files using [geojson.io](http://geojson.io/). Colored street edges show travel speed, and blue and red tick marks along edges show GPS relationship to matched point along street edge. Red tick marks are "failed matches" due to GPS or map errors (image below shows red ticks caused by missing OSM edges). diff --git a/src/main/java/io/sharedstreets/barefoot/roadmap/RoadMap.java b/src/main/java/io/sharedstreets/barefoot/roadmap/RoadMap.java index c0ddeac..4e83628 100644 --- a/src/main/java/io/sharedstreets/barefoot/roadmap/RoadMap.java +++ b/src/main/java/io/sharedstreets/barefoot/roadmap/RoadMap.java @@ -45,7 +45,10 @@ */ public class RoadMap extends Graph implements Serializable { + private final String tileServer; private final String tileSource; + private final Integer roadClass; + private final String tmpTilePath; private static final long serialVersionUID = 1L; @@ -61,11 +64,13 @@ static Collection split(BaseRoad base) { return roads; } - public RoadMap(String tmpTilePath, String tileSource) { + public RoadMap(String tmpTilePath, String tileServer, String tileSource, Integer roadClass) { this.tmpTilePath = tmpTilePath; + this.tileServer = tileServer; this.tileSource = tileSource; + this.roadClass = roadClass; index = new Index(); roads = new ArrayList<>(); @@ -123,7 +128,7 @@ public void loadTile(TileId tileId) throws IOException { if(loadedTiles.contains(tileId)) return; - SharedStreetsReader sharedStreetsReader = new SharedStreetsReader(this.tmpTilePath, this.tileSource, tileId); + SharedStreetsReader sharedStreetsReader = new SharedStreetsReader(this.tmpTilePath, this.tileServer, this.tileSource, this.roadClass, tileId); sharedStreetsReader.open(); @@ -172,7 +177,7 @@ public static RoadMap Load(RoadReader reader) throws SourceException { logger.info("inserting roads ..."); - RoadMap roadmap = new RoadMap(null, null); + RoadMap roadmap = new RoadMap(null, null, null, null); int geometryCount = 0, counter = 0; diff --git a/src/main/java/io/sharedstreets/matcher/BatchMatcher.java b/src/main/java/io/sharedstreets/matcher/BatchMatcher.java index 5047809..0b74003 100644 --- a/src/main/java/io/sharedstreets/matcher/BatchMatcher.java +++ b/src/main/java/io/sharedstreets/matcher/BatchMatcher.java @@ -73,10 +73,23 @@ public static void main(String[] args) throws Exception { .withArgName("DUBUG-DIR") .create() ); + options.addOption( OptionBuilder.withLongOpt( "tileServer" ) + .withDescription( "tile server" ) + .hasArg() + .withArgName("TILE-SERVER") + .create() ); + options.addOption( OptionBuilder.withLongOpt( "tileSource" ) .withDescription( "tile source" ) .hasArg() - .withArgName("TILE-SOUCCE") + .withArgName("TILE-SOURCE") + .create() ); + + options.addOption( OptionBuilder.withLongOpt( "roadClass" ) + .withDescription( "road class" ) + .hasArg() + .withType(PatternOptionBuilder.NUMBER_VALUE) + .withArgName("ROAD-CLASS") .create() ); options.addOption( OptionBuilder.withLongOpt( "tmpTilePath" ) @@ -106,8 +119,12 @@ public static void main(String[] args) throws Exception { options.addOption("f", "fast snap method" ); + String tileServer = "https://tiles.sharedstreets.io/"; + String tileSource = "osm/planet-180430"; + Integer roadClass = 6; + String tmpTilePath = "/tmp/shst_tiles/"; String inputPath = ""; @@ -149,10 +166,18 @@ public static void main(String[] args) throws Exception { outputPath = line.getOptionValue( "output" ); } + if( line.hasOption( "tileServer" ) ) { + tileServer = line.getOptionValue( "tileServer" ); + } + if( line.hasOption( "tileSource" ) ) { tileSource = line.getOptionValue( "tileSource" ); } + if( line.hasOption( "roadClass" ) ) { + roadClass = Math.toIntExact((Long) line.getParsedOptionValue("roadClass")); + } + if( line.hasOption( "tmpTilePath" ) ) { tmpTilePath = line.getOptionValue( "tmpTilePath" ); } @@ -196,7 +221,7 @@ public static void main(String[] args) throws Exception { // as workaround related to Flink serialization of speed matching reducer function // dynamically load map based on point data - SharedStreetsMatcher.map = new RoadMap(tmpTilePath, tileSource); + SharedStreetsMatcher.map = new RoadMap(tmpTilePath, tileServer, tileSource, roadClass); // build match engine SharedStreetsMatcher.matcher = MatcherFactory.createMatcher(trackerPath, SharedStreetsMatcher.map); diff --git a/src/main/java/io/sharedstreets/matcher/input/SharedStreetsReader.java b/src/main/java/io/sharedstreets/matcher/input/SharedStreetsReader.java index 2f70611..355217c 100644 --- a/src/main/java/io/sharedstreets/matcher/input/SharedStreetsReader.java +++ b/src/main/java/io/sharedstreets/matcher/input/SharedStreetsReader.java @@ -109,9 +109,9 @@ public SharedStreetsReader(Path tilePath) { this.tilePath = tilePath; } - public SharedStreetsReader(String tmpTilePath, String tileSource, TileId tileId) throws IOException { + public SharedStreetsReader(String tmpTilePath, String tileServer, String tileSource, Integer roadClass, TileId tileId) throws IOException { - String tileFileName = tileId.toString() + ".geometry.6.pbf"; + String tileFileName = tileId.toString() + ".geometry."+ roadClass +".pbf"; File tileTempFile = new File(tmpTilePath, tileFileName); @@ -121,7 +121,7 @@ public SharedStreetsReader(String tmpTilePath, String tileSource, TileId tileId) logger.info("loaded tile: {} {}", tileSource, tileFileName); - URL tileUrl = new URL("https://tiles.sharedstreets.io/" + tileSource + "/" + tileFileName); + URL tileUrl = new URL(tileServer + tileSource + "/" + tileFileName); FileUtils.copyURLToFile(tileUrl, tileTempFile); } From 9a0fb22d9380a9a3358041b8be728752285486c2 Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Sun, 9 Jun 2019 18:21:14 +0200 Subject: [PATCH 2/3] Replace deprecated OptionBuilder by Option --- .../sharedstreets/matcher/BatchMatcher.java | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/main/java/io/sharedstreets/matcher/BatchMatcher.java b/src/main/java/io/sharedstreets/matcher/BatchMatcher.java index 0b74003..bc0d9da 100644 --- a/src/main/java/io/sharedstreets/matcher/BatchMatcher.java +++ b/src/main/java/io/sharedstreets/matcher/BatchMatcher.java @@ -43,78 +43,78 @@ public static void main(String[] args) throws Exception { // create the Options Options options = new Options(); -// options.addOption( OptionBuilder.withLongOpt( "map" ) -// .withDescription( "path to map tiles" ) +// options.addOption( Option.builder().longOpt( "map" ) +// .desc( "path to map tiles" ) // .hasArg() -// .withArgName("MAP-DIR") -// .create() ); +// .argName("MAP-DIR") +// .build() ); - options.addOption( OptionBuilder.withLongOpt( "tracker" ) - .withDescription( "tracker.properties files" ) + options.addOption( Option.builder().longOpt( "tracker" ) + .desc( "tracker.properties files" ) .hasArg() - .withArgName("TRACKER-PATH") - .create() ); + .argName("TRACKER-PATH") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "input" ) - .withDescription( "path to input files" ) + options.addOption( Option.builder().longOpt( "input" ) + .desc( "path to input files" ) .hasArg() - .withArgName("INPUT-DIR") - .create() ); + .argName("INPUT-DIR") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "output" ) - .withDescription( "path to output" ) + options.addOption( Option.builder().longOpt( "output" ) + .desc( "path to output" ) .hasArg() - .withArgName("OUTPUT-DIR") - .create() ); + .argName("OUTPUT-DIR") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "debug" ) - .withDescription( "path to debug output" ) + options.addOption( Option.builder().longOpt( "debug" ) + .desc( "path to debug output" ) .hasArg() - .withArgName("DUBUG-DIR") - .create() ); + .argName("DUBUG-DIR") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "tileServer" ) - .withDescription( "tile server" ) + options.addOption( Option.builder().longOpt( "tileServer" ) + .desc( "tile server" ) .hasArg() - .withArgName("TILE-SERVER") - .create() ); + .argName("TILE-SERVER") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "tileSource" ) - .withDescription( "tile source" ) + options.addOption( Option.builder().longOpt( "tileSource" ) + .desc( "tile source" ) .hasArg() - .withArgName("TILE-SOURCE") - .create() ); + .argName("TILE-SOURCE") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "roadClass" ) - .withDescription( "road class" ) + options.addOption( Option.builder().longOpt( "roadClass" ) + .desc( "road class" ) .hasArg() - .withType(PatternOptionBuilder.NUMBER_VALUE) - .withArgName("ROAD-CLASS") - .create() ); + .type(PatternOptionBuilder.NUMBER_VALUE) + .argName("ROAD-CLASS") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "tmpTilePath" ) - .withDescription( "tmp tile path" ) + options.addOption( Option.builder().longOpt( "tmpTilePath" ) + .desc( "tmp tile path" ) .hasArg() - .withArgName("TMP-TILE-PATH") - .create() ); + .argName("TMP-TILE-PATH") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "dust" ) - .withDescription( "path to map dust output" ) + options.addOption( Option.builder().longOpt( "dust" ) + .desc( "path to map dust output" ) .hasArg() - .withArgName("DUST-DIR") - .create() ); + .argName("DUST-DIR") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "binSize" ) - .withDescription( "path to map dust output" ) + options.addOption( Option.builder().longOpt( "binSize" ) + .desc( "path to map dust output" ) .hasArg() - .withArgName("DUST-DIR") - .create() ); + .argName("DUST-DIR") + .build() ); - options.addOption( OptionBuilder.withLongOpt( "eventType" ) - .withDescription( "name for event output" ) + options.addOption( Option.builder().longOpt( "eventType" ) + .desc( "name for event output" ) .hasArg() - .withArgName("EVENT-TYPE") - .create() ); + .argName("EVENT-TYPE") + .build() ); options.addOption("f", "fast snap method" ); From df112c519aa8a0c6227f3b47c9ddc565ee6d9d3d Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Sun, 9 Jun 2019 18:21:56 +0200 Subject: [PATCH 3/3] Remove unused import --- src/main/java/io/sharedstreets/matcher/BatchMatcher.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/sharedstreets/matcher/BatchMatcher.java b/src/main/java/io/sharedstreets/matcher/BatchMatcher.java index bc0d9da..0b5e15d 100644 --- a/src/main/java/io/sharedstreets/matcher/BatchMatcher.java +++ b/src/main/java/io/sharedstreets/matcher/BatchMatcher.java @@ -3,7 +3,6 @@ import com.esri.core.geometry.Point; import com.esri.core.geometry.Polyline; import io.sharedstreets.barefoot.road.BaseRoad; -import io.sharedstreets.barefoot.roadmap.Loader; import io.sharedstreets.barefoot.roadmap.RoadMap; import io.sharedstreets.matcher.input.Ingest; import io.sharedstreets.matcher.model.aggregation.*;