1

I have a PostgreSQL db with a table with geometry multipolygons stored in srid 4326 (lat/lngs). I need to calculate the area of the oriented envelope around each polygon, and I am using st_orientedenvelope to do so. I want area in reasonable units, so I also need to use st_transform before calling st_area

Why do I get different results depending on the order of transforming and generating the envelope?

select
    st_area(st_orientedenvelope(st_transform(geom, 26910))) a,
    st_area(st_transform(st_orientedenvelope(geom), 26910)) reverse
from
    mytable

Whether the envelope is generated and then transformed or the transformation happens and then the envelope is generated shouldn't (to my mind) matter. Calculating a / reverse should always result in a number very close to 1. However, in my data set of ~2000 records, more than 10% of the area calculations (a compared to reverse) differ from each other by more than 5% - some by as much as 25%.

enter image description here

In the image, the black line is envelope generated after transform (a), and the orange line is transform after creating envelope (reverse)

In the above example, I use 26910, which is SRID for UTM 10N because the data is in Seattle area. However, I get very similar results using other SRIDs, including 2926 (Washington State Plane) and 2163 (US National Atlas Equal Area).

  • This may be trivially linked to the function finding more than one oriented envelope, and returning one at random. – ThingumaBob Feb 5 at 19:15
4

Envelopes are often very inaccurate, depending on the coordinate reference system (CRS), or converting an envelope between two CRS. An envelope is 2 points, so projecting or transforming them to a different CRS means you can miss distortions occurring at the other two corners, on the edges, etc. An envelope in one CRS, if it was densified first, many times, is not an envelope in another CRS.

This is likely what you're seeing. Calculating areas should usually be done in an equal area projection. If the area is small, a conformal projection like UTM) should give reasonable results if the geometry is inside the CRS's area of use. PostGIS says that it's using GeographicLib for calculating areas on the ellipsoid, so you might try a third option:

st_area(st_orientedenvelope(geom))

Is the envelope is small, defining it on the ellipsoid (spheroid) surface may be fine, but for a larger area, it might be important to look at converting to a 2D Cartesian surface first.

  • Thanks, @mkennedy. That explanation does make some sense...but I guess I'm still not sure I understand why the two envelopes are so different. These polygons are relatively small (say, 1500m^2), and I'm not sure why there would be so much distortion. Intuitively, I could buy it if the orange rectangle was more similar to the black (say, skewed just a little or rotated just a couple of degrees) instead of being entirely different. Why is the envelope created from lat/lngs so different from the other? – susie derkins Feb 7 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.