Polygon in Postgres/PostGIS database. It has the spatial reference 4269 which is in degrees.
I know there is a ST_Area() to calculate it. this is my query to select the areas in the SRID units.
select st_area(geom) from counties;
I want to calculate the area in Square Miles and insert a column named Area with the correct Square Mileage for each county
*I am a new to SQL and Postgres
1 Answer 1
ST_Area will use the units in your coordinate system, which as you say are degrees. So you have two options:
- transform your geometries to a coordinate system that uses feet or meters
- cast your geometries as geographies. ST_Area will then perform the calculation in meters.
You then need to convert from square feet or square meters to square miles.
Your query would look something like this
ALTER TABLE counties ADD COLUMN area real;
UPDATE counties SET area = ST_Area(geom::geography) / 1609.34^2
-
awesome I will give this a tryziggy– ziggy2016年05月14日 02:51:49 +00:00Commented May 14, 2016 at 2:51
-
Saved a day. Thanks heaps @amball!Petro Semeniuk– Petro Semeniuk2020年01月08日 02:45:37 +00:00Commented Jan 8, 2020 at 2:45