简体   繁体   English

PostGIS:调用ST_MakeValid()时,M维错误

[英]PostGIS : errors with M dimension when calling ST_MakeValid()

I am using PostgreSQL 9.5 with PostGIS 2.2. 我在PostgreSQL 9.5和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. 列的类型实际上是3或4D几何。 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. St_Dimension为您提供了几何图形的固有尺寸,对于Point为0,对于Lines为1,对于Polygons为2。

To get the number of dimensions, you have to use st_ndims. 要获取维数,必须使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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