skip to Main Content

I am trying to use Apache AGE to store geographical information. I have a table called locations that contains the following columns:

id: The unique identifier of the location
name: The name of the location
latitude: The latitude of the location
longitude: The longitude of the location
I want to be able to query the table to find all locations within a certain radius of a given location. I have tried using the following Cypher query, but it is not working:

MATCH (location)
WHERE location.latitude > latitude - radius AND location.latitude < latitude + radius AND location.longitude > longitude - radius AND location.longitude < longitude + radius
RETURN location

The query is not returning any results. What am I doing wrong?

2

Answers


  1. I believe you forgot to properly reference the property, you should use the following query:

    MATCH (givenLocation {id: 1}), (location)
    WHERE location.latitude > givenLocation.latitude - radius 
      AND location.latitude < givenLocation.latitude + radius 
      AND location.longitude > givenLocation.longitude - radius 
      AND location.longitude < givenLocation.longitude + radius
    RETURN location
    

    In the corrected query, I’ve introduced a new node givenLocation with an id property set to 1 to represent some given location. You can replace 1 with the desired ID value or use other property to get the desired location.

    Please note that radius should be a specific value representing the distance from the given location within which you want to find other locations.

    But, I don’t think it works this way, I recommend looking into this answer, which provides a calculation for determining the desired distance. You can use the same calculation mentioned in that answer.

    Login or Signup to reply.
  2. if radius is less than or equal to 0, then the query will return nothing and if the radius is positive then the query should return all nodes because any quantity is always less than quantity + a positive number and greater than quantity – a positive number.

    to find all nodes in the radius of a location first you need to find or provide the required location and the find other nodes that comes within the radius of that node.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search