• 上传gdb文件地理数据库所有图层到企业级空间库


    本例子支持上传gdb中所有图层到Oracle、PostgreSQL空间数据库,并自动去除gdb自动创建的一些字段,同时保留图层别名、字段别名。

    #导入文件夹中的gdb到地理数据库
    import os
    import arcpy
    from arcpy import env
    
    print "begin"
    gdb_path = r"E:	est.gdb"
    #Set SpatialReference
    sr = arcpy.SpatialReference("C:/data/CGCS2000.prj")
    sde_path = r"C:UsersAdministratorAppDataRoamingESRIDesktop10.2ArcCatalog192.168.1.30.sde"
    user_name = "sde.username."
    
    count = 0
    #List all datasets, create gdb with dataset name
    env.workspace = gdb_path
    datasets = arcpy.ListDatasets("","All")
    for ds in datasets:
        dsname = ds
        print str(count) + " gdb >" + dsname
        count = count + 1
        #Change workspace, and create dataset
        env.workspace = sde_path
        try:
            arcpy.CreateFeatureDataset_management(sde_path, dsname, sr)
        except:
            print "dataset exist"
        #Change workspace, and list featureclass
        env.workspace = gdb_path
        fcs = arcpy.ListFeatureClasses("","",ds)
        #when featureClass name = dataset name, ListFeatureClasses can not return
        if dsname not in fcs:
            if arcpy.Exists(dsname + "\" + dsname):
                fcs.append(dsname)
        #iport featureClass
        for fc in fcs:
            fcname = fc
            print fcname
            infc = dsname + "\" + fcname
            #Filter OBJECTID and other similar fields
            fieldmappings = arcpy.FieldMappings()
            infields = arcpy.ListFields(infc)
            for infield in infields:
                fname = infield.name
                fname = fname.lower()
                #Ignore fields
                if fname == "objectid" or fname == "shape":    
                    continue
                if fname == "shape.area" or fname == "shape.len" or fname == "shape_area" or fname == "shape_len":
                    continue
                if "objectid" in fname:
                    continue
                #pg database field
                if "st_length" in fname or "st_area" in fname:
                    continue
                #oracle - upper,pg - lower
                #fname = fname.upper()
                fieldmap = arcpy.FieldMap()
                fieldmap.addInputField(infc, infield.name)
                fieldmappings.addFieldMap(fieldmap)
                del fieldmap
            #upload featureclass to db
            env.workspace = gdb_path
            arcpy.FeatureClassToFeatureClass_conversion(infc, sde_path + "\" + user_name + dsname, fcname, "", fieldmappings)
            del fieldmappings
            #set aliasName
            desc = arcpy.Describe(infc)
            if desc.aliasName != "":
                arcpy.AlterAliasName(sde_path + "\" + user_name + dsname + "\" + user_name + fcname, desc.aliasName)
        print "done"
    
    print "all done"
    空间参考文件:CGCS2000.prj
  • 相关阅读:
    MHA-Atlas-MySQL高可用(上)
    MySQL数据库企业级应用实践(主从复制)
    MySQL数据库企业级应用实践(多实例源码编译)
    MySQL存储引擎
    MySQL索引与事务
    MySQL数据备份
    MySQL数据库操作
    bzoj 1038: [ZJOI2008]瞭望塔
    bzoj 2451 Uyuw's Concert
    poj 2187 Beauty Contest
  • 原文地址:https://www.cnblogs.com/publiter/p/15481856.html
Copyright © 2020-2023  润新知