简体   繁体   English

PostGIS SQL 查询和无效几何

[英]PostGIS SQL query and invalid geometries

I have a postgis database imported with osm2pgsql.我有一个用 osm2pgsql 导入的 postgis 数据库。 Obviously there are lots of invalid geometries which leads to errors with some spatial operations.显然有很多无效的几何图形会导致一些空间操作出现错误。

geometry.buffer(x) seems to solve this problem, but this operation takes a lot of time. geometry.buffer(x) 似乎解决了这个问题,但是这个操作需要很多时间。 So, I wanted to apply it only to geometries that are not valid:因此,我只想将其应用于无效的几何图形:

select * from
    (
        select *
        from polygons
        WHERE NOT IsValid(polygons.geom)
    ) as tbl
where ST_Intersects(
    ST_Buffer(tbl.geom, 0.001),
    GeomFromText('POLYGON ((XY))', 4326)
);

But this query seems to apply the buffer operation to all entries in the table.但是这个查询似乎将缓冲区操作应用于表中的所有条目。 How would you limit this operation to the invalid geometries only?您如何将此操作限制为仅对无效几何图形?

Thank you in advance!先感谢您!

PostgreSQL optimizer expands the inline views prior to optimizing, so it is not guaranteed that the predicates will not be pushed in or out the views. PostgreSQL优化器在优化之前扩展内联视图,因此不能保证谓词不会被推入或推出视图。

The CTE , on the other hand, are always materialized, so this query:另一方面, CTE总是物化的,所以这个查询:

WITH    tbl AS
        (
        SELECT  *
        FROM    polygons
        WHERE   NOT IsValid(polygons.geom)
        )
SELECT  *
FROM    tbl
WHERE   ST_Intersects
                (
                ST_Buffer(tbl.geom, 0.001),
                GeomFromText('POLYGON ((XY))', 4326)
                );

will only apply ST_buffer to the invalid geometries.只会将ST_buffer应用于无效的几何图形。

However, this does not seem to be a right solution to me.但是,这对我来说似乎不是一个正确的解决方案。 Could please provide a sample of "invalid geometry" produced by the import?能否提供进口产生的“无效几何”样本?

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

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