我有两个包含多边形的形状文件。我试图从中找到增量。尝试通过以下代码执行此操作,但未按我预期的方式工作。以下是两个形状文件蓝色一个是缓冲区形状文件,我需要删除与蓝色缓冲区相交的缓冲区。即需要获得与Qgis 差异 函数相同的几何差异
import fiona
from shapely.geometry import shape, mapping, Polygon
green = fiona.open(
"/home/gulve/manual_geo_ingestion/probe-data/images/r/shape_out/dissolved.shp")
blue = fiona.open(
"/home/gulve/manual_geo_ingestion/probe-data/images/g/shape/shape.shp")
print([not shape(i['geometry']).difference(shape(j['geometry'])).is_empty for i, j in zip(list(blue), list(green))])
schema = {'geometry': 'Polygon',
'properties': {}}
crs = {'init': u'epsg:3857'}
with fiona.open(
'/home/gulve/manual_geo_ingestion/probe-data/images/r/shape_out/diff.shp', 'w',
driver='ESRI Shapefile', crs=crs, schema=schema
) as write_shape:
for geom in [shape(i['geometry']).difference(shape(j['geometry'])) for i, j in zip(list(blue), list(green))]:
if not geom.empty:
write_shape.write({'geometry': mapping((shape(geom))), 'properties': {}})