我在 Windows 10 中使用 Postgis 2.4 和 posgresql 10。我有以下 SQL 查询:
WITH data (the_geom) as (
SELECT a.gid,
CASE WHEN ST_Within(a.geom,b.geom) THEN a.geom
ELSE ST_Intersection(a.geom,b.geom)
END AS the_geom
FROM source.g100_wby_lakes_r as a
JOIN extents.map_areas as b ON ST_Intersects(a.geom,b.geom)
WHERE b.map_id='AA01'
)
INSERT into public.g100_wby_lakes_r (gid,geom)
select *
from data
where st_GeometryType(the_geom)='MULTIPOLYGON';
Run Code Online (Sandbox Code Playgroud)
它尝试选择两个多边形之间的交点,并且只将相交的几何图形插入到新表中,这些几何图形也是多边形(交点也可能导致点或线)。除了给出以下错误的 WHERE 子句外,所有工作都有效:
WITH data (the_geom) as (
SELECT a.gid,
CASE WHEN ST_Within(a.geom,b.geom) THEN a.geom
ELSE ST_Intersection(a.geom,b.geom)
END AS the_geom
FROM source.g100_wby_lakes_r as a
JOIN extents.map_areas as b ON …Run Code Online (Sandbox Code Playgroud) postgresql ×1