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

Add spherical_area() function #2019

Merged
merged 1 commit into from
Jul 30, 2023
Merged

Conversation

joto
Copy link
Collaborator

@joto joto commented Jul 29, 2023

To calculate the "real" area of a (multi)polygon. This is still an approximation. Results are similar to what ST_Area(geography, false) calculates in PostGIS. Accessible from Lua.

{ column = 'area', type = 'real' },
-- In this column we'll put the true area calculated on the spheroid

Choose a reason for hiding this comment

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

on the spheroid

Shouldn't this read 'on the sphere'?

By the way, I recommend you to thoroughly test this, also with data near the date line. I ran into serious issues with crashes with Planet wide (generalized) data and PostGIS ST_Area and spherical calculations when I first attempted implementing both spherical and spheroidal area calculations, and had to switch to spheroidal (ST_Area(geography,true)) to overcome these issues. ST_Area for some reason failed with spherical calculations.

I have never been able to track down the real cause, and simply worked around it with the (slower) spheroidal calculations, but if this solution for osm2pgsql relies on some of the same libraries as PostGIS, it may encounter similar issues if it hasn't been fixed in the mean time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't use the same code PostGIS does but the code from boost::geometry which might or might not be better, different or whatever. I rely on that code like I do for everything we get from a library, so yes, there are some tests, but other than that I just expect this to work.

The description of the various area() functions are a bit fuzzy about whether they use a sphere or a spheroid and there are different versions of those functions etc. So I am going with spheroid because it sounds cooler and because technically a sphere is a special case of a spheroid so I am on the safe side. :-)

To calculate the "real" area of a (multi)polygon. This is still an
approximation. Results are similar to what ST_Area(geography, false)
calculates in PostGIS. Accessible from Lua.
@lonvia lonvia merged commit 57875ca into osm2pgsql-dev:master Jul 30, 2023
27 checks passed
@joto joto deleted the spherical-area branch July 30, 2023 18:12
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.

3 participants