zoukankan      html  css  js  c++  java
  • 批量Append

    GIS数据是按照图幅号组织的,现需要每个单独的系统数据进行拼接。

    以下是批量追加代码:

    # ---------------------------------------------------------------------------
    # Append.py
    # Created on: 2013-01-21 10:25:22.00000
    #   (generated by ArcGIS/ModelBuilder)
    # Description: 
    # ---------------------------------------------------------------------------
    
    # Import arcpy module
    import arcpy
    import os.path
    import time
    from arcpy import env
    
    SHP = "E:\lastquick1w"
    dicAllFC={}
    fcall=[]
    gdbAllPath=[]
    #Get Dataset and FeatureClass,Store in dicAllFC,Key =ds value= fc
    if os.path.exists(SHP):
        for dirpath,dirnames,filenames in os.walk(SHP):
            for filename in filenames:
                if os.path.splitext(filename)[1]=='.mdb':
                    mdbfilepath = os.path.join(dirpath,filename)
                    gdbAllPath.append(mdbfilepath)
                    env.workspace=mdbfilepath
                    datasetlist = arcpy.ListDatasets("","Feature")
                    for dataset in datasetlist:
                        if isinstance(mdbfilepath,unicode):
                            env.workspace = mdbfilepath+"\"+dataset
                        else:
                            env.workspace = mdbfilepath+"\"+dataset.decode('utf-8').encode('gb2312')
                        fclist = arcpy.ListFeatureClasses("")
                        if fclist and len(fclist)>0:
                            if not dicAllFC.has_key(dataset):
                                dicAllFC[dataset]=fclist
                    break
                break
    #Get All MDB Path
    if os.path.exists(SHP):
        for dirpath,dirnames,filenames in os.walk(SHP):
            for filename in filenames:
                if os.path.splitext(filename)[1]=='.mdb':
                    if os.path.join(dirpath,filename) not in gdbAllPath:
                        gdbAllPath.append(os.path.join(dirpath,filename))
    for (k,v) in dicAllFC.items():
        for singlefc in v:
            for singlegdbPath in gdbAllPath:
                if isinstance(singlegdbPath,unicode):
                    fcFullPath = singlegdbPath+"\"+k+"\"+singlefc
                else:
                    fcFullPath = singlegdbPath+"\"+k.decode('utf-8').encode('gb2312')+"\"+singlefc.decode('utf-8').encode('gb2312')
                if arcpy.Exists(fcFullPath) and fcFullPath not in fcall:
                    fcall.append(fcFullPath)
                else:
                    print fcFullPath + " Not Exist ****************************************"
            if fcall and len(fcall)>=2:
                targetFC = fcall.pop(0)
                try:
                    arcpy.Append_management(fcall,targetFC,"TEST","","");
                    print targetFC+"@@@succeed At "+time.strftime("%Y-%m-%d %X",time.localtime())+"###Contains "+str(len(fcall))
                    fcall=[]
                except Exception as inst:
                    print targetFC+"@@@Failed At "+time.strftime("%Y-%m-%d %X",time.localtime())+"###Contains "+str(len(fcall))
                    fcall=[]
    print "Complete At"+time.strftime("%Y-%m-%d %X",time.localtime())
                            
    View Code

    代码图片如下:

    高调做事,低调做人~!
  • 相关阅读:
    图的广度优先遍历,运用了数据结构,感觉非常好用,等会把深度优先遍历也用数据结构写一遍
    DFS之素数环问题
    图的深度优先遍历
    八皇后的详细解答,纯手打,求推荐!!!
    c++中priority_queue的用法
    c++中vector的用法
    #ifndef是什么意思????
    筛法求1000000以内素数个数---时间复杂度为o(n)
    C++中1/0和1/0.0的区别
    C++程序生成.exe文件,在文件夹中运行时闪现问题
  • 原文地址:https://www.cnblogs.com/514687800/p/3528674.html
Copyright © 2011-2022 走看看