Geohashes in FaunaDB

I didn’t find anything about geohashes in the forum and I thought it would be nice to start a conversation.

I was reading this article about solving geospatial problems in FaunaDB. The author relies on the s2-geometry JavaScript package to encode geohashes from latitude and longitude positions.

He also created an NPM package to filter out results by geohashes and calculate distances but it has some limitations. For example, you need to perform (and pay for) multiple read ops for finer filtering.

Geospatial data and querying is such a common need that it would be awesome if FaunaDB provided bult-in capabilities:

  • Having a native GeoPoint type that could be converted to lat/long (eg: to put a pin on a map) or geohashes
  • Having native functions to filter by distance, calculate distance between 2 points, box queries, etc.

Postgres already has a solution for these problems which makes working with geospatial data a trivial problem. See how Hasura leverages that (they’re huge in the GraphQL world).

MongoDB also has built-in geospatial types and queries.

It’s definitely a valid feature request. I don’t think we have any plans for geohashes since it’s quite a specific use-case. In the immediate future there are probably bigger fish to fry.

I am going to add it in a ticket as a feature request to make sure your feedback doesn’t get lost and is picked up once there is room for such a feature :upside_down_face:

2 Likes

Thanks!

Yeah, I totally get that it’s not an immediate priority. It would be killer to have a serverless geospatial DB with those capabilities. I don’t think anything like that exists in the market.

Firebase has a Geopoint data class but it’s only for storing lat/long. You need to do everything else yourself (see this video). Also, Firebase is not distributed like Fauna.

Elastic has geo points too, but I think only box type of queries (get all the points inside a rectangle). I’m not sure it qualifies as serverless… and again it’s not distributed.

2 Likes

Any update on this? Would be very welcome for many people to have geospatial functionality built in Fauna.

Or can someone point me to a UDF where you can lookup documents (s2/h3 location) with a certain radius? :thinking:

Hi @Friso - no update on official supports, but a couple approaches that might help.

  1. The blog and npm package that @pier linked in the original post are probably the best way to get this going today.
  2. We’re working on a way to deploy common tasks like this via Fauna Schema Migrate using ESM imports - would this approach work for you? Note that this would still involve creating and calling UDFs.

Any current update on native geospatial support with fauna? It seems strange to not have this on the roadmap as fauna seems to be perfectly positioned as being a one stop shop for everyone’s db needs

1 Like

Hi @cntran et al,

Indeed we do want to the best, general purpose database available. Support for geohashes, and more broadly geospatial query patterns, is not yet on our immediate roadmap. However it is something we’re interested in supporting in the future. This could include the ability to define points, lines, and polygons and use these geometric elements in your queries.

For instance, you could define a polygon representing a specific geographic area, or zone, and query you collection for documents that have latitude and longitude coordinate that fall within that zone. Would such a capability suit your use case @cntran, @pier, or @friso?

Continuing the discussion from Geohashes in FaunaDB:

Hi Bryan, yes that sort of support would be great. A simple ability to be able to insert a specific GeoPoint data type and then just to be able to query records that are within a designated polygon or within a specific radius of a geopoint would be sufficient imo.

You did mention it’s not in the immediate roadmap but any idea on how far out something like this would be? I have been hesitant to switch a few mongodb related projects to fauna because of this. Thanks!

Hi @ctran it’s not an item we have planned for this year

I don’t know how your preferences are defined but it’s important for my use case as well. Many people need it. Please work on it :pray:

+1 for this! Anyone know how to adapt potatopotaro’s library to search within a polygon? (At the moment, it only supports searching within a radius).

Thanks for your interest here folks. I am going to close this request since GeoHashes are not on the current roadmap. We’ll continue to watch for interest in this feature.

I will add that it is possible to write geo queries with FQL if you really need them. See the example here: Index binding: Transform value n times (Uber H3 algorithm)

Native support would of course make things much simpler to use and efficient to execute, but I refer you back to Bryan for that one :slight_smile: