Geographic Information Systems Asked by dyve on September 9, 2020
On my mac I use brew
to install PostGIS and all dependencies, including geos.
Since month or so, I have a failing test in my Python code.
A polygon that is entered in WGS84 (srid 4326), the converted to srid 28992 (RDS new) to get the surface in km2 used to give a surface of 76.33km2. Since updating packages, the surface is 225.14km2. In PostGIS, the calculation is just fine.
SELECT ST_Area(ST_Transform(ST_GeomFromEWKT('SRID=4326;POLYGON ((4 52, 4.1 52, 4.1 52.1, 4 52.1, 4 52))'), 28992))/1000000
# result: 76.32601969674697
In Django, this calculation is "outsourced" to the geos package, and gives 225.14km2.
AssertionError: False is not true : The field 'geom' on form 'form' in context 0 does not contain the error 'Geometry too big: area is 76.33km², maximum area is 25km².' (actual errors: ['Geometry too big: area is 225.14km², maximum area is 25km².'])
I have rebuilt my environments, reinstalled everything with brew, but I’m completely stumped as to how this can happen. in our CI process, the same tests passes (GitHub actions).
I’m looking for anything I can check to see if the projection used by geos on my mac is correct, or otherwise can help me find the reason for this change.
It seems Postgis and Geos package doesn't take coordinates in the same order. Best way to solve your problem is to swap coordinates.
SELECT ST_Area(ST_Transform(ST_GeomFromEWKT('SRID=4326;POLYGON ((52 4, 52 4.1, 52.1 4.1, 52.1 4, 52 4))'), 28992))/1000000 as area;
area
-------------------
225.1444151333475
SELECT ST_Area(ST_Transform(ST_GeomFromEWKT('SRID=4326;POLYGON ((4 52, 4.1 52, 4.1 52.1, 4 52.1, 4 52))'), 28992))/1000000 as area;
area
-------------------
76.32601969671276
Answered by Pierre B on September 9, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP