Add new Geometries to an osm file in Neo4J

▼魔方 西西 提交于 2021-02-11 11:46:13

问题


Hi im trying to add some restaurants to an importet .osm file. So I want to save the restaurants as new Point Geometries and connect them at the right point with the existing osm graph. Later I want to read out all resturants and find the nearest restaurant from any given point. So should I add the restaurants in a new layer? And is there an easy way to connect the restaurants with the graph at the right geogaphical point??

Thanks for answers

Greetings


回答1:


There are two options:

  • Edit the exiting OSM model (not trivial)
  • Add a new layer

Since the OSM editing is complex, I will answer that last. The easier option is to add a new layer. In this case you could use a SimplePointLayer, since you are only working with points. Just create one with the factory method SpatialDatabaseService.createSimplePointLayer(String name). This will allow you to store single nodes as Point objects with lat/lon attributes and any other attributes you want (restaurant name, etc.). Then query the index of the OSM layer (not the point layer) for nearby Geometries. You can then get fancy by connecting the Point nodes of your new layer to the Geometry nodes of the OSM layer with your own relationships, persisting the 'nearby'ness of the restaurant. Then your searches from OSM to find restaurants would need to traverse from the OSM graph along your new relationships.

The other option, editing the OSM model is not trivial today. The issue being that you need to find the part of the OSM model that you wish to edit and then apply changes to that. This is not done for you and requires knowledge of the OSM graph structure. For example, if you simply import an OSM file and then using the same layer object that the OSM was imported to, add a Point geometry to that layer, the geometry will be added as a free floating point, connected to the Rtree, but not to the rest of the OSM model.

If your point is already an existing node in the OSM graph, then the best option is to find that node and edit it. If it is already a Point geometry, then you will simply be changing attributes (of the Feature) or tags of the OSM node. If it is not a Point geometry, but simply a node of a way, then you would need to upgrade it to being a Point geometry and add it to the index. This 'upgrade' can be done by adding a new node, called a 'geom' node with the right attributes, and adding that to the RTree. See example code in the OSMImporter.java at https://github.com/neo4j/spatial/blob/f473a2e20f8f5392e211470e8fdc472bcf800e2d/src/main/java/org/neo4j/gis/spatial/osm/OSMImporter.java#L1097.

This get's us back to the question of finding the node in the OSM model in the first place. If you are starting with the location you want to add, then you could do a simple search for nearby Geometries, and traverse those to find the point that you want to edit. If you find no such existing point, you need to take a decision on how to add it. Inserting a new point into the OSM graph today is done using visual tools (like JOSM, iD or Potlatch, see http://wiki.openstreetmap.org/wiki/Editing). To do this in code would be more challenging. Perhaps you could work out if your point was on an existing way (close enough to the edge joining two existing nodes), and you could insert it into the chain. This sounds complex and risky, so I'd advise against it. It also requires a deeper knowledge of the current OSM model in Neo4j Spatial, which is somewhat complex.



来源:https://stackoverflow.com/questions/22345300/add-new-geometries-to-an-osm-file-in-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!