0

My App uses openstreetmap files to show waypoint (or coordinates) on a map.

Based on an Openstreet map file: how can I determine the shortest distance from a GPS coordinate to the (walking) path.

Can I read an OSM (map) or .osm file ... to access the paths?

tm1701
  • 7,307
  • 17
  • 79
  • 168

2 Answers2

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 ;)

Karussell
  • 17,085
  • 16
  • 97
  • 197
  • OSM file is not the map file, ok, thanx. # 1 - In Graphhopper many walking paths are not included in calculating the route. # 2 - My problem is: determine the distance of any GPS coordinate to a point on a path that is most nearby. I would like to determine that shortest distance to any (nearby) path . So, is there a way to read an OSM file ... so I can determine that shortest distance? – tm1701 Nov 02 '14 at 13:07
  • 1
    you can calculate the shortest distance via locationIndex.findClosest and then use queryResult.getQueryDistance to get the distance to a nearby path – Karussell Nov 03 '14 at 09:40
  • this last comment I missed. Thank you for posting. Can you elaborate on your comment? Do I need first to create the Graphhopper data ... and then I can get the shortest distance of any point to the closest path? – tm1701 Jun 29 '15 at 20:31
  • Yes, see the routing docs. Although you'll have to use some custom code instead of GraphHopper.route to make it efficient it should work with GraphHopper.route too – Karussell Jun 30 '15 at 07:18
  • Thank you! So, first generating the routing data. Then programming Java inside my Android App to access the routing data. Can you refer to the API docs? Is it fairly easy to do for a Java App developer? Or is there first a steep learning curve? Footage of the jar? Examples? – tm1701 Jul 01 '15 at 17:26
0

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:

    public static void main(String[] args) {
        private static String mapsFolder = "graphhopper-data/yourlocation-latest.osm-gh";
        GraphHopper graphHopper = new GraphHopper().forMobile();
        graphHopper.load(mapsFolder);
        System.out.println("Found graph " + graphHopper.getGraphHopperStorage().toString() + ", nodes:" + graphHopper.getGraphHopperStorage().getNodes());
        QueryResult queryResult = graphHopper.getLocationIndex().findClosest( 52.11111, 6.111111, EdgeFilter.ALL_EDGES);
        double distance = 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 = new GraphHopper().forMobile();
// Next line: 
graphHopper.setProfiles( Collections.singletonList(new ProfileConfig("my_car").setVehicle("car").setWeighting("fastest")));
graphHopper.load(routingDataFolder);

I hope you enjoy this wonderful 'graphhopper' software!

tm1701
  • 7,307
  • 17
  • 79
  • 168