赞
踩
(地理国情监测)arcgis使用python,做arctoolbox,渔网裁剪gdb里的要素,四等分:
# ecoding=gbk coding = 'utf-8' import os import shutil import arcpy import arcpy.cartography as CA import arcpy.management as DM import arcpy.analysis as AN inSacle=1 def setupProcess(): inputGDB1 = arcpy.GetParameterAsText(0); inputGDB2 = arcpy.GetParameterAsText(1); #inputGDB1 = "E:\\001.yangdebin\\渔网裁剪\\LCA\\DLGGC\\JC20_340401.gdb" #inputGDB2 = "E:\\001.yangdebin\\渔网裁剪\\LCA\\BGData\\JC19_340401.gdb" lca1= inputGDB1 + "/LcrDataset/UV_LCRA"; lca2= inputGDB2 + "/LcrDataset/V_LCRA"; desc = arcpy.Describe(lca1); extent = desc.extent; sr = desc.spatialReference; #创建渔网 fishnet = inputGDB1 + "/LcrDataset/fishnet"; originCoordinate = str(extent.XMin) + " " + str(extent.YMin); yAxisCoordinate = str(extent.XMin) + " " + str(int(extent.YMin)+10); oppositeCoorner = str(extent.XMax) + " " + str(extent.YMax); arcpy.CreateFishnet_management(fishnet, originCoordinate, yAxisCoordinate, 0, 0, 2, 2, oppositeCoorner, "NO_LABELS", lca1, "POLYGON"); print("--------创建渔网Success!--------") #添加标记字段 arcpy.AddField_management(fishnet, "Index", "TEXT","", "", 4); arcpy.CalculateField_management(fishnet, "Index", "[OID]","VB") #标记 idenFeatures1 = inputGDB1 + "/LcrDataset/idenFeatures"; idenFeatures2 = inputGDB2 + "/LcrDataset/idenFeatures"; arcpy.Identity_analysis(lca1, fishnet, idenFeatures1); arcpy.Identity_analysis(lca2, fishnet, idenFeatures2); outPath = arcpy.GetParameterAsText(2); #outPath = "E:\\001.yangdebin\\渔网裁剪\\LCA\\result" (filepath1,gdbname1) = os.path.split(inputGDB1); (filepath2,gdbname2) = os.path.split(inputGDB2); #分别输出 arcpy.CreateFolder_management(outPath, "block_1"); arcpy.CreateFolder_management(outPath+"/block_1/", "DLGGC"); arcpy.CreateFileGDB_management(outPath+"/block_1/DLGGC", gdbname1); arcpy.CreateFeatureDataset_management(outPath+"/block_1/DLGGC/"+gdbname1, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures1, outPath+"/block_1/DLGGC/"+gdbname1+"/LcrDataset", "UV_LCRA", "Index = '1'"); arcpy.CreateFolder_management(outPath+"/block_1/", "BGData"); arcpy.CreateFileGDB_management(outPath+"/block_1/BGData", gdbname2) arcpy.CreateFeatureDataset_management(outPath+"/block_1/BGData/"+gdbname2, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures2, outPath+"/block_1/BGData/"+gdbname2+"/LcrDataset", "V_LCRA", "Index = '1'"); print("--------创建block_1 ---Success!--------") arcpy.CreateFolder_management(outPath, "block_2"); arcpy.CreateFolder_management(outPath+"/block_2/", "DLGGC"); arcpy.CreateFileGDB_management(outPath+"/block_2/DLGGC", gdbname1) arcpy.CreateFeatureDataset_management(outPath+"/block_2/DLGGC/"+gdbname1, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures1, outPath+"/block_2/DLGGC/"+gdbname1+"/LcrDataset", "UV_LCRA", "Index = '2'"); arcpy.CreateFolder_management(outPath+"/block_2/", "BGData"); arcpy.CreateFileGDB_management(outPath+"/block_2/BGData", gdbname2) arcpy.CreateFeatureDataset_management(outPath+"/block_2/BGData/"+gdbname2, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures2, outPath+"/block_2/BGData/"+gdbname2+"/LcrDataset", "V_LCRA", "Index = '2'"); print("--------创建block_2 ---Success!--------") arcpy.CreateFolder_management(outPath, "block_3"); arcpy.CreateFolder_management(outPath+"/block_3/", "DLGGC"); arcpy.CreateFileGDB_management(outPath+"/block_3/DLGGC", gdbname1) arcpy.CreateFeatureDataset_management(outPath+"/block_3/DLGGC/"+gdbname1, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures1, outPath+"/block_3/DLGGC/"+gdbname1+"/LcrDataset", "UV_LCRA", "Index = '3'"); arcpy.CreateFolder_management(outPath+"/block_3/", "BGData"); arcpy.CreateFileGDB_management(outPath+"/block_3/BGData", gdbname2) arcpy.CreateFeatureDataset_management(outPath+"/block_3/BGData/"+gdbname2, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures2, outPath+"/block_3/BGData/"+gdbname2+"/LcrDataset", "V_LCRA", "Index = '3'"); print("--------创建block_3 ---Success!--------") arcpy.CreateFolder_management(outPath, "block_4"); arcpy.CreateFolder_management(outPath+"/block_4/", "DLGGC"); arcpy.CreateFileGDB_management(outPath+"/block_4/DLGGC", gdbname1) arcpy.CreateFeatureDataset_management(outPath+"/block_4/DLGGC/"+gdbname1, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures1, outPath+"/block_4/DLGGC/"+gdbname1+"/LcrDataset", "UV_LCRA", "Index = '4'"); arcpy.CreateFolder_management(outPath+"/block_4/", "BGData"); arcpy.CreateFileGDB_management(outPath+"/block_4/BGData", gdbname2) arcpy.CreateFeatureDataset_management(outPath+"/block_4/BGData/"+gdbname2, "LcrDataset", sr); arcpy.FeatureClassToFeatureClass_conversion(idenFeatures2, outPath+"/block_4/BGData/"+gdbname2+"/LcrDataset", "V_LCRA", "Index = '4'"); print("--------创建block_4 ---Success!--------") arcpy.Delete_management(idenFeatures1, ""); arcpy.Delete_management(idenFeatures2, ""); arcpy.Delete_management(fishnet, ""); print("--------全部---Success!--------") if __name__ == "__main__": setupProcess()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。