how to transfer geometry from one column to an empty column on postgre sql

Viewed 77

i used alter table to create a new column(named geom, 2157) but transferring geo informations from geom 4386 column to new geom, 2157 column is a problem

ALTER TABLE major ADD COLUMN gem geometry(POINT, 2157);
UPDATE major SET geom = ST_SetSRID(ST_MakePoint, 2157);
1 Answers

ST_Transform is what you're looking for:

Sample Data

CREATE TABLE t (geom GEOMETRY(POINT,4326));
INSERT INTO t VALUES ('SRID=4326;POINT(-4.43 54.32)'::GEOMETRY);
ALTER TABLE t ADD COLUMN geom2 geometry(POINT,2157);

To update the new geometry column with the geometry transformed to the SRS 2157 just use ST_Transform as follows:

UPDATE t SET geom2 = ST_Transform(geom,2157);

And here is your transformed geometry:

 SELECT ST_AsText(geom), ST_AsText(geom2) FROM t;
     st_astext      |                st_astext                 
--------------------+------------------------------------------
 POINT(-4.43 54.32) | POINT(832216.581140537 847131.995720883)
(1 Zeile)
Related