I am trying to validate the geometry of all polygons in my table.

When I perform the following query, I get an error:

update parcel2016
set geom = St_MakeValid(geom)

ERROR:  Column has M dimension but geometry does not
********** Error **********

ERROR: Column has M dimension but geometry does not
SQL state: 22023

How might this be corrected? I've also tried wrapping in:

set geom = st_multi(st_collectionextract(st_makevalid(geom)))

but this was equally unsuccessful

  • It seems that your polygons are of XYM or XYZM type but ST_MakeValid does not keep the M (measure) dimension. It is documented in postgis.net/docs/ST_MakeValid.html that 3d is supported but there is no mention about M. Do you really need M or could you convert your data into XY or XYZ? – user30184 Dec 12 '16 at 7:10
  • I don't need M at all – the_darkside Dec 12 '16 at 7:15
  • In that case I think it would be easiest to copy the whole table into a new one and drop M with some of the methods from the list of gis.stackexchange.com/questions/221052/…. If you are a beginner then I recommend using ogr2ogr with -dim XY because it takes automatically care of spatial index and updating geometry_columns. – user30184 Dec 12 '16 at 7:28

Without knowing what the full dimensionality of your data are (XYZM or just XYM) I cannot give a perfect answer, but assuming you have the more common XYZM you can strip the M dimension before running the ST_MakeValid(). Hopefully the M isn't important to you...

ALTER TABLE mytable 
  TYPE geometry(polygonz, 4326) 
  USING ST_Force3DZ(geom)

You'll have to fill in the geometry type and SRID number that make sense for your table.

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.