arcpy从面要素中根据字段获取指定的面来和sde中的点位进行叠加操作,并统计点位信息。数据存储在内存中。

1、从面要素中根据字段获取指定的面

# 通过objectid从拆迁项目中获取拆迁项目范围线
def getCQXM(cqxmPath,objectid,val):
    # 创建搜索游标并读取相应数据
    with arcpy.da.SearchCursor(cqxmPath, ["SHAPE@"], "{} = {}".format(objectid, val)) as cursor:
        # 获取符合条件的记录
        row = next(cursor, None)
    if row is not None:
        # 获取几何对象并创建输出文件名(可选)
        geometry = row[0]
    times = int(time.time())
    # 向临时要素类中添加面要素
    arcpy.CreateFeatureclass_management("in_memory", "temp_polygon_" + str(times), "POLYGON")
    insertCursor = arcpy.da.InsertCursor("in_memory/temp_polygon_"+str(times), ["SHAPE@"])
    insertCursor.insertRow([geometry])
    #返回面要素存储路径
    return "in_memory/temp_polygon_"+str(times)

2、获取到内存中存储的面要素和sde中’cqh’的点要素使用arcpy.Intersect_analysis()方法进行叠加操作

def IntersectAnalysis():
    times = int(time.time())
    # 创建一个临时要素类,用于存储相交分析的结果
    intersect_output = "in_memory/temp_intersect_" + str(times)
    polygonPath = getCQXM(cqxm,'OBJECTID','972')
    arcpy.Intersect_analysis([cqh,polygonPath], intersect_output, "ALL")

    sfdf_false = '0'
    sfdf_true = '1'
    sfqy_false = '0'
    sfqy_true = '1'
    count_map = {'sfdf_false_count':0,'sfdf_true_count':0,'sfqy_false_count':0,'sfqy_true_count':0}
    # 从临时要素类中读取数据
    fields = ['OBJECTID','XMID','NHXM','SFDF','SFQY','COLOR','SJWZ','YDMJ','FZWBCCSDJ','BCHCSDJ','ZYZHXM','BCCSDJ','QYMC','QYBCCSDJ','CSBCZJHJ','XMMC','FWXZ']
    with arcpy.da.SearchCursor(intersect_output, fields) as cursor:
        # 获取对应值的数量
        for row in cursor:
            if str(row[3]) == sfdf_false:
                count_map['sfdf_false_count'] = count_map['sfdf_false_count']+1
            if str(row[3]) == sfdf_true:
                count_map['sfdf_true_count'] = count_map['sfdf_true_count']+1
            if str(row[4]) == sfqy_false:
                count_map['sfqy_false_count'] = count_map['sfqy_false_count']+1
            if str(row[4]) == sfqy_true:
                count_map['sfqy_true_count'] = count_map['sfqy_true_count']+1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值