CartoDB/carto-react

[RFC] Add geospatial filter

Clebal opened this issue · 4 comments

Precedents

Currently, we already cover three filters:

  • IN: filters by certain categories
  • BETWEEN: filters by certain ranges.
  • TIME: special case of BETWEEN for time filtering.

Using a structure of these filters, we can build a filtering function that is used in workers and in getFilterValue for deck.gl DataFilterExtension.

Problem

We don't have any way to filter spatially but a certain geometry, for example: a isochrone.

Solution

Add new filter called: INTERSECTION.

Use as value: a geojson.

Returns: if a feature intersects with the given value using @turf/boolean-intersects.

I understand the input argument is a GeoJSON feature and, when the filter is applied, only the features in the source intersecting with that input feature are considered. It should work like any other filter by applying some condition to the source features, in this case a spatial intersection.

I'm ok with adding an extra spatial filter if it's useful... I'm just not 100% sure if we should stick here to the simple / most used use: 1 geojson polygon + intersection or maybe consider something wider in terms of api interface, like for example allowing 1 circle + distance (like we did in carto.js) for typical buffer analysis or even considering more operators beyond intersection.

We're currently just dealing with client-side calculations, so my guess is that this 'spatial filter' would be limited to the portion of the viewport the user sees right?, so if a portion of that new polygon is outside of the viewport, that wouldn't be considered... right?. If we enter server-side that (and also other aspects would need to change).

For now I will restrict the feature to intersecting the features with a single geojson feature. The circle/buffer case is interesting but the user can generate the buffer geometry using Turf.js or the SQL API. We are going to implement something similar in the feature selection tool.

We will work just with viewport features. It is just another filter we add, so all the existing filters apply (including the implicit viewport filter). If we have add support for "global" widgets in the future, it will be easy for geojson sources and not so easy for vector tiles as it will require queries to the backend.

Implementation has began in #226.