WasteCollection
汇总
此 ArcPy 类用于废弃物收集路径规划。
讨论
可通过废弃物收集分析优化城市的废弃物收集工作。 此分析可用于为从同一位置出发并在一天内服务于一个地区的车队规划路径。
语法
WasteCollection(in_network)
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
in_network |
将用于网络分析的网络数据集。 可以使用以下方法之一指定该参数:
网络必须至少具有一个出行模式、一个具有时间单位的成本属性和一个具有距离单位的成本属性。 |
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
allowAutoRelocate (读取和写入) |
指定是否可以在求解时自动重定位具有现有网络位置字段的输入,以确保分析的位置字段有效并且可路由。 如果值为 即使值为 默认值为 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 如果网络数据源是 ArcGIS Online、不支持使用网络位置字段的 ArcGIS Enterprise 门户或运行版本低于 11.0 的 ArcGIS Enterprise 的门户,则设置此属性会返回错误。 |
Boolean |
|
directionsLanguage (读取和写入) |
将显示输出转弯方向文本的语言。 返回该属性并将表示受支持方向语言的两个或五个字符的语言代码之一设置为字符串。 可从 |
String |
|
distanceUnits (读取和写入) |
报告分析输出中的行驶距离时要使用的单位。 无论网络数据集中成本属性的单位如何,输出都将转换为此属性中设置的单位并以该单位进行报告。 将返回该属性并将其设置为 注意:当分析使用服务作为其网络数据源时, |
Object |
|
maxRouteTotalTime (读取和写入) |
每条路径允许的最大总时间。 值可为任意正数。 值用于 值以 |
Double |
|
networkDataSource (只读) |
网络数据集的完整目录路径或用于分析的服务的 URL。 |
String |
|
overrides (读取和写入) |
注:此属性仅限内部使用。 |
String |
|
routeStartTime (读取和写入) |
默认的路径开始时间。 此时间用于 使用此属性的 |
DateTime |
|
searchSources (读取和写入) |
当在网络中定位输入时,此属性指定要使用的网络源列表和(可选)查询以将搜索限制为源要素类内的一部分要素。 默认值位于所有网络边源上,而不是网络交汇点源上。 默认情况下,不对任何源使用查询。 注意:如果任何停靠点位于交汇点,则求解操作将失败。 该属性值被指定为具有嵌套列表的列表,每个网络源最多具有一个条目。 每个内部列表由两个值组成,分别表示网络源的名称和用作该源的查询的 SQL 表达式。 网络源组件的可能值为参与网络的边源和交汇点源的字符串要素类名称。 列表中的源将用于定位,而不在列表中的源将不会用于定位。 查询在不想查找可能不适合网络位置的要素时很有用。 例如,如果您不想定位在高速公路坡道上,则可定义一个查询将其排除。 对于查询组件,请参阅 在 ArcGIS 中使用的查询表达式的 SQL 参考 获取正确表达式。 空字符串 例如,值 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 |
String |
|
searchTolerance (读取和写入) |
在网络上定位输入要素将使用的最大搜索距离。 返回该属性并将其设置为双精度,然后通过 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 |
Double |
|
searchToleranceUnits (读取和写入) |
指定 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 |
Object |
|
stopCollectionMode (读取和写入) |
每个停靠点的默认停靠点收集模式。 将返回该属性并将其设置为 值用于 |
Object |
|
timeUnits (读取和写入) |
指定报告分析输出中的行驶时间时要使用的单位。 无论网络数据集中成本属性的单位如何,输出都将转换为使用在此属性中设置的单位并以该单位进行报告。 将返回该属性并将其设置为 |
Object |
|
travelMode (读取和写入) |
要用于分析的出行模式。 出行模式的阻抗属性必须具有时间单位。 对于废弃物收集分析,必须在死胡同处允许调头。 如果出行模式不允许调头,则求解程序将放宽出行模式的调头策略以允许在死胡同处调头。 选择合适的出行模式对于生成良好的废弃物收集分析结果尤为重要,因为垃圾车通常行驶在私人车辆不允许通行的街道上,例如私家路、禁止通行的街道和需要通过上锁的大门进入的道路。 将返回该值并将其设置为 |
Object |
方法
addFields(input_type, field_description[field_description,...])
将自定义字段添加到指定的输入类。 这些字段将包含在通过 fieldMappings 方法创建的字段映射字典中,也可与 insertCursor 方法配合使用。
| 名称 | 说明 | 数据类型 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
input_type |
The type of input to which the fields will be added. 使用 |
Object |
||||||||||||||||||||||||
|
field_description[field_description,...] |
The fields and their properties that will be added to the input class. The value will be constructed as a list of lists with each row containing the following items:
Available field types are as follows:
Only the field name and type are required. Use None as a place holder for any of the other parameters to accept the default or if the parameter does not apply to the specified field type. The method will return an error if the field already exists in the table or if any of the field properties are invalid. |
TEXT |
count(input_type)
返回为输入类型添加的行数。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
用于计数的输入要素类型。 使用 |
Object |
返回值
| 数据类型 | 说明 |
|---|---|
|
Integer |
行数。 |
fieldMappings(input_type, {use_location_fields}, {list_candidate_fields[list_candidate_fields,...]})
生成将输入类型的字段名称映射到 arcpy.nax.NAClassFieldMap 对象的 NAClassFieldMappings 字典,以允许您将字段从输入数据映射到求解程序属性。 字典可用作 load 方法的 field_mappings 参数的输入。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input for which the field mappings will be returned. 使用 |
Object |
|
use_location_fields (可选) |
Specifies whether network location fields will be included in the returned field mappings dictionary. Network location fields describe the point on the network where an object is located. You can use network location fields to more precisely control how analysis inputs locate on the network and to save time when calling the Learn more about network location fields and how inputs are located on the network When this argument is set to (默认值为 False) |
Boolean |
|
list_candidate_fields[list_candidate_fields,...] (可选) |
Use this parameter to map additional, nondefault fields from the input data to the analysis inputs. For example, if the input feature class contains a field named Specify this parameter as a list of Learn more about best practices for setting up analysis inputs 旧版本:If the network data source is an ArcGIS Enterprise portal, the method will return an error if any of the fields specified are of a type that is not supported by the portal version. (默认值为 None) |
Field |
返回值
| 数据类型 | 说明 |
|---|---|
|
Dictionary |
|
fieldNames(input_type, {use_location_fields})
获取指定输入类型支持的字段名称列表。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
返回其支持的字段名称的输入类型。 使用 |
Object |
|
use_location_fields (可选) |
指示网络位置字段是否包含在返回的字段名称列表中。网络位置字段可描述网络中对象所在的点。您可以使用网络位置字段更精确地控制分析输入在网络上的定位方式,并且由于求解程序不必从输入的几何计算位置字段,因此在调用 当此参数设置为 (默认值为 False) |
Boolean |
返回值
| 数据类型 | 说明 |
|---|---|
|
String |
指定输入类型支持的字段名称列表。 |
insertCursor(input_type, field_names[field_names,...], {append})
在指定的输入类型上建立写入光标。 此游标可用于将行直接添加到输入。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input into which the cursor can be used to insert rows. 使用 |
Object |
|
field_names[field_names,...] |
A list of field names of the input type whose values you want to set when inserting rows using the cursor. You can get the names of the fields supported by an input type using the Learn more about the fields available for each input type In addition to regular fields, you can also set the geometry of the input using one of the following geometry tokens:
The |
String |
|
append (可选) |
Specifies whether the features being inserted will be appended to the existing set of features for the input type. A value of (默认值为 True) |
Boolean |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
可用于写入要素的 |
load(input_type, features, {field_mappings}, {append}, {max_features})
设置用于分析的输入要素。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input feature that will be loaded. 使用 |
Object |
|
features |
The input features that will be loaded. This parameter accepts the following input types:
For layer inputs, only selected features will be loaded. If a layer has a definition query, only the subset of features visible with the definition query will be loaded. The method also honors the Extent geoprocessing environment; only features in the specified extent will be loaded. |
String |
|
field_mappings (可选) |
An If no field mappings are specified, all fields from the input features that have the same name as the supported fields for the input type will be mapped. Learn more about the fields available for each input type (默认值为 None) |
Dictionary |
|
append (可选) |
Specifies whether the features being loaded will be appended to the existing set of features for the input type. A value of (默认值为 True) |
Boolean |
|
max_features (可选) |
The maximum number of features that can be loaded into the input type. This is useful if you are creating a tool or service and want an error returned if the size of the input exceeds the available resources. The If no value is provided, no limit will be enforced for the count of the input features. (默认值为 None) |
Integer |
setLocateSettingsOverrides(input_type, {search_sources[[Source, Expression],...]}, {allow_auto_relocate}, {search_tolerance}, {search_tolerance_units})
为指定输入类设置定位设置,并覆盖为分析指定的默认定位设置。 如果想要使用不同的规则定位不同的输入,这非常有用。 例如,在 OD 成本矩阵分析中,如果搜索查询不需要应用于输入目标和障碍,则可以使用仅应用于输入源的搜索查询。
可使用此方法覆盖指定输入类的 searchSources 、 allowAutoRelocate 、 searchTolerance 和 searchToleranceUnits 属性值。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input for which to override default locate settings. 使用 |
Object |
|
search_sources[[Source, Expression],...] (可选) |
The list of network sources to be used when locating inputs of the designated type on the network, and, optionally, a query to restrict the search to a subset of the features within a source feature class. See the documentation for the Specifying a value for this parameter overrides the default If this parameter is not specified or is set to 注意:The solve will fail if any stops are located on junctions. |
String |
|
allow_auto_relocate (可选) |
Specifies whether inputs of the designated type with existing network location fields can be automatically relocated at solve time to ensure valid, routable location fields for the analysis. If the value is Even if the value is Specifying a value for this parameter overrides the default If this parameter is not specified or is set to The method returns an error if the network data source is ArcGIS Online. The method returns an error if the network data source is an ArcGIS Enterprise portal that does not support using network location fields. |
Boolean |
|
search_tolerance (可选) |
The maximum search distance to use when locating inputs of the designated type on the network. Specifying a value for this parameter overrides the default If this parameter is not specified or is set to The units of this parameter value are set using the This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the |
Double |
|
search_tolerance_units (可选) |
The units of the maximum search distance when locating inputs of the designated type of the network. The parameter is specified using a member of the Specifying a value for this parameter overrides the default If this parameter is not specified or is set to The value specified using the This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the |
Double |
solve()
使用在 WasteCollection 对象上设置的属性和已加载的输入执行废弃物收集分析。
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
|
代码示例
使用要素类和表中的输入执行废弃物收集分析。
# An example showing how to perform waste collection analysis using inputs
# from feature classes and tables.
import datetime
import arcpy
# Define inputs
nds = "C:/data/MyCity.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_stops = "C:/data/io.gdb/BinLocations"
input_depots = "C:/data/io.gdb/Depots"
input_routes = "C:/data/io.gdb/Trucks"
input_renewals = "C:/data/io.gdb/Landfill"
input_route_renewals = "C:/data/io.gdb/RouteRenewals"
# Define outputs
output_stops = "C:/data/io.gdb/OutputBins"
output_routes = "C:/data/io.gdb/OutputTrucks"
# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
# travel_mode = nd_travel_modes["Garbage Truck Time"]
travel_mode = nd_travel_modes["Driving Time"]
# Instantiate a WasteCollection solver object
waste_collection = arcpy.nax.WasteCollection(nd_layer_name)
# Set properties
waste_collection.travelMode = travel_mode
waste_collection.stopCollectionMode = arcpy.nax.StopCollectionMode.OneSide
waste_collection.routeStartTime = datetime.time(6, 0, 0)
waste_collection.timeUnits = arcpy.nax.TimeUnits.Hours
waste_collection.maxRouteTotalTime = 6 # hours
# Load inputs
waste_collection.load(arcpy.nax.WasteCollectionInputDataType.Stops, input_stops)
waste_collection.load(arcpy.nax.WasteCollectionInputDataType.Depots, input_depots)
waste_collection.load(arcpy.nax.WasteCollectionInputDataType.Routes, input_routes)
waste_collection.load(arcpy.nax.WasteCollectionInputDataType.Renewals, input_renewals)
waste_collection.load(arcpy.nax.WasteCollectionInputDataType.RouteRenewals, input_route_renewals)
# Solve the analysis
result = waste_collection.solve()
# Export the results to feature classes
if result.solveSucceeded:
result.export(arcpy.nax.WasteCollectionOutputDataType.Stops, output_stops)
result.export(arcpy.nax.WasteCollectionOutputDataType.Routes, output_routes)
else:
print("Solve failed")
print(result.solverMessages(arcpy.nax.MessageSeverity.All))