Hi Nolan,

I will answer inline below.

Hi folks. A few months ago, someone pointed me to Neo4J Spatial, though
> I haven't seriously investigated it until now. I have a few questions
> both about how to get started, as well as about what is and isn't possible.
>

I am in the process of writing a set of blogs that should help getting
started, but it will take a bit of time to get them out. For now there are
three ways:

   - Clone the git repo at https://github.com/neo4j/neo4j-spatial, use maven
   to run the test code, and then review the text code for examples of use.
   - Add the requirements to pom.xml of your own application'
   - Use the Ruby gem 'neo4j-spatial' at
   https://rubygems.org/gems/neo4j-spatial (just install with 'jruby -S gem
   install neo4j-spatial).

The last is the easiest to get started, but the Ruby API is still a bit
limited. You can get access to the complete Java API through JRuby, but
there is not yet that many utility functions for making it more Ruby-esque.

I'm currently working on a web-based (and hopefully embedded at some
> point) GPS navigation platform based on OSM data. The codebase is at a
> fairly advanced state, but I'm starting to run up against the limits of
> my data model. In particular, I'm encountering the following issues
> which I'm wondering if Neo4J Spatial can help with:
>

Neo4j Spatial is a good choice for OSM data, and can load OSM files and
expose them to GIS application for analysis. Are you planning to run this on
a mobile device? The question of whether or not, or how well, Neo4j runs on
embedded devices would need to be answered by others. I only use it (so far)
on PCs. I know there was an android prototype a few years back, but I do not
believe android (or other platforms) are officially supported. If you have a
backend server for neo4j (which it sounds like you do), then there is no
problem.

My database is currently H2 with no geospatial extensions whatsoever, so
> I'm finding it very hard to, say, list the ten nearest points to a given
> location, ten more beyond that, etc. as all I'm doing is increasing the
> bounds on an arbitrary box and taking whatever that returns. Is this
> something that Neo4J can do well? It seems like a graph database would
> be specialized at these sorts of queries, but I could be wrong.
>

The answer is yes and no ;-)

Certainly this kind of query is better for graph databases than others, but
at the end of the day indexing large amounts of spatial data in classical
RTree or related spatial indexes will have similar performance
characteristics. Our current main approach to doing distance queries is the
same as yours, use bounding boxes for the RTree and then sort by distance.
This is working well for most cases.

However, your pagination requirement is more tricky. If the starting point
for the distance calculation can be any point in the map, then I am not
aware of a solution that works well for this. If you have specific starting
points, for example nodes within the graph, then there may be solutions that
can use the graph for this. However, the usual graph algorithms tend to
define distance as cummulative distance along the path from one node to
another (through the connected graph), and not 'as the crow flies' which is
what you really want. I think I would need to know more about your needs
before recommending further.

I think I have a basic understanding of how graph databases work, but
> could someone relate that to how Neo4J Spatial would import OSM data?
> Are OSM nodes directly imported into Neo4J nodes, with ways modeling the
> relations between them? Or is there another scheme?
>

Certainly Neo4j can import OSM data into a decent graph. The OSM model in
Neo4j is somewhat similar to the graph model in the OSM xml files, but
expressed in a more graph-friendly way. The only public information on the
model so far is in the presentation I gave at FOSS4J. See these at
slideshare:
http://www.slideshare.net/craigtaverner/neo4j-spatial-backing-a-gis-with-a-true-graph-database
(slides
13, 14 and 15 show graphs of the OSM model in the database).

I think it would really help if I can import and play with live data.
> Where can I find the simplest possible code to import OSM data into a
> Neo4J Spatial database? And, once done, how can I best play with that
> data? Does the shell support spatial queries?
>

Well, the simplest possible code is the Ruby wrapper. I originally wrote
that specifically to import OSM files and export PNG and SHP versions on the
command-line. Look at the getting started instructions at
https://github.com/craigtaverner/neo4j-spatial.rb

Once installed you can copy the examples to somewhere in your path and run a
command like:

jruby osm_import.rb map2.osm

Alternatively, look at the contents of the example for the Ruby code that
does this:
https://github.com/craigtaverner/neo4j-spatial.rb/blob/master/examples/osm_import.rb

The key parts are:
require 'neo4j/spatial'
osm_importer = Neo4j::Spatial::OSMImporter.new
osm_importer.import 'my_test_file.osm'

If you want to do this in Java, take a look at the sample code at
https://github.com/neo4j/neo4j-spatial/blob/master/src/test/java/org/neo4j/gis/spatial/TestDynamicLayers.java

Hope this helps.

Regards, Craig
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to