Geo search, find all areas specified by polygon points that my location is in

hi @wchandler,

As @abhinav mentioned, FTS doesn’t have a built-in solution for this.

FTS doesn’t support the geo shape indexing capability now. So even if you have a series of boundary points within a field in the source document - FTS doesn’t have a way to index/digest it now.

Still, I think your point-radius query is very close, but with a few tweaks which might also involve the additional field introduction into your original source document.

One potential idea popping to mind is that,

  1. First you need to add/introduce an additional geo field into your source document which is the centroid/central point of the given series of boundary points. Let’s call this new central point of the region as newGeo.
    ref - Centroid - Wikipedia or this becomes an approximation with irregular polygons. Perhaps find the center point of the bounding rectangle for the given region/polygon boundary. You need to investigate more there on the approach which eventually gives you better precision for the results.
  2. You need to index this new newGeo field as a geo point type while defining the FTS index.
  3. Then you need to index the original region boundary field (series of geo points as a polygon) of the document.
  4. Note: Enable the store option for this boundary field so that you need to retrieve this boundary field contents later along with the search results. (You may need to change the type of this field in the source document to fit the field types we support here).

Now we are all set with the indexing part.

  1. Your mobile device geolocation is sent as a point-radius query to the FTS backend against the newGeo point.
    The radius value has to be in a reasonable limit/range to fetch the surrounding source documents.
    Note: You need to request the original stored boundary field contents along with the search results. You may use the Fields in the search request for this. ref - https://docs.couchbase.com/server/current/fts/fts-response-object-schema.html
  2. Once you have a couple of overlapping documents in the search result, the client app needs to figure out whether your mobile device location really lies within the boundary of the returned documents. (This value is already there in the Fields returned on every Hit of the search result)
    You may use any standard point inclusion algorithms for polygons - http://geomalgorithms.com/a03-_inclusion.html
    (This part is a light and fast logic as you would be checking this against a handful of documents)

Cheers,
Sreekanth

1 Like