使用方法
语法
arcpy.na.MakeServiceAreaLayer(in_network_dataset, out_network_analysis_layer, impedance_attribute, {travel_from_to}, {default_break_values}, {polygon_type}, {merge}, {nesting_type}, {line_type}, {overlap}, {split}, {excluded_source_name}, {accumulate_attribute_name}, {UTurn_policy}, {restriction_attribute_name}, {polygon_trim}, {poly_trim_value}, {lines_source_fields}, {hierarchy}, {time_of_day})
参数 | 说明 | 数据类型 |
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。 可使用以下日期来指定一周中的每一天,而无需使用特定的日期:
重复解决相同的分析问题,但使用不同的“时间”参数值,这样您就会看到设施点的到达时间随时间的变化。例如,消防站周围的 5 分钟服务区在大清早时可能变得大一点,而在早高峰期消失,上午晚些时候服务区又扩大,并在一天中都保持这样。 | Date |
派生输出
名称 | 说明 | 数据类型 |
output_layer | 新创建的网络分析图层。 | 网络分析图层 |
代码示例
仅使用必需参数执行此工具。
network = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
arcpy.na.MakeServiceAreaLayer(network, "FireStationCoverage", "TravelTime")
使用所有参数执行此工具。
network = "C:/Data/Paris.gdb/Transportation/ParisMultimodal_ND"
arcpy.na.MakeServiceAreaLayer(network, "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 areas 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
import os
try:
#Set environment settings
output_dir = "C:/Data"
#The NA layer's data will be saved to the workspace specified here
env.workspace = os.path.join(output_dir, "Output.gdb")
env.overwriteOutput = True
#Set local variables
input_gdb = "C:/Data/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
layer_name = "FireStationCoverage"
impedance = "TravelTime"
facilities = os.path.join(input_gdb, "Analysis", "FireStations")
output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")
#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.
result_object = arcpy.na.MakeServiceAreaLayer(network, layer_name,
impedance, "TRAVEL_FROM", "1 2 3",
"DETAILED_POLYS", "NO_MERGE", "RINGS")
#Get the layer object from the result object. The service layer can now be
#referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
#Load the fire stations as facilities using default field mappings and
#default search tolerance
arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities, "",
"")
#Solve the service area layer
arcpy.na.Solve(layer_object)
#Save the solved service area layer as a layer file on disk
layer_object.saveACopy(output_layer_file)
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)))
本例展示了如何在一天的多个时间点内围绕设施点创建服务区,以及如何将字段从输入要素移到输出要素并将输出面追加到现有要素类中。
# 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 system modules
import arcpy
from arcpy import env
import os, datetime
try:
#Set environment settings
output_dir = "C:/Data"
#The NA layer's data will be saved to the workspace specified here
env.workspace = os.path.join(output_dir, "Output.gdb")
env.overwriteOutput = True
#Set local variables
input_gdb = "C:/Data/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
layer_name = "FireStationCoverage"
out_featureclass = os.path.join(output_dir, "Output.gdb",
"FireStationCoverage")
impedance = "TravelTime"
facilities = os.path.join(input_gdb, "Analysis", "FireStations")
times_of_day = [datetime.datetime(2014, 9, 25, 7, 0, 0),
datetime.datetime(2014, 9, 25, 12, 30, 0),
datetime.datetime(2014, 9, 25, 17, 30, 0),
datetime.datetime(2014, 9, 25, 21, 0, 0)]
#Create a new service area layer.
result_object = arcpy.na.MakeServiceAreaLayer(network, layer_name,
impedance, "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.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
polygons_layer_name = sublayer_names["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(layer_object, facilities_layer_name,
"FireStationID", "TEXT")
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
facilities_layer_name)
field_mappings["FireStationID"].mappedFieldName = "FireStationID"
#Load the fire stations as facilities.
arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities,
field_mappings, "",
exclude_restricted_elements = "EXCLUDE")
# Add fields to the output Polygons sublayer for later use.
arcpy.na.AddFieldToAnalysisLayer(layer_object, polygons_layer_name,
"FireStationID", "TEXT")
arcpy.na.AddFieldToAnalysisLayer(layer_object, polygons_layer_name,
"TimeOfDay", "TEXT")
#Get sublayers to work with later
facilities_sublayer = layer_object.listLayers(facilities_layer_name)[0]
polygons_sublayer = layer_object.listLayers(polygons_layer_name)[0]
#Get the Service Area Layer's solver properties. This can be used to
#set individual properties later without re-creating the layer.
solver_properties = arcpy.na.GetSolverProperties(layer_object)
#Solve the Service Area for each time of day in the time list
for t in times_of_day:
print("Calculating service area for time of day: ", t)
#Use the solver properties to set the time of day for the solve
solver_properties.timeOfDay = t
#Solve the service area layer
arcpy.na.Solve(layer_object)
#Transfer the FireStationID field from the input Facilities to the
#output Polygons
arcpy.management.AddJoin(polygons_sublayer, "FacilityID",
facilities_sublayer, "ObjectID")
#The joined fields are qualified by the feature class name of the joined
#table, so determine the feature class names
field_qualifier_pol = os.path.basename(polygons_sublayer.dataSource)
target_field_name = "%s.FireStationID" % field_qualifier_pol
field_qualifier_fac = os.path.basename(facilities_sublayer.dataSource)
expression = "!%s.FireStationID!" % field_qualifier_fac
arcpy.management.CalculateField(polygons_sublayer, target_field_name,
expression, "PYTHON")
arcpy.management.RemoveJoin(polygons_sublayer)
#Populate the TimeOfDay field in the output feature class
expression = '"' + str(t) + '"'
arcpy.management.CalculateField(polygons_sublayer, "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(out_featureclass):
arcpy.management.CopyFeatures(polygons_sublayer, out_featureclass)
else:
arcpy.management.Append(polygons_sublayer, out_featureclass)
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))
环境
许可信息
- Basic: 是
- Standard: 是
- Advanced: 是