Neo4j-spatial Finding Nodes in OSM and finding shortest way to POI

1.1k views Asked by At

Hi im new to neo4j and trying to figure out how everything works atm

I importet a OSM file and now im working on a function which you can input a point in WGS84 format and a POI and then the function finds the shortest path to the POI.

So for finding the nearest Geometries to my WGS84 Point I use

Coordinate co = new Coordinate(12.9639158,56.070904);
List<SpatialDatabaseRecord> results2 = GeoPipeline
                .startNearestNeighborLatLonSearch(layer, co, 1)
                .toSpatialDatabaseRecordList();

but then my problems start because i don't really understand how the OSM file is built up

Is there a function so that i can get my POI Node by name? I get an index from the OSM file

SpatialDatabaseService spatialService = new SpatialDatabaseService(database);
Layer layer = spatialService.getLayer(osm);
LayerIndexReader spatialIndex = layer.getIndex();

Can I use it to search Nodes by properties?

And for finding the shortest Way between the points I found a dijkstra Algorithm

PathFinder<WeightedPath> finder = GraphAlgoFactory.dijkstra(
        Traversal.expanderForTypes( ExampleTypes.MY_TYPE, Direction.BOTH ), "cost" );
WeightedPath path = finder.findSinglePath( nodeA, nodeB );

The question now is what are my RelationshipTypes??? I think it shoud be NEXT but how do I include this in the code? Do I have to create an Enum with NEXT???

Can someone give me some feedback if im on the right way and give me some help please?

Okay finally found out how to find Nodes by id :D not too difficult but i searched for a long time :D

Thank you

1

There are 1 answers

3
Craig Taverner On

I can make a few comments:

  • We currently do not add names or tags to lucene indexes in the OSM importer, but it is a good idea.
  • What is done is adding all geometries (poi, streets, polygons, etc.) to the RTree index. This is the index you got back when you called layer.getIndex(). This index can be used to find things within regions, and can also perform a filter by properties of the geometry (name or tags) while searching the index. This is probably your best bet for finding something by name. See below for two options for this.
  • Route finding in the OSM model is not trivial, because the current model is designed for OSM completeness with all osm-nodes represented as real nodes in one huge connected network including all geometries (not just roads). The graph is complex, and a traverser would need to know how to traverse it to achieve route finding. It is not as simple as following NEXT relationships. See for example slides 13 and 15 at http://www.slideshare.net/craigtaverner/neo4j-spatial-backing-a-gis-with-a-true-graph-database. Each line segment does have a length, but what you really want is a simpler graph that has nodes only for points of intersection, and single relationships for the total drive distance between these points. This graph is not there, but could be added by the OSM importer.

Finally, two suggestions for finding POI by name. Either: - dynamic layers - or geopipes

For Dynamic layers you can use either CQL syntax or key,value pairs (for tags). For examples of each see lines 81 and 84 of https://github.com/neo4j/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/TestDynamicLayers.java. This approach allows the test for name to be done during the traversal in a callback from the RTree.

For GeoPipes, you define a stream, and each object returned by the RTree will be passed to the next filter. This should have the same performance as the dynamic layers, and also be a bit more intuitive to use. See for example the 'filter_by_osm_attribute' and 'filter_by_property' tests on lines 99 and 112 of https://github.com/neo4j/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesTest.java. These both search for streets by name.