创建服务区图层 (Network Analyst)
摘要
创建服务区网络分析图层并设置其分析属性。服务区分析图层主要用于确定在指定中断成本范围内能从设施点位置访问的区域。
 注:
注:生成服务区和创建服务区图层工具类似,只是目的不同而已。如果正在设置地理处理服务,请使用生成服务区;这将会简化设置过程。否则,请使用创建服务区图层。同样地,如果需要生成服务区线,请使用创建服务区图层;生成服务区不提供生成线的选项。
如要使用生成服务区创建服务区地理处理服务,只需设置一个工具,然后便可直接将其发布为服务。与此相反,您需要使用创建服务区图层创建模型,将其正确连接到其他不同的工具,并发布此模型以创建服务区地理处理服务。请参阅地理处理服务示例:行驶时间面,了解如何使用教程数据设置行驶时间面服务。要考虑的另一个选项是 ArcGIS Online 生成服务区服务。该服务与 ArcMap 中地理处理工具的运行方式类似,可通过其他应用程序进行访问,并包含世界上大部分地区的高质量道路数据。
用法
语法
| 参数 | 说明 | 数据类型 | 
| in_network_dataset | 将在其中执行服务区分析的网络数据集。 | Network Dataset Layer | 
| out_network_analysis_layer | 要创建的服务区网络分析图层的名称。 | String | 
| impedance_attribute | 分析过程中用作阻抗的成本属性。 | String | 
| travel_from_to (可选) | 指定行至/离开设施点的方向。 
 使用此选项的结果是,在基于行驶方向的网络中,单向限制及不同行驶方向的阻抗差异会产生不同的服务区。例如,应该在远离设施点的方向上创建比萨外卖店的服务区,而医院的服务区应该创建在接近设施点的方向上。 | String | 
| default_break_values (可选) | 指示要计算的服务区范围的默认阻抗值。可通过对设施点指定中断值来覆盖默认值。 可以设置多个面中断来创建同心服务区。例如,要为同一设施点查找 2 分钟、3 分钟和 5 分钟服务区,请将“默认中断值”参数指定为“2 3 5”(2、3 和 5 这些数字之间应该以空格分隔)。 | String | 
| polygon_type (可选) | 指定要生成的面的类型。 
 如果是具有类似格网网络的市区数据,则概化面和详细面之间的差别最小。然而,对于山区道路和农村道路,详细面可能会呈现出比概化面更精确的结果。 | String | 
| merge (可选) | 指定用来合并共享相似中断值的面的选项。仅当为多个设施点生成面时,此选项才可用。 
 | String | 
| nesting_type (可选) | 指定该选项,将同心服务区面创建为圆盘或圆环。仅当为这些设施点指定多个中断值时,此选项才可用。 
 | String | 
| line_type (可选) | 指定基于服务区分析生成的线的类型。对于大型服务区,选择 TRUE_LINES 或 TRUE_LINES_WITH_MEASURES 选项将增大分析所占用的内存量。 
 | String | 
| overlap (可选) | 确定计算服务区线时是否生成重叠线。 
 | Boolean | 
| split (可选) | 
 | Boolean | 
| excluded_source_name [excluded_source_name,...] (可选) | 指定生成面时要排除的网络源的列表。所有面都将忽略排除的源中遍历元素的几何。 在生成面的过程中,如果需要排除某些会创建低精度的面或者对服务区分析无关紧要的网络源时,此选项十分有用。例如,在街道和铁路的多模式网络上创建行驶时间服务区时,应该在面生成过程中选择排除铁路线,这样才能准确地对车辆可以行驶的区域进行建模。 从服务区面中排除网络源并不会阻止这些源被遍历。只会影响该服务区面的形状。如果要阻止遍历一个给定的网络源,必须在定义网络数据集时创建适当的限制。 | String | 
| accumulate_attribute_name [accumulate_attribute_name,...] (可选) | 分析过程中要累积的成本属性的列表。这些累积属性仅供参考;求解程序仅使用阻抗属性参数所指定的成本属性来计算路径。 对于每个累积的成本属性,均会向求解程序所输出的路径中添加一个 Total_[阻抗] 属性。 | String | 
| UTurn_policy (可选) | 交汇点的 U 形转弯策略。允许 U 形转弯表示求解程序可以在交汇点处转向并沿同一街道往回行驶。 考虑到交汇点表示街道交叉路口和死角,不同的车辆可以在某些交汇点转弯,而在其他交汇点则不行 - 这取决于交汇点是交叉路口还是死角。为适应此情况,U 形转弯策略参数由连接到交汇点的边数隐性指定,这称为交汇点原子价。此参数可接受的值如下所列;每个值的后面是根据交汇点原子价对其含义的描述。 
  提示: 如果您需要定义更加精确的 U 形转弯策略,可以考虑在网络成本属性中添加一个通用转弯延迟赋值器,或者如果存在的话,调整其设置,并特别注意反向转弯的配置。还要考虑设置网络位置的 CurbApproach 属性。 | String | 
