7

I have a bunch of polygons in my CartoDB map, and I want to create a new column called AREA in the table MY_TABLE that contains values from my area calculation query:

select ST_Area(the_geom::geography) as area_sqm FROM My_TABLE

this statement works, but the column area_sqm that contains the area value clears every time I clear the query, how can I have this permanently as part of my table so I can display the area value in the info table of my map?

1 Answer 1

8

In general:

ALTER TABLE  your_table ADD COLUMN area double precision;

UPDATE your_table SET area=ST_AREA(geom::geography);

(If your srid is 4326 and your data is stored as geometry)

Edit:

To round to 2 decimals use round() funcrion. If I remember right it works on numeric type and not double precision. So you need something like:

ROUND((ST_Area(geom::geography))::numeric,2)
1
  • Great! worked! Is there anyway to limit the precision to be just 2 digits after decimal points? Now its showing 9 digits....THANKS!
    – Vivian Ngo
    Jul 18, 2014 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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