创建位置分配图层 (Network Analyst)
摘要
创建位置分配网络分析图层并设置其分析属性。位置分配分析图层对于从一组可能位置中选择指定数量的设施点(以便以最佳且高效的方式将需求点分配给设施点)十分有用。
用法
语法
| 参数 | 说明 | 数据类型 | 
in_network_dataset  | 
 要执行位置分配分析的网络数据集。  | Network Dataset Layer | 
out_network_analysis_layer  | 
 要创建的位置分配网络分析图层的名称。  | String | 
impedance_attribute  | 
 分析过程中用作阻抗的成本属性。  | String | 
loc_alloc_from_to (可选)  | 
 指定计算网络成本时设施点与请求点之间的行驶方向。 
 使用此选项会影响具有单向限制和根据方向不同阻抗不同的网络上的请求点到设施点的分配。例如,从请求点驾车到达设施点可能需要 15 分钟,但从设施点行驶至请求点仅需 10 分钟。 消防部门通常使用设施点到请求点设置,因为他们需要关注从消防站行驶到紧急救援位置所花的时间。零售商店则更关注顾客到达商店所花的时间;因此,商店通常使用请求点到设施点选项。  | String | 
loc_alloc_problem_type (可选)  | 
 将要求解的问题的类型。问题类型的选择取决于要定位的设施点种类。不同种类的设施点具有不同的优先级和约束。 
  | String | 
number_facilities_to_find (可选)  | 
 指定求解程序将查找的设施点数。 当要查找的设施点多于所需设施点时,FacilityType 值为“必选项”的设施点将始终为解的一部分;要选择的任何额外设施点都将从候选设施点中选取。 在求解前所有 FacilityType 值为“已选项”的设施点在求解时都将视为候选设施点。 对于 MINIMIZE_FACILITIES 问题类型不会考虑参数值,因为求解程序会确定最小的设施点数来查找最大的覆盖范围。 对于 TARGET_MARKET_SHARE 问题类型,参数值会被覆盖,因为求解程序会搜索要占有指定市场份额所需的最小设施点数。  | Long | 
impedance_cutoff (可选)  | 
  阻抗中断指定请求点可分配给设施点的最大阻抗。最大阻抗以沿网络的最小成本路径进行测量。如果请求点位于中断外,则不会被分配。此属性可用于对人们为前往商店而愿意行进的最大距离,以及消防站到达社区中任一请求点所允许的最大时间进行建模。 如果设置请求点的 Cutoff_[阻抗] 属性,该属性将覆盖分析图层的阻抗中断属性。您可能会发现,乡村居民愿意走 10 英里远去往某个设施点,而城镇居民则只愿意走 2 英里的路程。此情况可以如下方式建模:将分析图层的阻抗中断值设置为 10,而将城镇地区中请求点的 Cutoff_Miles 值设置为 2。  | Double | 
impedance_transformation (可选)  | 
 此属性可设置对设施点与请求点间网络成本进行变换的方程。它还可与阻抗参数结合使用,指定设施点与请求点间的网络阻抗对于求解程序选择设施点的影响的严重程度。 
 如果设置请求点的 ImpedanceTransformation 属性,该属性会覆盖分析图层的“阻抗变换”属性。这时,您可能要针对城镇居民和乡村居民使用不同的阻抗变换。可通过为分析图层设置阻抗变换以匹配乡村居民的阻抗参数,同时为城镇地区中的请求点设置阻抗参数以匹配城镇居民的阻抗参数,来执行建模。  | String | 
impedance_parameter (可选)  | 
 为“阻抗变换”参数中指定的方程提供参数值。当阻抗变换的类型为线性时会忽略参数值。对于幂阻抗变换和指数阻抗变换,应设置非零值。 如果设置请求点的 ImpedanceParameter 属性,该属性会覆盖分析图层的阻抗参数属性。您可能要针对城镇居民和乡村居民使用不同的阻抗参数。可通过为分析图层设置阻抗变换以匹配乡村居民的阻抗参数,同时为城镇地区中的请求点设置阻抗参数以匹配城镇居民的阻抗参数,来执行建模。  | Double | 
target_market_share (可选)  | 
 指定当位置分配问题类型参数设置为 TARGET_MARKET_SHARE 时要求解的目标市场份额百分比。它是您希望设施点解占总请求权重的百分比。求解程序会求出为占有该值指定的目标市场份额所需的最小设施点数。  | Double | 
accumulate_attribute_name [accumulate_attribute_name,...] (可选)  | 分析过程中要累积的成本属性的列表。这些累积属性仅供参考;求解程序仅使用阻抗属性参数所指定的成本属性来计算路径。 对于每个累积的成本属性,均会向求解程序所输出的路径中添加一个 Total_[阻抗] 属性。  | String | 
UTurn_policy (可选)  | 
 交汇点的 U 形转弯策略。允许 U 形转弯表示求解程序可以在交汇点处转向并沿同一街道往回行驶。 考虑到交汇点表示街道交叉路口和死角,不同的车辆可以在某些交汇点转弯,而在其他交汇点则不行 - 这取决于交汇点是交叉路口还是死角。为适应此情况,U 形转弯策略参数由连接到交汇点的边数隐性指定,这称为交汇点原子价。此参数可接受的值如下所列;每个值的后面是根据交汇点原子价对其含义的描述。 
  提示:如果您需要定义更加精确的 U 形转弯策略,可以考虑在网络成本属性中添加一个通用转弯延迟赋值器,或者如果存在的话,调整其设置,并特别注意反向转弯的配置。还要考虑设置网络位置的 CurbApproach 属性。  | String | 
