11

I have a Point table in which the geometry column contains both 3 dimension and 2 dimension values.I want to convert this 3 dimensional geometry to 2 dimension.Is there any function in PostGIS? Please help me to solve this problem.

Regards Sreesha.T.A

  • I would like to use ST_Force2D but it says: function st_force2d(geometry) does not exist Do you have any idea? Thanks, Laszlo – Laszlo Oct 17 '18 at 10:30
14

http://postgis.net/docs/manual-2.0/ST_Force_2D.html

SELECT ST_Force_2D(the_geom) FROM...

Update your existing table

 
ALTER TABLE your_geo_table ADD geom2d geometry;
UPDATE your_geo_table SET geom2d = ST_Force_2D(the_geom);

See also http://postgis.net/docs/

  • 1
    Use ST_Force2D instead of ST_Force_2d. ST_Force_2d signature was deprecated in 2.1.0. – jgrocha Jan 19 '17 at 16:05
8

If you don't want to add a new column you can also do the following:

ALTER TABLE your_geo_table  
  ALTER COLUMN geom TYPE geometry(YOUR_GEOM_TYPE, YOUR_EPSG) 
    USING ST_Force_2D(geom);

For example:

ALTER TABLE your_geo_table  
  ALTER COLUMN geom TYPE geometry(MULTILINESTRING, 4326) 
    USING ST_Force_2D(geom);
  • I've tried this suggestion on a database I have (in my case I had a similar problem but I wanted to force the points to be 3D), but I get this error: ERROR: function st_force_3d(geography) does not exist LINE 3: USING ST_Force_3D(geom); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. ********** Error ********** ERROR: function st_force_3d(geography) does not exist SQL state: 42883 Hint: No function matches the given name and argument types. You might need to add explicit type casts. Character: 89 – Andrea Grandi Dec 19 '16 at 11:43
  • I guess it's because ST_Force3D works with geometry type and not with geography type. – Thomas B Dec 19 '16 at 12:34

Your Answer

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

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