简体   繁体   中英

PostGIS : errors with M dimension when calling ST_MakeValid()

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM