skip to Main Content

Does Amazon Web Services have a solution to store objects in a database with a latitude and longitude and then to do a geo query on them to give you all objects in a specific radius and sort them by what is closest to the center of that radius?

There are geohashing solutions for DynamoDB but those don’t allow you to sort results by what is closest to the target location.

3

Answers


  1. I think the term you’re looking for is spatial search or spatial indexing. DynamoDB does not have such a feature, but the SQL-based products in the RDS area support spatial indices, including geofencing just like their “normal” counterparts (MySQL, Postrgres etc.).

    If you are looking for a low-touch solution, you can look into the different Aurora options, including Aurora Serverless. For example, Aurora MySQL has support for different spatial types/indices.

    Login or Signup to reply.
  2. There are many offerings from AWS which can offer geo-spatial queries, depending on your specific use-case will determine which option is best for you.

    NoSQL

    Relational

    Login or Signup to reply.
  3. Use RDS PostgreSQL with PostGIS, its spatial extension. PostGIS gives you geospatial data types, function, and indexes. With that you can ask all sorts of geospatial questions in a performant way using plain old SQL 🙂

    You can use ST_DWithin to get what you want, for example:

    SELECT DISTINCT ON (s.gid) s.gid, s.school_name, s.geom, h.hospital_name
      FROM schools s
        LEFT JOIN hospitals h ON ST_DWithin(s.geom, h.geom, 3000)
      ORDER BY s.gid, ST_Distance(s.geom, h.geom);
    

    This query will find the nearest hospital to each school that is within 3000 units of the school. ST_DWithin leverages spatial indexes to perform the search faster so make sure you index your geom. If the units of the spatial reference is meters then units would be meters.

    Take a look at this intro to PostGIS workshop to get an overview of PostGIS and its capabilities. Visit Managing spatial data with the PostGIS extension to see how to work with PostGIS on AWS.

    Hope this helps.

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