0

Using the Neo4j Spatial core java api, I have been able to put together code which allows me to lookup nodes within a specific distance from a given point however, I would like to be able to include nodes based on their catchment radius.

For example, if I am located at any given point which pizza companies in my local area or further afield could deliver to me (given their own delivery radius)

Any ideas on how this could be achieved with Neo4j Spatial?

FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86

1 Answers1

2

Instead of modelling your Pizza companies as simply points on a map could you model their delivery radius as a related geometry shape? This would give you greater control over the delivery shape as well (not delivering to an island for example).

If you model the deliver area as a WKT Polygon, you can then perform a search in the form:

START loc = node:idx_bounding_location(withinDistance:[<lat>,<lon>,0.0])
MATCH (pz:Pizza:Company)-[:DELIVERY_AREA]->loc
RETURN pz

In this query the lat and lon values are the location of the person requiring pizza delivery.

JohnMark13
  • 3,709
  • 1
  • 15
  • 26
  • Awesome answer cheers! If it were to have a radius, do you know how best to model that? Can you make a WKT Polygon a circle? – jamesclarke Sep 24 '14 at 18:19
  • TBH I don't know how you would build the shape, however the Neo4J Spatial documentation says `Likewise the subclasses of Geometry: Point, LineString, Polygon and others are all from JTS` which suggests all geometry types are supported. The one you would want would be `CIRCULARSTRING(x1 y1, x2 y2, x3 y3, x4 y4, x1 y1)`, I'd think that there is some maths somewhere which will allow you to generate the co-ordinates from a centre point and radius. – JohnMark13 Sep 24 '14 at 18:39