4

I am trying to convert a geometry column to a geography column and calculate the area using this query:

SELECT dccode,SUM(CAST(St_Area(geom::geography,true) AS NUMERIC)) as Area 
       FROM  schema.table   
       GROUP BY dccode

but I am getting a strange error:

...
NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
NOTICE:  Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY


ERROR:  lwgeom_area_spher(oid) returned area < 0.0
********** Error **********

ERROR: lwgeom_area_spher(oid) returned area < 0.0

I've run this query to verify that there is no invalid geometry:

select gid, dccode, st_isvalidreason(geom) from table.schema where st_isvalid(geom) = false;

but it doesn't return anything. How can I isolate the geometry that is < 0.0?

  • 1
    what srid is your geometry data in? the coercing to rang warning is probably the issue – Ian Turton Oct 25 '18 at 14:10
  • It is in srid 4326 – Matt Oct 25 '18 at 14:12
  • and is it lon/lat or lat/lon? – Ian Turton Oct 25 '18 at 14:12
  • 1
    but which way are the coordinates stored? it seems PostGIS believes some of your coordinates lay off planet and it is moving them to make a Geography polygon. – Ian Turton Oct 25 '18 at 14:25
  • 4
    The other error which will generate negative area is incorrect polygon ring rotation. Please Edit the question to provide an example of your coordinates. – Vince Oct 25 '18 at 14:55

Your Answer

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

Browse other questions tagged or ask your own question.