Reputation: 402
I am using PostgreSQL 9.5 with PostGIS 2.2.
I found some of my data has invalid geometries so I am trying to rectify that.
UPDATE schema.table
SET geom = ST_MakeValid(geom)
WHERE NOT ST_IsValid(geom);
But I have this error :
ERROR: Column has M dimension but geometry does not
État SQL :22023
I previously checked how many dimensions the geometries have with
SELECT count(gid), ST_Dimension(geom)
FROM schema.table
GROUP BY ST_Dimension(geom) ;
And they all have only 2 dimensions.
So what worked was :
UPDATE schema.table
SET geom = ST_Force4D(ST_MakeValid(geom))
WHERE NOT ST_IsValid(geom);
But I don't know why and and what is going on...
Can somebody explain me ?
Upvotes: 1
Views: 2386
Reputation: 335
The type of your column is effectively 3 or 4D geometry. You've used the wrong function to test the coordinate dimension count of your geometries.
St_Dimension is giving you the inherent dimension of the geometry, which is 0 for Point, 1 for Lines, and 2 for Polygons.
To get the number of dimensions, you have to use st_ndims.
See the doc :
Here is a little query to illustrate the difference:
SELECT st_ndims(g) = 4 , st_dimension(g) = 2
FROM (SELECT 'POLYGON((0 0 0 0, 1 0 1 1, 0.5 1 1 1, 0 0 0 0))'::geometry g) f
Upvotes: 2