I guess I make some silly mistake somewhere, if anybody could help me, I'll be grateful.
I need road distances and I'm trying to use osm2po to do this.
After downloading the OSM files and converting them to gph format, using the osm2po program, I start at the very beginning with the following very simple java program:
import java.io.File;import java.util.Arrays;
import de.cm.osm2po.logging.Log;import de.cm.osm2po.logging.Log2poConsoleWriter;import de.cm.osm2po.model.LatLon;import de.cm.osm2po.routing.Graph;import de.cm.osm2po.routing.MultiTargetRouter;import de.cm.osm2po.routing.PoiRouter;
public class TestOSM {
public static void main(String[] args) { File graphFile = new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph"); Graph graph = new Graph(graphFile); // Somewhere in Hamburg int sourceId = graph.findClosestVertexId(53.5f, 10.0f); int targetId = graph.findClosestVertexId(53.4f, 10.1f); graph.close();}}
I get it to compile using:
javac -d . -classpath osm2po-core-5.0.0-signed.jar TestOSM.java
It compiles and creates the TestOSM.class file.
I then use the following to run the program:
java TestOSM
It gives a runtime error (I'll show the error message below)
I suspected the program does not read the hh_2po.gph file, so I used another java program to first use "normal" java file read to confirm successful file reading operation.
My java program to try to confirm successful file reading looks like this:
import java.io.File;import java.util.Arrays;
import java.io.Console;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.io.FileInputStream;import java.io.InputStream;
import de.cm.osm2po.logging.Log;import de.cm.osm2po.logging.Log2poConsoleWriter;import de.cm.osm2po.model.LatLon;import de.cm.osm2po.routing.Graph;import de.cm.osm2po.routing.MultiTargetRouter;import de.cm.osm2po.routing.PoiRouter;
public class TestOSM {
public static void main(String[] args) { // Testing take1 File graphFile = new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph"); //File graphFile = new File(args[0]); // tried this, and then supply file name when calling the program - does not work //File graphFile = new File("hh_2po.gph"); // tried this after copying hh_2po.gph in the same directory - does not work Graph graph = new Graph(graphFile); // Somewhere in Hamburg int sourceId = graph.findClosestVertexId(53.5f, 10.0f); int targetId = graph.findClosestVertexId(53.4f, 10.1f); graph.close();/* // Testing take2 // Part 1, to confirm that the program can read the hh_2po.gph file: try{ BufferedReader reader = new BufferedReader(new FileReader(new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph")));
String thisLine = thisLine = reader.readLine(); System.out.println(thisLine); System.out.println("file read good"); reader.close(); }catch(IOException ioe) { System.out.println("could not read file"); } System.out.println("enter to continue"); Console console = System.console(); String line = console.readLine(); // end of test
// Part 2, this time try to convert file to InputStream before converting to a Graph: try{ File initialFile = new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph"); InputStream targetStream = new FileInputStream(initialFile); Graph graph = new Graph(targetStream); }catch(IOException ioe) { System.out.println("Heuston we have a problem"); }*/
}}
When I run it, again using java TestOSM, I get the following runtime error:
I use Windows10 and java jdk1.8.0_60
Thanks very much for the help.
Pieter
أكثر...
I need road distances and I'm trying to use osm2po to do this.
After downloading the OSM files and converting them to gph format, using the osm2po program, I start at the very beginning with the following very simple java program:
import java.io.File;import java.util.Arrays;
import de.cm.osm2po.logging.Log;import de.cm.osm2po.logging.Log2poConsoleWriter;import de.cm.osm2po.model.LatLon;import de.cm.osm2po.routing.Graph;import de.cm.osm2po.routing.MultiTargetRouter;import de.cm.osm2po.routing.PoiRouter;
public class TestOSM {
public static void main(String[] args) { File graphFile = new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph"); Graph graph = new Graph(graphFile); // Somewhere in Hamburg int sourceId = graph.findClosestVertexId(53.5f, 10.0f); int targetId = graph.findClosestVertexId(53.4f, 10.1f); graph.close();}}
I get it to compile using:
javac -d . -classpath osm2po-core-5.0.0-signed.jar TestOSM.java
It compiles and creates the TestOSM.class file.
I then use the following to run the program:
java TestOSM
It gives a runtime error (I'll show the error message below)
I suspected the program does not read the hh_2po.gph file, so I used another java program to first use "normal" java file read to confirm successful file reading operation.
My java program to try to confirm successful file reading looks like this:
import java.io.File;import java.util.Arrays;
import java.io.Console;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.io.FileInputStream;import java.io.InputStream;
import de.cm.osm2po.logging.Log;import de.cm.osm2po.logging.Log2poConsoleWriter;import de.cm.osm2po.model.LatLon;import de.cm.osm2po.routing.Graph;import de.cm.osm2po.routing.MultiTargetRouter;import de.cm.osm2po.routing.PoiRouter;
public class TestOSM {
public static void main(String[] args) { // Testing take1 File graphFile = new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph"); //File graphFile = new File(args[0]); // tried this, and then supply file name when calling the program - does not work //File graphFile = new File("hh_2po.gph"); // tried this after copying hh_2po.gph in the same directory - does not work Graph graph = new Graph(graphFile); // Somewhere in Hamburg int sourceId = graph.findClosestVertexId(53.5f, 10.0f); int targetId = graph.findClosestVertexId(53.4f, 10.1f); graph.close();/* // Testing take2 // Part 1, to confirm that the program can read the hh_2po.gph file: try{ BufferedReader reader = new BufferedReader(new FileReader(new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph")));
String thisLine = thisLine = reader.readLine(); System.out.println(thisLine); System.out.println("file read good"); reader.close(); }catch(IOException ioe) { System.out.println("could not read file"); } System.out.println("enter to continue"); Console console = System.console(); String line = console.readLine(); // end of test
// Part 2, this time try to convert file to InputStream before converting to a Graph: try{ File initialFile = new File("C:/osm2po/osm2po-5.0.0/hh/hh_2po.gph"); InputStream targetStream = new FileInputStream(initialFile); Graph graph = new Graph(targetStream); }catch(IOException ioe) { System.out.println("Heuston we have a problem"); }*/
}}
When I run it, again using java TestOSM, I get the following runtime error:

I use Windows10 and java jdk1.8.0_60
Thanks very much for the help.
Pieter
أكثر...