[Feat] add selection and brushing for Geojson layer #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is to add selection and brushing for Geojson layer:
datacontainer
http://www.faqs.org/faqs/graphics/algorithms-faq/
Performance tests:
data: ~1 million polygons Utah house footprint
centroids/mean centers
Spatial index
Flatbush: 163ms
Summary
C++ code is normally 2x - 6x faster than the JS code with the same implementation. Boost::Geometry C++ has the fastest implementation. However, the centroid function in GEOS is not optimized and is slow (see explanation here Mean center and centroid)
1 million polygons Utah house footprint
3085 US counties
Note: Why the GEOS Centroid() function is slow?
The GEOS centroid() function performs an additional calculation for the fallback case when the polygon area is 0. This additional calculation is quite expensive, as it computes the total length of all the edges and returns the point at length/2 as the centroid.
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), even though mean center is more affected by the points that are far away from the center of the shape (see notes below).
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.