描述
用于创建车辆配送 (VRP) 网络分析图层并设置其分析属性。VRP 分析图层可用于在使用一支车队时对一组路径进行优化。该图层可通过本地网络数据集进行创建,也可通过在线托管服务或门户托管服务进行创建。
创建车辆配送分析图层和求解车辆配送工具类似,只是目的不同而已。如果您要设置地理处理服务,请使用求解车辆配题工具;该工具将简化设置过程。否则,请使用创建车辆配送分析图层工具。
使用方法
语法
MakeVehicleRoutingProblemAnalysisLayer(network_data_source, {layer_name}, {travel_mode}, {time_units}, {distance_units}, {default_date}, {time_zone_for_time_fields}, {line_shape}, {time_window_factor}, {excess_transit_factor}, {generate_directions_on_solve}, {spatial_clustering})
参数 | 说明 | 数据类型 |
network_data_source | 将对其执行网络分析的网络数据集或服务。将门户 URL 用于服务。 | Network Dataset Layer; String |
layer_name (可选) | 要创建的车辆配送网络分析图层的名称。 | String |
travel_mode (可选) | 分析中使用的出行模式名称。出行模式为一组网络设置(例如行驶限制和 U 形转弯),用于确定行人、车辆、卡车或其他交通媒介在网络中的移动方式。出行模式在网络数据源中进行定义。arcpy.na.TravelMode 对象和包含出行模式有效 JSON 表示的字符串也可用作参数的输入。 | String |
time_units (可选) | 用于指定分析图层的子图层和表(网络分析类)的时态字段所用的时间单位。该值不必与时间成本属性的单位相匹配。
| String |
distance_units (可选) | 用于指定分析图层的子图层和表(网络分析类)的距离字段所用的距离单位。该值不必与可选距离成本属性的单位相匹配。
| String |
default_date (可选) | 未用时间指定日期的时间字段值的隐式日期。如果某个停靠点对象的时间字段(如 TimeWindowStart1)只有时间值,则假定该日期为默认日期。默认日期不影响已具有日期的时间字段值。 | Date |
time_zone_for_time_fields (可选) | 为工具支持的输入日期时间字段指定时区。
如果不知道停靠点或站点所在的时区,或者停靠点或站点处在多个时区内并且您想要所有的日期时间值同时启动,那么在 UTC 中指定日期时间值非常有用。UTC 选项仅在您的网络数据集定义了时区属性时才可用。否则,所有日期时间值将始终被视为与该位置相对应的时区。 | String |
line_shape (可选) | 为分析所输出的路径要素指定形状类型。
无论选择何种输出形状类型,最佳路径始终由网络阻抗(而非欧氏距离)决定。这表示只是路径形状不同,而对网络进行的基础遍历则相同。 | String |
time_window_factor (可选) | 用于指定支持时间窗且不引起冲突的重要性。如果路径在时间窗关闭后才到达停靠点、站点或休息点,将会产生时间窗冲突。该冲突是时间窗关闭与路径到达时间之间的时间间隔。
| String |
excess_transit_factor (可选) | 指定减少额外行驶时间的重要性。额外行驶时间是指超出停靠点对间直线行驶所需时间的数量。额外时间是由于在需求点对的访问期间进行休息或者行驶至其他停靠点或站点而导致的。仅当您使用停靠点对时,此参数才相关。
| String |
generate_directions_on_solve (可选) | 指定是否将生成方向。
| Boolean |
spatial_clustering (可选) | 指定是否使用空间聚类。
| Boolean |
派生输出
名称 | 说明 | 数据类型 |
out_network_analysis_layer | 新建网络分析图层。 | 网络分析图层 |
代码示例
仅使用必需参数执行此工具。
import arcpy
arcpy.env.workspace = "C:/Data/SanFrancisco.gdb"
arcpy.na.MakeVehicleRoutingProblemLayer("Transportation/Streets_ND")
使用所有参数执行此工具。
import arcpy
arcpy.env.workspace = "C:/Data/SanFrancisco.gdb"
arcpy.na.MakeVehicleRoutingProblemAnalysisLayer('Streets_ND', 'FridayRoutes',
'Driving Time', 'Minutes',
'Miles', '1/2/2020',
'LOCAL_TIME_AT_LOCATIONS',
'TRUE_LINES_WITHOUT_MEASURES',
'High', 'Medium', 'DIRECTIONS')
以下独立 Python 脚本演示了如何使用 MakeVehicleRoutingProblemAnalysisLayer 工具通过一支车队为一组停靠点提供服务。
# Name: MakeVehicleRoutingProblemLayer_Workflow.py
# Description: Find the best routes for a fleet of vehicles, which is operated
# by a distribution company, to deliver goods from a main
# distribution center to a set of grocery stores.
# Requirements: Network Analyst Extension
# Import system modules
import arcpy
from arcpy import env
import os
try:
# Check out the Network Analyst license if available.
# Fail if the Network Analyst
# license is not available.
if arcpy.CheckExtension("network") == "Available":
arcpy.CheckOutExtension("network")
else:
raise arcpy.ExecuteError("Network Analyst Extension license is not available.")
# 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 = "StoreDeliveryRoute"
travel_mode = "Driving Time"
time_units = "Minutes"
distance_units = "Miles"
in_orders = os.path.join(input_gdb, "Analysis/Stores")
in_depots = os.path.join(input_gdb, "Analysis/DistributionCenter")
in_routes = os.path.join(input_gdb, "Analysis/Routes")
output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")
# Create a new Vehicle Routing Problem (VRP) layer. Since the time-based
# attributes such as ServiceTime on orders and CostPerUnitTime on routes is
# recorded in minutes, we use minutes for time_units parameter. As we are
# using cost per unit distance in routes, we have to specify a distance
# attribute. The values for CosterPerUnitDistance are in miles, so we
# specify miles for distance units parameter
result_object = arcpy.na.MakeVehicleRoutingProblemAnalysisLayer(network,
layer_name, travel_mode,
time_units, distance_units,
line_shape="STRAIGHT_LINES")
# Get the layer object form the result object. The route layer can now be
# referenced using the layer object.
layer_object = result_object.getOutput(0)
# Get the names of all the sublayers within the VRP layer.
sub_layer_names = arcpy.na.GetNAClassNames(layer_object)
# Store the layer names that we will use later
orders_layer_name = sub_layer_names["Orders"]
depots_layer_name = sub_layer_names["Depots"]
routes_layer_name = sub_layer_names["Routes"]
# Load the store locations as orders. Using field mappings we map the
# TimeWindowStart1, TimeWindowEnd1, and DeliveryQuantities properties
# for Orders from the fields of store features and assign a value of
# 0 to MaxViolationTime1 property. The Name and ServiceTime properties
# have the correct mapped field names when using the candidate fields
# from store locations feature class.
candidate_fields = arcpy.ListFields(in_orders)
order_field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
orders_layer_name,
False, candidate_fields)
order_field_mappings["TimeWindowStart1"].mappedFieldName = "TimeStart1"
order_field_mappings["TimeWindowEnd1"].mappedFieldName = "TimeEnd1"
order_field_mappings["DeliveryQuantities"].mappedFieldName = "Demand"
order_field_mappings["MaxViolationTime1"].defaultValue = 0
arcpy.na.AddLocations(layer_object, orders_layer_name, in_orders,
order_field_mappings, "")
# Load the depots from the distribution center features. Using field mappings
# we map the Name properties for Depots from the fields of distribution
# center features and assign a value of 8 AM for TimeWindowStart1 and a
# value of 5 PM for TimeWindowEnd1 properties
depot_field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
depots_layer_name)
depot_field_mappings["Name"].mappedFieldName = "Name"
depot_field_mappings["TimeWindowStart1"].defaultValue = "8 AM"
depot_field_mappings["TimeWindowEnd1"].defaultValue = "5 PM"
arcpy.na.AddLocations(layer_object, depots_layer_name, in_depots,
depot_field_mappings, "")
# Load the routes from a table containing information about routes. In this
# case, since the fields on the routes table and property names for Routes
# are the same, we will just use the default field mappings
arcpy.na.AddLocations(layer_object, routes_layer_name, in_routes, "", "")
# Solve the VRP layer
arcpy.na.Solve(layer_object)
# Save the solved VRP layer as a layer file on disk with relative paths
arcpy.management.SaveToLayerFile(layer_object, output_layer_file, "RELATIVE")
print ("Script Completed Successfully")
except Exception as e:
# If an error occurred, print line number and error message
import traceback
import sys
tb = sys.exc_info()[2]
print ("An error occurred on line %i" % tb.tb_lineno)
print (str(e))
环境
许可信息
- Basic: 是
- Standard: 是
- Advanced: 是