I do not see people asking this exact question, and yet I see a lot of questions that this would answer. Specifically, people with point data and location-based search use cases trying to use the spatial plugin, or trying to use a combination of the plugin and the built-in features. So I wanted to try to clarify the differences between the two:
Neo4j 3.0 introduced the
distance functions to Cypher, and Neo4j 3.4 enhanced this dramatically with the ability to store points as properties, and do index-backed searches using both range (and bounding box) as well as distance searches. If your use case involves point data (latitude and longitude, or just x and y), and you want to find data close to other points, or within specific regions, then it is best to use Neo4j 3.4. The support is built into the database through the entire stack. From the storage and indexing, through Cypher and even into the drivers and clients (browser and cypher-shell).
If you instead have complex GIS use cases, need to store complex geometries like Polygons and multi-polygons and need to import and perform GIS queries against the OpenStreetMap model, then the spatial plugin is the better choice. It has a much richer spatial feature set than Neo4j itself. However, keep in mind that this is a community maintained project, written back when Neo4j was primarily an embedded database. It was not designed for the high volume and high concurrency production environments that Neo4j is used for today. By all means, give it a try for your complex GIS case, but make sure you test if it is up to the challenge of your production use cases before relying on it too heavily.
So the short answer is, try Neo4j itself first. Only use the spatial plugin if you really need its richer capabilities.
thank you very much for that explanation. It indeed helps. I have a very small example importing the cantons of Switzerland into a neo4j database with nothing inside. This already makes some of the Neo4J browser functionality and the of Bloom unusable. It seems to me that my polygons are stored as cleartext into the nodes and that this makes the Neo4j browser crash.
Could you please explain a bit more what you mean with:
[quote="craig.taverner, post:1, topic:159"]
, or within specific regions,
If I have the Swiss cantons and want to identify power plants inside these cantons along with other smaller areas (e.g. municipalities, owners of electricity distribution grids) and other points (e.g. CO2 sources, consumers, clusters of buildings) for clustering, aggregation or other analyses. How would you implement such geospatial information in Neo4j? My goal is to build up a knowledge graph which later on should be the input of different machine learning algorithms.
Thanks in advance for your input.
Regarding your question about what I meant about within specific regions, in Neo4j 3.4 there are only two relevant search queries: distance and bounding box (MBR). Search within polygon is not (yet) supported, so you would need to calculate the bounding box of the rectangle and then call the range search with that, followed by filtering out anything outside your rectangle. For more information on spatial range queries, see the docs at https://neo4j.com/docs/developer-manual/current/cypher/schema/index/#schema-index-spatial-bounding-box-searches-single-property-index
I have also done some simple work on procedures for creating and filtering using polygons in a separate community library. This is very alpha work, but might make your life easier if you want to search for points in polygons. See GitHub - craigtaverner/spatial-3d: Utilities and Algorithms for 3D Objects. The goal of that library is to provide point in 3D polygon mesh searches, but as preparatory work I developed point in 2D polygon already. See the example on this line: spatial-3d/UserDefinedFunctionsTest.java at master · craigtaverner/spatial-3d · GitHub
Since that is alpha code we have not made a release yet and you would need to build it yourself.
Back to your original comment about importing cantons. Did you import them as plain text into Neo4j, or did you use the 'Neo4j Spatial' plugin to import them? I suspect the browser is struggling with returning large data and storing it in local JSON memory. I'm not sure if it will treat binary more carefully than strings, and if so you could try storing as WKB instead of WKT.
@craig.taverner is there any more information available for neo4j spatial and upcoming releases? Thank you.
Neither the built-in spatial features of Neo4j itself, nor the external library "Neo4j Spatial" have a proper roadmap with clear plans. Both have their own loose schedule. For Neo4j itself, a lot depends on customer demand and alignment with product strategy. Currently that does not include any immediate plans to improve spatial support. And the library is a community supported project, which gets occasional improvements, but not in a very predictable way.
While I cannot predict the future, I can point you to the latest work we've done in this area, which is an improvement on the point-in-polygon work I described in my answer above. Take a look at the NODES2019 presentation I gave last month, which describes a new library of spatial functions you can use with Neo4j to provide some more complex capabilities around polygons. NODES 2019: Talk - Neo4j Graph Data Platform
I read your blog and saw the video in youtube (also liked ) as well where you give a fantastic demonstration of the spatial functions, thank you for that.
I use neo4j 4.0 and i use the following documentation
It is fine for me right now as I only do box and distance search... but soon i will need to store polygons/area and search within it.... I think I need to revisit your video again, its not something that can be grapsed in one go. Once again thank you for enlightening us.
Thanks Mithun, I'm glad you found it useful. I can mention that we only recently ported the 'spatial-algorithms' library to Neo4j 4.0, and I've also worked on porting the OSM library to Neo4j 4.0 (but not released it yet). Together they can be used for some polygon search work if you use OpenStreetMap data, or can be the basis of building your own polygon support if you are into coding Java.
The remaining alternative for polygons is the older 'Neo4j Spatial' library, but it has not been ported to Neo4j 4.0 yet, and I suspect that will take a bit of time.
I am nodejs developer, so I think best case for me is to go through 'spatial-algorithms' library.... can you point me to the doc... is it same doc that i am using/refered to my last post?
Also I saw in your video... you talked about some very complex scenarios... must admit that have not understood fully, but need to listen again and again and use them in practical codes... but I think its my bible right now to work with spatial and neo4j 4.0.
hi @mithun.das I think this is what @craig.taverner was refering to in regards to the spatial algo's: GitHub - neo4j-contrib/spatial-algorithms: Spatial algorithms for both cartesian and geographic data
I too am looking for more spatial support and will take a look and some of the material that has been posted
I noticed that the original post has become a little dated. Based on an answer I gave in the neo4j-users slack channel, I thought I'd add some more current information.
- Neo4j 4.1 still has the same spatial support as Neo4j 3.4 (ie. only one new property type 'Point', and arrays of points). The Coordinate is just an in-memory type representing the Points coordinate without the units or coordinate reference system. Read more about these concepts in the Neo4j Cypher documentation at Spatial values - Cypher Manual
- There are three spatial libraries written and published under the neo4j-contrib organisation:
spatial is an old library that wraps the well known JTS and Geotools libraries, and so gives a lot of power (like a full GIS), but was originally designed for embedded database use, so might not be that ideal for a high concurrency production environment. It has NOT been ported to Neo4j 4.x yet (that is work in progress).
osm is an extract of the OSM support from the old
spatial library, re-written to use a much faster offline bulk importing framework, and including a number of useful Cypher procedures for modeling OSM data for geoprocessing and routing (as demonstrated in my GraphConnect and NODES2019 videos). It has been ported to Neo4j 4.0 (might even work for 4.1, but not tested)
spatial-algorithms is a ground-up implementation of a few useful spatial algorithms (as demonstrated in my NODES2019 talk). It is a prototype and work-in-progress, written mostly by an intern 'Stef van der Linde'. If you are interested in writing spatial algorithms, this is a great starting point. It has been ported to Neo4j 4.0. It can make use of data imported using the
- There is no routing support built into any of the above, and you would need to use another implementation of something like
A* for that. However, as mentioned in my GraphConnect talk, the
osm library and the talk show how to configure a graph like OSM for use with an A* algorithm. We used the one published by APOC, but you could just as well use routing algorithms from GDS also.
Videos covering this: