免费视频|新人指南|投诉删帖|广告合作|地信网APP下载

查看: 3696|回复: 13
收起左侧

[二次开发] arcgis 面与面赋值 如何按所占比例赋值

[复制链接]

8

主题

3322

铜板

8

好友

工程师

Rank: 7Rank: 7Rank: 7

积分
424
发表于 2021-5-30 11:43 | 显示全部楼层 |阅读模式
arcgis 面与面赋值  如何按所占比例赋值
头像被屏蔽

141

主题

980万

铜板

3万

好友

管理员

Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20

积分
627184
发表于 2021-5-31 09:42 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

0

主题

920

铜板

2

好友

技术员

Rank: 3Rank: 3

积分
79
发表于 2021-5-31 10:24 | 显示全部楼层
相交面积和相交占比分析工具用这个可以
回复 支持 反对

使用道具 举报

0

主题

2534

铜板

2

好友

至尊VIP

Rank: 24Rank: 24Rank: 24Rank: 24Rank: 24Rank: 24

积分
114
发表于 2021-5-31 11:09 | 显示全部楼层
添加唯一标识码字段并赋值,相交,融合唯一标识码字段,计算相交后的面积,再用唯一标识码连接回去,计算占比
回复 支持 反对

使用道具 举报

1

主题

886

铜板

0

好友

助理工程师

Rank: 5Rank: 5

积分
105
发表于 2021-6-1 10:07 | 显示全部楼层
购买超级工具
回复 支持 反对

使用道具 举报

0

主题

1906

铜板

1

好友

助理工程师

Rank: 5Rank: 5

积分
104
发表于 2021-6-1 21:22 | 显示全部楼层
这个需要应该是要搞一个小编程吧
回复 支持 反对

使用道具 举报

1

主题

886

铜板

0

好友

助理工程师

Rank: 5Rank: 5

积分
105
发表于 2021-8-20 17:28 | 显示全部楼层
#coding=utf8
import arcpy
import sys
def initProgress(hint,num):
    arcpy.SetProgressor("step", u"正在"+hint,0,num,1)
def step():
    arcpy.SetProgressorLabel(u"正在进行....")
    arcpy.SetProgressorPosition()
def freeProgress():
    arcpy.ResetProgressor()


##########
def getCount(inFeature):
    result = arcpy.GetCount_management(inFeature)
    count= int(result.getOutput(0))
    return count
#####
def delsame(jfb_Select):
    desc = arcpy.Describe(jfb_Select)
    shapeName = desc.ShapeFieldName
    arcpy.DeleteIdentical_management(jfb_Select, [shapeName])
def getOIDField(jfb_Select):
    desc = arcpy.Describe(jfb_Select)
    OIDField=desc.OIDFieldName
    return OIDField
#######
def AddLayer(mxd,inFeature):

    df=arcpy.mapping.ListDataFrames(mxd)[0]
    addLayer = arcpy.mapping.Layer(inFeature)
    arcpy.mapping.AddLayer(df, addLayer,"TOP") #AUTO_ARRANGE,"BOTTOM",TOP

def FieldExists(TableName,FieldName):
    desc = arcpy.Describe(TableName)
    FieldName=FieldName.upper()
    for field in desc.fields:
        if field.Name.upper() ==FieldName:
            return True
            break
    return False
def getField(TableName,FieldName):
    desc = arcpy.Describe(TableName)
    FieldName=FieldName.upper()
    for field in desc.fields:
        if field.Name.upper() ==FieldName:
            return field
            break
    return None

def getrowbyFID(FieldNames,FID):
    with arcpy.da.SearchCursor(byFeature, FieldNames,oidFieldNameby+"="+str(FID))  as cursor:
        for row in cursor:
            return row

def Main():
    count=getCount(inFeature)
    if count <= 0:
        arcpy.AddMessage(u""+inFeature+"没有数据")
        return
    arcpy.Select_analysis(inFeature,outFeature) #ORIG_FID
    YL_FID1="YL_FID1"
    if not FieldExists(inFeature,YL_FID1):
        arcpy.AddField_management(inFeature,YL_FID1 ,"LONG")
    FidFieldName=getOIDField(outFeature)
    arcpy.CalculateField_management(inFeature,YL_FID1, '!'+FidFieldName+'!', "YTHON")

    FieldNames= FieldList.split(";")
    for FieldName in FieldNames:
        if not FieldExists(outFeature,FieldName):
            inField=getField(byFeature,FieldName)
            if inField:
                arcpy.AddField_management(outFeature,FieldName ,inField.type,inField.precision
                                          ,inField.scale,inField.length,inField.AliasName)
    num=len(FieldNames)
    for i in range(num-1,-1,-1):#0需要循环的
        FieldName=FieldNames[i]
        #arcpy.AddMessage(u"FieldName"+FieldName+",i="+str(i))
        pField=getField(outFeature,FieldName)
        if not pField.editable or pField.type=="OID" or pField.type=="Geometry":
            #arcpy.AddMessage(u"FieldName"+FieldName+",只读,删除")
            FieldNames.pop(i)
    FieldNames.append("OID@")
    YL_FID2="YL_FID2"
    if not FieldExists(byFeature,YL_FID2):
        arcpy.AddField_management(byFeature,YL_FID2 ,"LONG")
    FidFieldName=getOIDField(byFeature)
    arcpy.CalculateField_management(byFeature,YL_FID2, '!'+FidFieldName+'!', "PYTHON")


    mytemp="in_memory/YL999888"
    mysort="in_memory/YL999sort"
    arcpy.AddMessage("TabulateIntersection================")
    arcpy.TabulateIntersection_analysis(outFeature,YL_FID1,byFeature,mytemp,YL_FID2)
    arcpy.AddMessage("TabulateIntersection")
    arcpy.Sort_management(mytemp,mysort,YL_FID1+" ASCENDING;PERCENTAGE DESCENDING")
    arcpy.AddMessage("Sort_management")
    arcpy.DeleteIdentical_management(mysort, [YL_FID1])
    arcpy.AddMessage("DeleteIdentical")
    initProgress("update",num)

    updatecursor=arcpy.da.UpdateCursor(outFeature, FieldNames)
    scursor=arcpy.da.SearchCursor(mysort, [YL_FID1,YL_FID2,"PERCENTAGE"])

    try:
        srow=scursor.next()
        Fieldnum=len(FieldNames)
        k=1

        for row in updatecursor:
            step()
            FID1=srow[0]
            FID2=srow[1]
            Scale=srow[2]
            #arcpy.AddMessage("========{0},{1},{2}".format(FID1,FID2,Scale))

            if Scale>minScale:
                row2= getrowbyFID(FieldNames,FID2)

                for i in range(Fieldnum-1):
                    row[i]=row2[i]

                updatecursor.updateRow(row)
            else:
                arcpy.AddMessage(u""+inFeature+"中FID="+str(FID1)+"最大比例"+str(Scale)+",找不到叠加比例大于"+str(minScale))



            if k<=num:
                srow=scursor.next()
            k=k+1
        if FieldExists(byFeature,YL_FID2):
            arcpy.DeleteField_management(byFeature,YL_FID2)
        if FieldExists(outFeature,YL_FID1):
            arcpy.DeleteField_management(outFeature,YL_FID1)
        if updatecursor:
            del updatecursor
        if scursor:
            del scursor
    finally:

        freeProgress()

arcpy.env.overwriteOutput = True


inFeature = arcpy.GetParameterAsText(0) #输入要素
byFeature = arcpy.GetParameterAsText(1) #依据的要素
FieldList = arcpy.GetParameterAsText(2) #字段列表
outFeature = arcpy.GetParameterAsText(3) #输出要素
minScale=arcpy.GetParameter(4) ##最小比例,如果是负值,取最大的
oidFieldNameby=getOIDField(byFeature)
try:
    Main()
except Exception as e:
    arcpy.AddError(e.message)
回复 支持 反对

使用道具 举报

1

主题

2738

铜板

0

好友

教授级高工

Rank: 12Rank: 12Rank: 12

积分
1473
发表于 2022-1-22 16:35 | 显示全部楼层
感谢分享                                           。
回复 支持 反对

使用道具 举报

1

主题

2902

铜板

1

好友

VIP会员

Rank: 23Rank: 23Rank: 23Rank: 23Rank: 23Rank: 23Rank: 23

积分
128
发表于 2022-1-27 17:53 | 显示全部楼层
6666666666666
回复 支持 反对

使用道具 举报

8

主题

3322

铜板

8

好友

工程师

Rank: 7Rank: 7Rank: 7

积分
424
 楼主| 发表于 2022-2-8 15:52 | 显示全部楼层
感谢大神的指导  谢谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

在线客服
快速回复 返回顶部 返回列表