restriction_attribute_name [restriction_attribute_name,...] (可选)  | 
 分析过程中要应用的限制属性的列表。  | String | 
hierarchy (可选)  | 
 如果未在用于执行分析的网络数据集中定义等级属性,该参数将不可用。在这种情况下,使用 "#" 作为参数值。  | Boolean | 
output_path_shape (可选)  | 
  | String | 
default_capacity (可选)  | 
 指定位置分配问题类型参数设为 MAXIMIZE_CAPACITATED_COVERAGE 时默认的设施点容量。对于所有其他问题类型,可忽略此参数。 设施点有容量属性,如果此属性设置为非空值,将覆盖该设施点的默认容量参数。  | Double | 
time_of_day (可选)  | 
 指示出发的时间和日期。出发时间可以来自设施点或请求点,取决于行驶是从请求点到设施点还是从设施点到请求点。 如果您已经选择了基于流量的阻抗属性,将会根据特定的某天某时的动态交通状况来生成解决方案。日期和时间可被指定为 5/14/2012 10:30 AM。 可使用以下日期来指定一周中的每一天,而无需使用特定的日期。 
  | Date | 
代码实例
仅使用必需参数执行此工具。
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.na.MakeLocationAllocationLayer("Transportation/Streets_ND",
                                     "StoreLocations","Minutes")
使用所有参数执行此工具。
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.na.MakeLocationAllocationLayer("Transportation/Streets_ND","NewStores",
                                     "Minutes","DEMAND_TO_FACILITY",
                                     "MAXIMIZE_ATTENDANCE",3,5,"POWER",2,"",
                                     ["Minutes","Meters"],"ALLOW_UTURNS",
                                     ["Oneway"],"NO_HIERARCHY","STRAIGHT_LINES",
                                     "","9 AM")
以下独立 Python 脚本演示了如何使用创建位置分配图层 (MakeLocationAllocationLayer) 工具选择将为连锁零售店生成最大业务量的商店位置。
# Name: MakeLocationAllocationLayer_Workflow.py
# Description: Choose the store locations that would generate the most business 
#              for a retail chain. For this scenario we will perform the 
#              location-allocation analysis using maximize attendance problem 
#              type. 
# Requirements: Network Analyst Extension 
#Import system modules
import arcpy
from arcpy import env
try:
    #Check out the Network Analyst extension license
    arcpy.CheckOutExtension("Network")
    #Set environment settings
    env.workspace = "C:/data/SanFrancisco.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/Streets_ND"
    outNALayerName = "NewStoreLocations"
    impedanceAttribute = "TravelTime"
    inFacilities = "Analysis/CandidateStores"
    requiredFacility = "Analysis/ExistingStore"
    inDemandPoints = "Analysis/TractCentroids"
    outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr"
    
    #Create a new location-allocation layer. In this case the demand travels to
    #the facility. We wish to find 3 potential store locations out of all the
    #candidate store locations using the maximize attendance model.
    outNALayer = arcpy.na.MakeLocationAllocationLayer(inNetworkDataset,
                                                      outNALayerName,
                                                      impedanceAttribute,
                                                      "DEMAND_TO_FACILITY",
                                                      "MAXIMIZE_ATTENDANCE",3,5,
                                                      "LINEAR")
    
    #Get the layer object from the result object. The location-allocation layer
    #can now be referenced using the layer object.
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the location-allocation layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    facilitiesLayerName = subLayerNames["Facilities"]
    demandPointsLayerName = subLayerNames["DemandPoints"]
    
    
    #Load the candidate store locations as facilities using default search
    #tolerance and field mappings.
    arcpy.na.AddLocations(outNALayer, facilitiesLayerName, inFacilities, "", "",
                          exclude_restricted_elements = "EXCLUDE")
    
    #Load the existing store location as the required facility. Use the field
    #mappings to set the facility type to requried. We need to append this
    #required facility to existing facilities.
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, facilitiesLayerName)
    fieldMappings["FacilityType"].defaultValue = 1
    arcpy.na.AddLocations(outNALayer, facilitiesLayerName, requiredFacility,
                          fieldMappings, "", append = "APPEND",
                          exclude_restricted_elements = "EXCLUDE")
    
    #Load the tract centroids as demand points using default search tolerance
    #Use the field mappings to map the Weight property from POP2000 field.
    demandFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer,
                                                        demandPointsLayerName)
    demandFieldMappings["Weight"].mappedFieldName = "POP2000"    
    arcpy.na.AddLocations(outNALayer,demandPointsLayerName ,inDemandPoints,
                          demandFieldMappings, "",
                          exclude_restricted_elements = "EXCLUDE")
    
    #Solve the location-allocation layer
    arcpy.na.Solve(outNALayer)
    
    #Save the solved location-allocation 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 occured on line %i" % tb.tb_lineno
    print str(e)
