Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GeoArrow): handle tessellation error & improve mean centers #2803

Merged
merged 4 commits into from
Nov 28, 2023

Conversation

lixun910
Copy link
Collaborator

@lixun910 lixun910 commented Nov 23, 2023

In practice, there are many geoarrow files converted from GeoJson files using ogr2ogr containing invalid geometries. For example, polygon ring not closed; self-intersect polygon; multipolygon within geoarrow.polygon type arrow file etc. This will cause earcut() function to hang or return an empty triangle index.

Ideally, users should make sure the geoarrow file is correct, and use ogr2ogr to fix these invalid geometries e.g. with -makeValie or using Sqlite SELECT ST_MAKEVALID. However, to prevent hanging or crashing in loader.gl, we catch the possible error in earcut and let deckgl to remove the positions of these invalid polygons for filling polygon props. The option triangulate: boolean is also added to allow users to skip polygon tessellation on bulk geometries at loader.gl.

Another fix in this PR is to improve the performance of getMeanCentersFromGeometry(), which is too slow on a big dataset for now.

@lixun910 lixun910 requested a review from ibgreen November 23, 2023 05:02
Signed-off-by: Xun Li <lixun910@gmail.com>
const triangles: number[] = [];
// loop polygonIndices to get triangles
for (let i = 0; i < polygonIndices.length - 1; i++) {
const startIdx = polygonIndices[i];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this code be split into smaller helper functions - e.g. one that prepares the input to earcut?

modules/arrow/src/triangulate-on-worker.ts Outdated Show resolved Hide resolved
lixun910 and others added 2 commits November 27, 2023 21:47
Co-authored-by: Ib Green <ib@foursquare.com>
Signed-off-by: Xun Li <lixun910@gmail.com>
@lixun910 lixun910 merged commit 8a35c9a into master Nov 28, 2023
4 checks passed
@lixun910 lixun910 deleted the xli/fix-geoarrow-options branch November 28, 2023 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants