基于OSGEO的两个面状矢量文件空间操作:相交、交集取反、相减和合并

本文介绍了如何使用OSGeo库在Python环境中进行面状矢量文件的空间操作,包括相交、交集取反、相减和合并等核心功能,详细阐述了相关代码实现和步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

John H.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值