使用QGIS虚拟层的多边形相交


10

我正在尝试通过使用虚拟层来使QGIS中的多边形几何图形相交:

SELECT
    sbqry.rowid AS gid,
    sbqry.geom
FROM
    (SELECT
        ST_Intersection(land_parcels.geometry, flood_zone.geometry) AS geom
    FROM land_parcels, flood_zone
    WHERE ST_Intersects(land_parcels.geometry, flood_zone.geometry) AND NOT ST_Touches(land_parcels.geometry, flood_zone.geometry))
    AS sbqry;

不幸的是,sbqry.rowid AS gid返回NULL而不是自动递增值。

在此处输入图片说明 在此处输入图片说明

有人知道如何创建名为“ gid”的唯一标识符列吗?据我所知,虚拟层是基于SQLite / Spatialite的。


您为虚拟层使用哪种数据类型?
DPSSpatial

输入层是.shp文件,输出几何类型是'多边形'。
eclipsed_by_the_moon

我不知道您可以在shapefile上运行空间函数(ST_ *)!那很棒!!!
DPSSpatial '16

您是否尝试过从“ SELECT rowid as gid”中删除sbqry ...我发现了另一个带有此类示例的帖子。
kttii

“ rowid AS gid”适用于简单的SELECT语句,例如创建缓冲区,但不适用于子查询。
eclipsed_by_the_moon

Answers:


3

在PostGIS中,如果只需要行号,则可以执行以下操作:

SELECT
    row_number() over () as gid,
    sbqry.geom
FROM
    (SELECT
        ST_Intersection(land_parcels.geometry, flood_zone.geometry) AS geom
    FROM land_parcels, flood_zone
    WHERE ST_Intersects(land_parcels.geometry, flood_zone.geometry) AND NOT ST_Touches(land_parcels.geometry, flood_zone.geometry))
    AS sbqry;

“ row_number()over()”似乎在PostGIS中有效,但在SpatiaLite(QGIS虚拟层)中无效。
eclipsed_by_the_moon

2
SELECT  f.rowid AS gid, f.geom
FROM
(SELECT sbqry.geom
FROM (SELECT ST_Intersection(land_parcels.geometry, flood_zone.geometry) AS geom FROM land_parcels, flood_zone 
WHERE ST_Intersects(land_parcels.geometry, flood_zone.geometry) AND NOT ST_Touches(land_parcels.geometry, flood_zone.geometry)) AS sbqry) as f

不幸的是,查询仅返回NULL值。
eclipsed_by_the_moon
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.