keplergl / kepler.gl

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
http://kepler.gl
MIT License
10.12k stars 1.71k forks source link

[Feat] add polygon filter based on mean centers for GeoJsonLayer #2476

Closed lixun910 closed 6 months ago

lixun910 commented 6 months ago

This PR is to add polygon filter based on mean centers for GeoJsonLayer. Mean centers are easy to compute (much faster than computing the mass centers or geometry centers), with a downside that the mean center is more affected by the points that are far away from the center of the shape (see notes below).

mean-centers

Notes:

Mean center vs centroid (mass center):

Mean center and centroid are two different ways to represent the center of a geometric shape. The mean center is the average of all the points in the shape. To compute it, you add up the x-coordinates of all the points and divide by the number of points, and then do the same for the y-coordinates.

The centroid (a.k.a. the center of mass, or center of gravity) of a polygon can be computed as the weighted sum of the centroids of a partition of the polygon into triangles. The centroid of a triangle is simply the average of its three vertices, i.e., it has coordinates (x1 + x2 + x3)/3 and (y1 + y2 + y3)/3. This suggests first triangulating the polygon, then forming a sum of the centroids of each triangle, weighted by the area of each triangle, the whole sum normalized by the total polygon area.

In general, the mean center and centroid will be different. The mean center is more affected by the points that are far away from the center of the shape, while the centroid is more affected by the points that have a large area.

image