Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-16-2018 07:04 AM
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 point
and 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.
08-31-2018 05:10 AM
Hi Craig,
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,
[/quote]?
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.
08-31-2018 08:56 AM
Hi Sinan,
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-b...
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 https://github.com/craigtaverner/spatial-3d. 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: https://github.com/craigtaverner/spatial-3d/blob/master/neo4j/src/test/java/org/amanzi/spatial/neo4j...
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.
Regards, Craig
10-31-2019 06:50 AM
@craig.taverner is there any more information available for neo4j spatial and upcoming releases? Thank you.
11-03-2019 07:22 AM
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. https://neo4j.com/online-summit/session/spatial-search-algorithms-neo4j
02-26-2020 08:15 AM
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
https://neo4j.com/docs/cypher-manual/current/functions/spatial/
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.
03-02-2020 01:12 PM
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.
03-02-2020 01:31 PM
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.
07-20-2020 06:54 AM
hi @mithun.das I think this is what @craig.taverner was refering to in regards to the spatial algo's: https://github.com/neo4j-contrib/spatial-algorithms#:~:text=%20Spatial%20Algorithms%20%201%20Coordin...
I too am looking for more spatial support and will take a look and some of the material that has been posted
08-10-2020 07:09 AM
Thank you for the link.
09-14-2020 07:54 AM
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.
spatial
, osm
and spatial-algorithms
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)osm
library.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:
All the sessions of the conference are now available online