| restriction_attribute_name [restriction_attribute_name,...] (可选) | 分析过程中要应用的限制属性的列表。 | String | 
| polygon_trim (可选) | 
 | Boolean | 
| poly_trim_value (可选) | 指定对服务区面进行修剪的距离范围。该参数包括距离的值和单位。默认值是 100 米。 | Linear unit | 
| lines_source_fields (可选) | 
 | Boolean | 
| hierarchy (可选) | 
 如果未在用于执行分析的网络数据集中定义等级属性,该参数将不可用。在这种情况下,使用 "#" 作为参数值。 | Boolean | 
| time_of_day (可选) | 离开或到达服务区图层的设施点的时间。将此值理解为离开还是到达时间,取决于行驶方向是离开还是朝向设施点。 
 如果您已经选择了基于流量的阻抗属性,将会根据特定的某天某时的动态交通状况来生成解决方案。日期和时间可被指定为 5/14/2012 10:30 AM。 可使用以下日期来指定一周中的每一天,而无需使用特定的日期。 
 重复解决相同的分析问题,但使用不同的“时间”参数值,这样您就会看到设施点的到达时间随时间的变化。例如,消防站周围的五分钟服务区在大清早时可能变得大一点,而在早高峰期消失,上午晚些时候服务区又扩大,并在一天中都保持这样。 | Date | 
代码实例
仅使用必需参数执行此工具。
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.na.MakeServiceAreaLayer("Transportation/Streets_ND","FireStationCoverage",
                              "Minutes")
使用所有参数执行此工具。
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/Paris.gdb"
arcpy.na.MakeServiceAreaLayer("Transportation/ParisNet","WarehouseCoverage",
                              "Drivetime","TRAVEL_FROM","5 10 15", 
                              "SIMPLE_POLYS", "NO_OVERLAP","RINGS","TRUE_LINES",
                              "NON_OVERLAP","NO_SPLIT",
                              ["Metro_Lines","Transfer_Stations",
                               "Transfer_Street_Station"],
                              ["Meters","Drivetime"],"ALLOW_DEAD_ENDS_ONLY",
                              ["Oneway"],"NO_TRIM_POLYS","",
                              "LINES_SOURCE_FIELDS")
以下独立 Python 脚本演示了如何使用创建服务区图层 (MakeServiceAreaLayer) 工具在消防站周围生成 1 分钟、2 分钟和 3 分钟服务区。
# Name: MakeServiceAreaLayer_Workflow.py
# Description: Generate 1-,2-,3- minute service area around fire stations and
#              save the results to a layer file on disk. The service area
#              polygons can be used to visualize the areas that do not have
#              adequate coverage from the fire stations
# 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 = "FireStationCoverage"
    impedanceAttribute = "TravelTime"
    inFacilities = "Analysis/FireStations"
    outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr"
    #Create a new service area layer. We wish to generate the service area
    #polygons as rings, so that we can easily visualize the coverage for any
    #given location. We also want overlapping polygons as we can determine the
    #number of fire stations that cover a given location. We use hierarchy to
    #speed up the time taken to create the polygons. We will specify these
    #options while creating the new service area layer.
    outNALayer = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
                                  impedanceAttribute, "TRAVEL_FROM", "1 2 3",
                                  "SIMPLE_POLYS", "NO_MERGE", "RINGS",
                                  hierarchy = "USE_HIERARCHY")
    #Get the layer object from the result object. The service layer can now be
    #referenced using the layer object.
    outNALayer = outNALayer.getOutput(0)
    #Get the names of all the sublayers within the service area layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    facilitiesLayerName = subLayerNames["Facilities"]
    #Load the fire stations as facilities using default field mappings and
    #default search tolerance
    arcpy.na.AddLocations(outNALayer, facilitiesLayerName, inFacilities, "", "")
    #Solve the service area layer
    arcpy.na.Solve(outNALayer)
    #Save the solved service area 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)
