Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change SRID of geometry column?

Tags:

I have a table where one of the columns is a geometry column the_geom for polygons with an SRID. I added a new column in the same table with exactly the same geometry data as the_geom.

This new column has the name the_geom4258 because I want to set its SRID to 4258. What is the procedure to change the geometry's SRID to another coordinate system? Is it enough to apply the following query:

UPDATE table SET the_geom4258=ST_SetSRID(the_geom4258,4258); 
like image 764
Z77 Avatar asked Jun 10 '10 08:06

Z77


People also ask

What is Srid in geometry?

A spatial reference identifier (SRID) is a unique identifier associated with a specific coordinate system, tolerance, and resolution.

What does Srid 0 mean?

SRID of 0 doesn't technically exist, it just means no SRID — ie, the default if you forget to set it. Zero is a valid SRID, your PostGIS configurations will set for some default value, that in a fresh installation will be WGS84, srid 4326 .

What is ST_Transform?

The ST_Transform function takes a geometry and a spatial reference system identifier as input parameters and transforms the geometry to be represented in the given spatial reference system.

What is geometry in PostGIS?

geometry is a fundamental PostGIS spatial data type used to represent a feature in planar (Euclidean) coordinate systems. All spatial operations on geometry use the units of the Spatial Reference System the geometry is in.


1 Answers

You should use the ST_Transform function. Also use the function AddGeometryColumn to create your new column, to ensure all the necessary constraints are also created:

SELECT AddGeometryColumn('table','the_geom4258',4258, 'POLYGON', 2);  UPDATE table SET the_geom4258 = ST_Transform(the_geom,4258); 

ST_SetSRID just sets the projection identifier, but does not actually transform the geometries.

like image 58
amercader Avatar answered Sep 18 '22 19:09

amercader