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

sf issues associated with s2 #265

Open
edzer opened this issue Jan 14, 2025 · 6 comments
Open

sf issues associated with s2 #265

edzer opened this issue Jan 14, 2025 · 6 comments

Comments

@edzer
Copy link
Member

edzer commented Jan 14, 2025

There's a collection: r-spatial/sf#1771

@paleolimbot
Copy link
Collaborator

Thanks!

@sschooler
Copy link

Is there a fix that does not involve changing to calculating over a flat earth? I'm trying to obtain areas for large polygons (e.g. >1000 km) and changing to a flat earth changes the calculations.
Thanks!

@edzer
Copy link
Member Author

edzer commented Jan 23, 2025

@sschooler a fix to what?

@sschooler
Copy link

sschooler commented Jan 23, 2025

To the issue where s2 can't handle crossing vertices and throws the error "Loop X edge Y crosses loop A edge B", and st_make_valid doesn't work (e.g. Loop 0 is not valid: Edge 4441 crosses edge 4445, Loop 0 is not valid: Edge x has duplicate vertex with edge y).

What is recommended is using sf_use_s2(FALSE), but that changes geometry to planar and therefore leads to incorrect area calculations. I tried loading the file in with spherical geometry, turning spherical geometry off to do st_make_valid, then turning it back on to calculate area, but it still throws the error.

I think I might have a fix- it seems like if I use the s2 package with the s2_area function and set st_as_s2 manually using the rebuild = TRUE argument, it works. I found that solution in this thread st_difference broken with S2 on?.

@kadyb
Copy link

kadyb commented Jan 26, 2025

What is recommended is using sf_use_s2(FALSE), but that changes geometry to planar and therefore leads to incorrect area calculations.

But are the differences significant? Here is comparison using geographical coordinates and geodesic surface from lwgeom and the results are quite consistent.

@sschooler
Copy link

sschooler commented Jan 27, 2025

I saw that, but that example is on the scale of millions of square meters, and the areas I'm looking at are on the scale of billions of square meters. The distances become more pronounced the larger the area because the curvature of the earth matters more. E.g. in a calculation of area for one of my polygons, there is a difference of 30 million meters when computing with the lwgeom (sf_use_s2(FALSE)) versus computing with s2 (sf_use_s2(TRUE))

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

No branches or pull requests

4 participants