Reputation: 33
I just started working with neo4j-spatial and have good understanding of basics of spatial geometries - polygons, points, lines.
So we are building web application that needs to index tourist information (only points) based on OSM administrative area like country, county and city. How do I store and index such data using neo4j-spatial? I am familiar with RDBMS so we were able to create solution using PostGIS link to solution
I created layer and index for each administrative area.
POST http://localhost:7474/db/data/index/node {"name":"india", "config": {"provider":"spatial", "wkt":"wkt"}}
Created Polygon node
POST http://localhost:7474/db/data/index/node { layer : "india", name:"Hyderabad", wkt : "POLYGON((11.0 11.0, 11.0 12.0, 12.0 12.0, 12.0 11.0, 11.0 11.0))" }
Also how do I determine administrative area based on given GPS Tourist point so as to create a node for it?
Upvotes: 0
Views: 395
Reputation: 2272
It seems to me that you probably want a combination approach to solving this problem. Your post doesn't provide much information, but your second REST call is not correctly formed.
Here is an answer to another question that shows you how to do what you want to do.
I don't show it in that answer, but the proper REST syntax for creating the polygon node is:
POST http://localhost:7474/db/data/node {"name":"Hyderabad", "wkt":"POLYGON((11.0 11.0, 11.0 12.0, 12.0 12.0, 12.0 11.0, 11.0 11.0))"}
or, if you wish to give the node one or more labels:
POST http://localhost:7474/db/data/transaction/commit {"statements":[{"statement":"CREATE (n:City {name : 'Hyderabad', wkt : 'POLYGON((11.0 11.0, 11.0 12.0, 12.0 12.0, 12.0 11.0, 11.0 11.0))') RETURN id(n)" }]}
I would tend to build standard Neo4j relationships between your cities, counties, provinces, and countries along the lines of (this example assumes that both nodes exist):
MATCH (n:City {name : 'Hyderabad'}), (m:Country {name :'India'}) CREATE (n)-[:IS_IN]->(m);
Then I would put all of the cities, counties, etc, into a single spatial index (the 'India' index, for example). If you then do a 'withinDistance' Cypher query using your tourist point with a distance of zero and a return limit of 1:
START n = node:India('withinDistance:[11.5,11.5,0.0]') RETURN n LIMIT 1
you will get node for the smallest containing entity. You can then follow the relationships to get to the parent entities.
One more thing. There are a variety of bulk load Java applications out there, as well as the LOAD CSV Cypher command. You should check them out if you haven't already.
Grace and peace,
Jim
Upvotes: 0
Reputation: 41706
Not sure if you're doing the right thing.
You would create a node that has a location (either as wkt or geo-coords) by posting to the node endpoint.
And then add that node to the spatial index.
see max blog post: http://maxdemarzi.com/2014/01/31/neo4j-spatial-part-1/
Unfortunately the cypher docs miss that point, but here is a test: https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/SpatialPluginFunctionalTest.java#L407
http://neo4j-contrib.github.io/spatial/#rest-api-add-a-node-to-the-spatial-index
Upvotes: 0