I want to build the road network of any city and save the graph data into text file. For this purpose, I have followed this tutorial. In this tutorial they have used the Graphhoper. The output of Graphhoper is in binary format. Following files have been generated.
edges geometry, location_index, names,nodes,nodes_ch_fastest_car,properties,shortcuts_fastest_car
I do not know how to read it. Can somebody help me??
1 Like
What is your use case and why do you need to store this in a text file?
Later on, I will use this text file that contains Graph data for graph computations.
And why not use the binary data as it is from the GraphHopper API? And what do you mean with “graph computations”
Both binary and text formats are fine. My main problem is that I do not know how to read the data in the files in the xxx.osm-gh folder.
It will be helpful to know either the format of the files in the folder so I can read it using my own script or the specific sections of the API that manipulate these files.
I am trying to study demand and supply of vehicles between multiple nodes of a road network in a city.
See the documentation to use the Java API e.g. for routing or low level api or technical overview with minor description about the format
1 Like
Thank you. I have been trying to write code to read graph data using GraphHopper API. I got the following error. Tried finding setOSMFile method in GraphHopper class but cannot find it. Can you help please.
Many thanks again.
“The method setOSMFile(String) is undefined for the type GraphHopper”
Here is my Code
import java.util.Locale;
import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse;
import com.graphhopper.GraphHopper;
import com.graphhopper.routing.util.EncodingManager;
public class GhClass {
public static void main(String[] args) {
double latTo;
double latFrom;
double lonFrom;
double lonTo;
// Prints "Hello, World" in the terminal window.
System.out.println("Hello, World");
// create one GraphHopper instance
GraphHopper hopper = new GraphHopper().forServer();
hopper.setOSMFile("/Users/yasirarfat/Downloads/Malta/malta-latest.osm.pbf");
// where to store graphhopper files?
hopper.setGraphHopperLocation("/Users/yasirarfat/Downloads/Malta/");
hopper.setEncodingManager(new EncodingManager("car"));
hopper.importOrLoad();
// simple configuration of the request object, see the GraphHopperServlet classs for more possibilities.
GHRequest req = new GHRequest(latFrom, lonFrom, latTo, lonTo).
setWeighting("fastest").
setVehicle("car").
setLocale(Locale.US);
GHResponse rsp = hopper.route(req);
// first check for errors
if(rsp.hasErrors()) {
// handle them!
// rsp.getErrors()
return;
}
}
}
You should use the stable release 0.7 or use the GraphHopperOSM class and we’ll have to update the docs