Reading Osm Map (or Other Format) Files To Determine Shortest Distance From Coordinate To Path
Solution 1:
There are some misconceptions. First, the OSM file is not the map file. The OSM file can be used to create a format to make map rendering fast e.g. mapsforge format does this.
With e.g. GraphHopper you import the OSM file like .pbf or .osm which then creates a graph which can be used for problems you described. Not exactly sure what problem you have though ;)
Solution 2:
The following solution works:
- Get the graphhopper project in your IDE.
- Get the raw Openstreetmap data (.pbf) via this very nice provider.
- Run this command in your (git) bash shell: ./graphhopper.sh -a import -i gelderland-latest.osm.pbf
Make a new (maven) project with this pom.xml file:
nl.xyz graphhopper 1.0 system ${project.basedir}/libs/graphhopper-web-1.0-SNAPSHOT.jar
Copy generated graphhopper-web-1.0-SNAPSHOT.jar from the graphhopper project to the libs folder of your new project so it will be included in your path.
Copy the generated graphhopper data to a folder within your small project.
Create this simple demo:
publicstaticvoidmain(String[] args) { privatestaticStringmapsFolder="graphhopper-data/yourlocation-latest.osm-gh"; GraphHoppergraphHopper=newGraphHopper().forMobile(); graphHopper.load(mapsFolder); System.out.println("Found graph " + graphHopper.getGraphHopperStorage().toString() + ", nodes:" + graphHopper.getGraphHopperStorage().getNodes()); QueryResultqueryResult= graphHopper.getLocationIndex().findClosest( 52.11111, 6.111111, EdgeFilter.ALL_EDGES); doubledistance= queryResult.getQueryDistance(); System.out.println( "Shortest distance is: " + distance); }
UPDATE: Using the JAR on Android may give a lot of compiler errors due to library version mismatchers. A better solution for getting this example run at Android, is using this dependency in your build.gradle:
implementation 'com.graphhopper:graphhopper-core:1.0-pre33'
Consequence is that you have to set the default routing profile. You can achieve via this change:
graphHopper = newGraphHopper().forMobile();
// Next line:
graphHopper.setProfiles( Collections.singletonList(newProfileConfig("my_car").setVehicle("car").setWeighting("fastest")));
graphHopper.load(routingDataFolder);
I hope you enjoy this wonderful 'graphhopper' software!
Post a Comment for "Reading Osm Map (or Other Format) Files To Determine Shortest Distance From Coordinate To Path"