本例展示了如何在一天的多个时间点内围绕设施点创建服务区,以及如何将字段从输入要素移到输出要素并将输出面追加到现有要素类中。
# Name: MakeServiceAreaLayer_Workflow2.py
# Description: Generate 3-minute service areas around fire stations at several
#               times of day to compare coverage differences due to varying
#               traffic conditions. Save the results to a feature class on disk.
# Requirements: Network Analyst Extension
import datetime
#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 = "FireStationCoverage"
    outSAFC = "Analysis/outSAPolys"
    impedanceAttribute = "TravelTime"
    inFacilities = "Analysis/FireStations"
    timelist = [datetime.datetime(2013, 8, 23, 7, 0, 0),
                datetime.datetime(2013, 8, 23, 12, 30, 0),
                datetime.datetime(2013, 8, 23, 17, 30, 0),
                datetime.datetime(2013, 8, 23, 21, 0, 0)]
    #Create a new service area layer.
    outSAResultObject = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
                                  impedanceAttribute, "TRAVEL_FROM", "3",
                                  "DETAILED_POLYS", "NO_MERGE",
                                  hierarchy = "NO_HIERARCHY")
    #Get the layer object from the result object. The service area layer can
    #now be referenced using the layer object.
    outNALayer = outSAResultObject.getOutput(0)
    #Get the names of all the sublayers within the service area layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Store the layer names that we will use later
    facilitiesLayerName = subLayerNames["Facilities"]
    polygonsLayerName = subLayerNames["SAPolygons"]
    #The input data has a field for FireStationID that we want to transfer to
    #our analysis layer. Add the field, and then use field mapping to transfer
    #the values.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, facilitiesLayerName,
                                                    "FireStationID", "TEXT")
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer,
                                                    facilitiesLayerName)
    fieldMappings["FireStationID"].mappedFieldName = "FireStationID"
    #Load the fire stations as facilities.
    arcpy.na.AddLocations(outNALayer, facilitiesLayerName, inFacilities,
                            fieldMappings, "",
                            exclude_restricted_elements = "EXCLUDE")
    #Get sublayers we will want to work with later
    FacilitiesSubLayer = arcpy.mapping.ListLayers(outNALayer,
                                                    facilitiesLayerName)[0]
    PolygonsSubLayer = arcpy.mapping.ListLayers(outNALayer,
                                                    polygonsLayerName)[0]
    # Add fields to the output Polygons sublayer. We will fill the values later.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, polygonsLayerName,
                                        "FireStationID", "TEXT")
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, polygonsLayerName,
                                        "TimeOfDay", "TEXT")
    #Get the Service Area Layer's solver properties. This will allow us to
    #set individual properties later without re-creating the layer.
    SA_SolverProperties = arcpy.na.GetSolverProperties(outNALayer)
    #Solve the Service Area for each time of day in our time list
    for t in timelist:
        print "Now solving for time of day: " + t
        #Use the solver properties to set the time of day for the solve
        SA_SolverProperties.timeOfDay = t
        #Solve the service area layer
        arcpy.na.Solve(outNALayer)
        #Transfer the FireStationID field from the input Facilities to the
        #output Polygons
        arcpy.management.AddJoin(PolygonsSubLayer, "FacilityID",
                                        FacilitiesSubLayer, "ObjectID")
        arcpy.management.CalculateField(PolygonsSubLayer, "FireStationID",
                                        "!Facilities.FireStationID!", "PYTHON")
        arcpy.management.RemoveJoin(PolygonsSubLayer)
        #Populate the TimeOfDay field
        expression = '"' + t + '"'
        arcpy.management.CalculateField(PolygonsSubLayer, "TimeOfDay",
                                            expression, "PYTHON")
        #Append the polygons to the output feature class. If this was the first
        #solve, create the feature class.
        if not arcpy.Exists(outSAFC):
            arcpy.management.CopyFeatures(PolygonsSubLayer, outSAFC)
        else:
            arcpy.management.Append(PolygonsSubLayer, outSAFC)
    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)