zoukankan      html  css  js  c++  java
  • arcpy 10.8计算最短路径,并复制出结果

    官方示例,记录而已
    #
    coding=utf-8 import arcpy from arcpy import env try: #Check out the Network Analyst extension license arcpy.CheckOutExtension("Network") #Set environment settings env.workspace = r'E:xxx est2Data80.gdb' env.overwriteOutput = True #Set local variables inNetworkDataset = r'RD/RD_ND' outNALayerName = "ClosestHospital" impedanceAttribute = "Length" accumulateAttributeName = ["Meters"] inFacilities = "DX/三甲医院2" inIncidents = "TMP/小区点" outLayerFile = "E:\xxx\test2\" + outNALayerName + "333.lyr" out_featureclass =r'E:xxx est2Data80.gdbTMPHOS' #Create a new closest facility analysis layer. Apart from finding the drive #time to the closest warehouse, we also want to find the total distance. So #we will accumulate the "Meters" impedance attribute. outNALayer = arcpy.na.MakeClosestFacilityLayer(inNetworkDataset,outNALayerName, impedanceAttribute,"TRAVEL_TO", "",1, "", "ALLOW_UTURNS") #Get the layer object from the result object. The closest facility layer can #now be referenced using the layer object. outNALayer = outNALayer.getOutput(0) #Get the names of all the sublayers within the closest facility layer. subLayerNames = arcpy.na.GetNAClassNames(outNALayer) #Stores the layer names that we will use later facilitiesLayerName = subLayerNames["Facilities"] incidentsLayerName = subLayerNames["Incidents"] #Load the warehouses as Facilities using the default field mappings and #search tolerance arcpy.na.AddLocations(outNALayer, facilitiesLayerName, inFacilities, "", "") #Load the Stores as Incidents. Map the Name property from the NOM field #using field mappings fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, incidentsLayerName) fieldMappings["Name"].mappedFieldName = "NOM" arcpy.na.AddLocations(outNALayer, incidentsLayerName, inIncidents, fieldMappings,"") #Solve the closest facility layer arcpy.na.Solve(outNALayer) #复制最短距离 routes 到其他地方 routes = arcpy.mapping.ListLayers(outNALayer, "Routes")[0] arcpy.CopyFeatures_management(routes, out_featureclass) #Save the solved closest facility layer as a layer file on disk with relative paths arcpy.management.SaveToLayerFile(outNALayer, outLayerFile,"RELATIVE") print "Script completed successfully" except Exception as e: # If an error occurred, print line number and error message import traceback, sys tb = sys.exc_info()[2] print "An error occurred on line %i" % tb.tb_lineno print str(e) print 'over'

  • 相关阅读:
    python 爬虫数据处理字符串时间转换格式方法
    python 爬虫时间数据-时间格式转换
    python 爬虫数据时间转换格式
    python 爬虫newspaper3k 新闻爬去方法 利用第三方库
    python 三方库
    python 26个技巧
    python 爬虫第三方库
    python 爬虫数据准换时间格式
    python cookies提取——从字符串到字典(一行Python代码)
    python scrapy 把cookie并转化为字典的形式
  • 原文地址:https://www.cnblogs.com/yansc/p/14081575.html
Copyright © 2011-2022 走看看