当前位置:   article > 正文

(地理国情监测)arcgis使用python,做arctoolbox,渔网裁剪gdb里的要素,四等分_arcgis渔网裁剪

arcgis渔网裁剪

(地理国情监测)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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/310775
推荐阅读
相关标签
  

闽ICP备14008679号