[GraphHopper] ExtendedStorage for OSM ids

Diego Guidi diegoguidi at gmail.com
Tue Apr 22 06:50:52 UTC 2014


thanks for sharing this

Diego Guidi


On Mon, Apr 21, 2014 at 10:59 PM, Bruno Carle <brunocarle at yahoo.com> wrote:
> Thanks for the snippet Diego. I did not know about this possibility. I
> already got the blacklist running with the extended storage, if you are
> interested it is on https://github.com/brunesto/graphhopper . The code has
> some additional changes in the base classes, mainly to support multiple
> extended storages.
>
> Bruno
>
>
>
> ________________________________
> From: Diego Guidi <diegoguidi at gmail.com>
> To: Bruno Carle <brunocarle at yahoo.com>; GraphHopper Java routing engine
> <graphhopper at openstreetmap.org>
> Sent: Monday, April 21, 2014 9:29 PM
>
> Subject: Re: [GraphHopper] ExtendedStorage for OSM ids
>
> On Fri, Mar 28, 2014 at 2:43 PM, Bruno Carle <brunocarle at yahoo.com> wrote:
>> At the moment I would like to be able to blacklist both nodes and edges,
>> so
>> I will stick with the ExtendedStorage.
>
> I've made a slightly different thing.
> I've created a "support map" that stores osmid for each node, using
> this code (in the extended OsmReader that is similar that the one you
> posted):
>
>   @Override
>   protected boolean addNode(OSMNode node) {
>     boolean added = super.addNode(node);
>     if (!added) {
>       return false;
>     }
>
>     long osmid = node.getId();
>     int graphid = this.getInternalNodeIdOfOsmNode(osmid);
>     map.put(graphid, osmid);
>     return true;
>   }
>
>
> The I've stored this map as an external "support file" inside graph folder:
>
>   private File createSupportFile() throws IOException {
>     String dir = this.getGraphStorage().getDirectory().getLocation();
>     File file = new File(dir + "/support");
>     String path = file.getAbsolutePath();
>     if (file.exists()) {
>       file.delete();
>     }
>     if (!file.createNewFile()) {
>       throw new IllegalStateException("file not created: " + path);
>     }
>
>     String newline = System.getProperty("line.separator");
>     Writer fw = new FileWriter(file);
>     BufferedWriter bw = new BufferedWriter(fw);
>
>     try {
>
>       for (Integer key : map.keySet()) {
>         Long val = map.get(key);
>         bw.write(String.format("%d|%d%s", key, val, newline));
>       }
>     } finally {
>       bw.close();
>     }
>     return file;
>   }
>
> Pretty unelegant (ExtendedStorage is the right way to do things, I
> suppose) but simple and well working for small graphs (my osm source
> file is 22mb).
>
> Hope this can help someone.
>
>
> Diego Guidi
>
>
>



More information about the GraphHopper mailing list