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'

  • 相关阅读:
    在一个字符串中找到第一个只出现一次的字符
    查找最小的k个数
    动规:最大上升子序列
    平衡二叉树
    【笔记】php和mysql结合 搞了一个表出来
    设计模式心得(既设计模式篇终章):描述设计模式时的通用公式
    分享系列 之 linux IO原理与几种零拷贝机制的实现
    近期分享:BIO 与 NIO 的实质区别到底是什么?
    源码阅读笔记 之 ThreadLocal —— 不复杂,却有点绕的一个 per thread API
    小脑袋瓜充满了问号:为什么AMQP可以叫做 Advanced?JMS就要low一等吗?
  • 原文地址:https://www.cnblogs.com/yansc/p/14081575.html
Copyright © 2011-2022 走看看