import os, shutil, sys
from osgeo import ogr, gdal, gdal_array, ogr, osr
import math, numpy
def shapefile_geometric_relations_operations(_input_shapefile_1, _input_shapefile_2, result_shapfile, action=1):
'''
_input_shapefile_1第一个矢量文件的绝对路径
_input_shapefile_2第二个矢量文件的绝对路径
result_shapfile输出矢量文件绝对路径
action=1表示取两个矢量的交集intersection
=2表示取两个矢量交集的反集sysdifference
=3表示两个矢量相减difference
=4表示取两个矢量的并集union
这个函数对输入的矢量文件没有坐标系的要求,输出的矢量文件和输入的矢量文件坐标系相同
'''
_ds_1, _ds_2 = ogr.Open(_input_shapefile_1), ogr.Open(_input_shapefile_2)
_lyr_1, _lyr_2 = _ds_1.GetLayer(), _ds_2.GetLayer()
shpdriver = ogr.GetDriverByName('ESRI Shapefile')
if os.path.exists(result_shapfile):
shpdriver.DeleteDataSource(result_shapfile)
outDifference = shpdriver.CreateDataSource(result_shapfile)
outDifferenceLyr = outDifference
基于OSGEO的两个面状矢量文件空间操作:相交、交集取反、相减和合并
于 2022-03-24 09:16:06 首次发布