[GraphHopper] Truncated routes

Emden R. Gansner erg at research.att.com
Fri Jun 20 13:27:04 UTC 2014


On 6/20/14, 6:57 AM, Bruno Carle wrote:
> Hi Emden, I just tried your route locally with the texas pbf file and 
> I get same road as on graphhopper.com <http://graphhopper.com>
>
> Can you send the code you are using to call GH?
>
> Here is the code I used to test it:
>
> public void testMe() throws Exception{
>         test("../../../maps/texas-latest.osm.pbf",
>                 new GHPlace(32.71201241907505, -96.92441816057254),
>                 new GHPlace(32.67352373055029, -97.02611101550494));
>
>
>     }
>
>
>     public void test(String osmFile,GHPlace from,GHPlace to) throws 
> Exception{
>         GraphHopper graphHopper=new GraphHopper();
>         graphHopper.setInMemory(true)
> .setGraphHopperLocation("/tmp/ghosm2-test")
>                     .setOSMFile(osmFile)
> //                    .disableCHShortcuts()
>                     .setEncodingManager(new EncodingManager("car"));
>         graphHopper.importOrLoad();
>         GHRequest request=new GHRequest(from, to);
>           GHResponse response= graphHopper.route(request);
>
> ...
>
I have attached my code. It would be fine with me if I were told I was 
using the API incorrectly. From the code you sent,
it certainly appears I am working at a lower level than necessary. 
Thanks for helping.

     Emden

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/graphhopper/attachments/20140620/86006940/attachment.html>
-------------- next part --------------
package billboard;

import com.graphhopper.*;
import com.graphhopper.routing.util.*;
import com.graphhopper.util.PointList;
import com.graphhopper.util.DistanceCalcEarth;

/**
 *
 * @author erg
 */
public class Billboard {

    static String datafile = "/data/users/erg/texas-latest.osm.pbf";
    static String graphFolder = "/data/users/erg";
    static double lat0 = 32.71201241907505;
    static double lon0 = -96.92441816057254;
    static double lat1 = 32.67352373055029;
    static double lon1 = -97.02611101550494;

    /*
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        GraphHopper hopper = new GraphHopper().forServer();
		hopper.setInMemory(true);
		hopper.setOSMFile(datafile);
			// where to store graphhopper files?
		hopper.setGraphHopperLocation(graphFolder);
		hopper.setEncodingManager(new EncodingManager("car"));

		hopper.importOrLoad();

		GHRequest req = new GHRequest(lat0, lon0, lat1, lon1).setVehicle("car");
		GHResponse rsp = hopper.route(req);

			// first check for errors
		if(rsp.hasErrors()) {
			// handle them!
			// rsp.getErrors()
			System.out.println("errors");
			return;
		}

			// route was found? e.g. if disconnected areas (like island) 
			// no route can ever be found
		if(!rsp.isFound()) {
			// handle properly
			System.out.println("no route");
			return;
		}
		System.out.println("success");
			// points, distance in meters and time in millis of the full path
		PointList pts = rsp.getPoints();
		int cnt = pts.size();
		double distance = rsp.getDistance();
		long millis = rsp.getMillis();
		System.out.println(distance + " ms " + millis + " msec");
		System.out.format("%.03f ms (%d msec)\n", distance, millis);
		System.out.format("%d points\n", cnt);
		if (cnt > 1) {
    		DistanceCalcEarth dce = new DistanceCalcEarth();
			double sdist = dce.calcDist(lat0,lon0,pts.getLatitude(0),pts.getLongitude(0));
			double tdist = dce.calcDist(lat1,lon1,pts.getLatitude(cnt-1),pts.getLongitude(cnt-1));

			System.out.format("distance from source to start %.04fms\n", sdist);
			System.out.format("distance from end to target %.04fms\n", tdist);
		}
    }
}



More information about the GraphHopper mailing list