Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从PostGIS表中删除几何数据_Postgis_Postgresql 9.1_Shapefile - Fatal编程技术网

如何从PostGIS表中删除几何数据

如何从PostGIS表中删除几何数据,postgis,postgresql-9.1,shapefile,Postgis,Postgresql 9.1,Shapefile,我有两个从shapefile生成的表。一个表有陆地区域,另一个表有水域区域。如何减去第一个表中第二个表的水区域 像这样的 UPDATE table1 SET table1.geom AS table1.geom-table2.geom 使用QGIS地理处理差异可以轻松完成。使用该功能。我认为,您还需要一列作为连接两个表的外键,例如id列: UPDATE table1 SET table1.geom = ST_Difference(table1.geom, table2.geom)

我有两个从shapefile生成的表。一个表有陆地区域,另一个表有水域区域。如何减去第一个表中第二个表的水区域

像这样的

UPDATE table1 
   SET table1.geom AS table1.geom-table2.geom
使用QGIS地理处理差异可以轻松完成。使用该功能。我认为,您还需要一列作为连接两个表的外键,例如id列:

UPDATE table1 
SET table1.geom = ST_Difference(table1.geom, table2.geom) 
FROM table2 WHERE table1.id = table2.id;

如果您可以加入表格,请使用Tommaso Di Bucchianico的答案。这是最有效的查询

如果无法连接表(这是GIS表的常见情况),请使用ST_相交ST_差

UPDATE table1
SET table1.geom = ST_Difference(table1.geom, table2.geom)
FROM table2
WHERE ST_Intersects(table1.geom, table2.geom);
如果
table1.geom
类型为MultiPolygon,则使用ST_Multi:

UPDATE table1
SET table1.geom = ST_Multi(ST_Difference(table1.geom, table2.geom))
FROM table2
WHERE ST_Intersects(table1.geom, table2.geom);

几何体类型(多边形)与列类型(多多边形)不匹配我收到此错误
table1。geom
列类型是多多边形,并且
ST_差分(table1.geom,table2.geom)
返回多边形。这就是为什么会出现这个错误。您必须使用ST_Multi()。