添加位置 (网络分析)

摘要

向网络分析图层添加网络分析对象。向特定子图层(如“停靠点”图层和“障碍”图层)添加对象。对象将作为要素或记录输入。

用法

语法

AddLocations_na (in_network_analysis_layer, sub_layer, in_table, field_mappings, search_tolerance, {sort_field}, {search_criteria}, {match_type}, {append}, {snap_to_position_along_network}, {snap_offset}, {exclude_restricted_elements}, {search_query})
参数说明数据类型
in_network_analysis_layer

要添加网络分析对象的网络分析图层。

Network Analyst Layer
sub_layer

要添加网络分析对象的网络分析图层的子图层。

String
in_table

充当新网络分析对象的源的要素类或表。

Table View
field_mappings

Sets the values for the properties of the network analysis objects. Properties can be set to a constant or mapped to a field from the input feature class or table.

参数值被指定为一个由分号分开的,含有三个值且由属性名、字段名和默认值组成的列表。您应该指定属性的字段名或默认值。例如,参数值 "Name Address #; Attr_Minutes # 2" 指定出“名称”属性从“地址”字段映射且 Attr_Minutes 属性在添加输入要素时应该具有常量值 2。

如果某个特定属性没有映射到字段中或具有默认值或没有包含在参数值中,那么该属性将进行默认映射。如果想对所有属性使用默认映射,请将 # 用于参数值。

If both the Field and the Default Value are not specified for a property, the resulting network analysis objects will have null values for that property.

如果正在加载的数据含有基于用于分析的网络数据集的网络位置或位置范围,请将网络位置字段从输入要素映射到网络位置属性。对于点位置(如停靠点或事件点),映射 SourceID、SourceOID、PosAlong 和 SideOfEdge 属性;对于线位置或面位置(如面障碍),映射“位置”属性。使用网络位置字段来添加网络分析对象比按照几何加载网络分析对象快得多。在字段映射中指定网络位置字段与使用工具对话框中的使用网络位置字段代替几何参数相类似。

警告警告:

如果为其中的任意一个网络位置属性指定字段映射,您需要为其余的网络位置属性指定字段映射,以避免工具执行错误。

Network Analyst Field Map
search_tolerance

The search tolerance for locating the input features on the network. Features that are outside the search tolerance are left unlocated. The parameter includes a value and units for the tolerance.

将位置添加到线障碍或面障碍子图层时,不使用该参数。在这种情况下,使用 "#" 作为参数值。

Linear Unit
sort_field
(可选)

当网络分析对象被添加到网络分析图层时存储网络分析对象的字段。默认设置为输入要素类或表中的 ObjectID 字段。

Field
search_criteria
[[Source, SnapType],...]
(可选)

Specifies which sources in the network dataset will be searched when finding locations and what portions of geometry (also known as snap types) will be used.

该参数值被指定为具有嵌套列表的列表。嵌套列表由两个值组成,分别表示每个网络源的名称和捕捉类型。捕捉类型通过关键字“SHAPE”、“MIDDLE”、“END”或“NONE”来指定。例如,查找位置时,参数值 [["Streets","SHAPE"],["Streets_ND_Junctions","NONE"]] 指定搜索可定位于 Streets 源的形状,而不可定位于 Streets_ND_Junctions 源。

要为单一网络源指定多个捕捉类型,请使用捕捉类型关键字的组合形式,用下划线将关键字分开。例如,MIDDLE_END 指定位置可以捕捉到网络源的中部或末尾。

When adding line or polygon network locations, only the Shape snap type is used even if other snap types are specified.

Value Table
match_type
(可选)
  • MATCH_TO_CLOSEST将新网络位置与所有已在搜索条件中指定捕捉类型的源中的最近的网络源匹配。这是默认设置。
  • PRIORITY将新网络位置与第一个在搜索条件中指定捕捉类型的网络源匹配。这些源按照优先级顺序进行搜索;当在搜索容差内找到位置时,搜索停止。

The parameter is not used when adding locations to the Line Barriers or Polygon Barriers sublayers. In such cases, use "#" as the parameter value.

Boolean
append
(可选)

Specifies whether or not to append new network analysis objects to existing objects.

  • APPEND将新网络分析对象追加到所选子图层中的现有对象集中。
  • CLEAR将删除现有的网络分析对象并使用新的对象来代替。
Boolean
snap_to_position_along_network
(可选)

Specifies that you want to snap the network locations along the network dataset or at some specified offset from the network dataset.

  • NO_SNAP 网络位置的几何将基于输入要素的几何。如果想使用要求清楚网络位置处于边的哪一侧的路边通道,这一点将非常有用。
  • SNAP 如果具有点要素,则点将被捕捉到网络,您将无法使用路边通道。如果您不关心车辆如何接近车站,这一点将很有用。如果输入要素是线或面,请使用此参数值。

The parameter is not used when adding locations to the Line Barriers or Polygon Barriers sublayers. In such cases, use "#" as the parameter value.

Boolean
snap_offset
(可选)

When snapping a point to the network, you can apply an offset distance. An offset distance of zero means the point will be coincident with the network feature (typically a line). To offset the point from the network feature, enter an offset distance. The offset is in relation to the original point location. That is, if the original point was on the left side, its new location will be offset to the left. If it was originally on the right side, its new location will be offset to the right.

The parameter is not used when adding locations to the Line Barriers or Polygon Barriers sublayers. In such cases, use "#" as the parameter value.

Long
exclude_restricted_elements
(可选)
  • EXCLUDE指定将网络位置仅放置在网络的可遍历部分。这样可防止将网络位置放在因限制或障碍而无法到达的元素上。通过该选项添加网络位置之前,请确保已经向输入网络分析图层添加了所有限制障碍以得到预期结果。添加障碍对象时,此参数不适用。在这种情况下,使用 "#" 作为参数值。
  • INCLUDE指定将网络位置放置在网络的所有元素上。如果通过该选项添加的网络位置被放置在受限元素上,那么在求解过程中,可能无法到达这些网络位置。
Boolean
search_query
[[Source, Expression],...]
(可选)

Specifies a query to restrict the search to a subset of the features within a source feature class. This is useful if you don't want to find features that may be unsuited for a network location. For example, if you are loading centroids of polygons and don't want to locate on local roads, you can define a query that searches for major roads only.

该参数值被指定为具有嵌套列表的列表。嵌套列表由两个值组成,分别表示所有网络源的名称和 SQL 表达式。对于不同的网络源要素类类型,SQL 表达式的语法略有不同。例如,如果要查询存储在文件或 ArcSDE 地理数据库中的源要素类、shapefile 或 SDC,需将字段名用双引号括起:"CFCC"。如果要查询存储在个人地理数据库中的源要素类,需将字段用方括号括起:[CFCC]

如果您不想指定特定源的查询,请使用 "#" 作为 SQL 表达式的值,或者将源名称和 SQL 表达式从参数值中排除。如果您不想指定所有网络源的查询,请使用 "#" 作为参数值。

例如,参数值 [["Streets","\"CFCC\" = 'A15'"], ["Streets_ND_Junctions",""]] 指定了 Streets 源要素类的 SQL 表达式,而没有指定 Streets_ND_Junctions 源要素类的表达式。注意:用于括字段名 CFCC 的双引号通过反斜杠字符进行转义,以避免 Python 解释程序出现分析错误。

Value Table

代码示例

AddLocations 示例 1(Python 窗口)

仅使用必需参数执行此工具

import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.AddLocations_na("Route","Stops","Analysis/Hospital","","")
AddLocations 示例 2(Python 窗口)

使用所有参数执行此工具

import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.AddLocations_na("Route","Stops","Analysis/Hospital",
                      "Name Name #;Attr_Minutes VisitTime 0;CurbApproach # 0",
                      "2 Miles","FID",
                      [["Streets","SHAPE"],["Streets_ND_Junctions","NONE"]],
                      "MATCH_TO_CLOSEST","CLEAR","SNAP","10 Feet","EXCLUDE",
                      [["Streets",'"FREEWAY" = 0'],["Streets_ND_Junctions",""]])


AddLocations 示例 3(工作流)

下述独立 Python 脚本演示了如何使用 AddLocations 工具将原点和目标加载到 OD 成本矩阵图层中。

# Name: AddLocations_Workflow.py
# Description: The scenario shows how to calculate a travel time matrix between 
#              store features. Use the Add Locations tool to load origins and 
#              destinations into an OD Cost Matrix layer.Since the origins and 
#              destinations are same in this case, the origins are first loaded 
#              from the store features using their geometry and the destinations
#              are loaded from the origins using network location fields to 
#              speed up the load times. 
# 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"
    outNALayer = "StoreTravelTimeMatrix"
    impedanceAttribute = "TravelTime"
    inFeatures = "Analysis/Stores"
    searchTolerance = "500 Meters"
    searchQuery = [["Streets",'"FREEWAY" = 0'],["Streets_ND_Junctions",""]]
    originsLayer = outNALayer + "/" + "Origins"
    fieldMappings = "Name Name #; SourceID SourceID #;SourceOID SourceOID #;" \
                    + "PosAlong PosAlong #;SideOfEdge SideOfEdge #"
    outLayer = "C:/data/output" + "/" + outNALayer + ".lyr"
    
    #Create a new OD cost matrix analysis layer. For this scenario, the default 
    #value for all the remaining parameters statisfies the analysis requirements
    arcpy.MakeODCostMatrixLayer_na(inNetworkDataset, outNALayer, 
                                   impedanceAttribute)
    
    #Load store features as origins using the geometry of store features.
    #Ensure that the stores are not located on freeways by using a search query.
    #The OD cost matrix layer created previously is referred using its name. 
    arcpy.AddLocations_na(outNALayer,"Origins",inFeatures,"",searchTolerance,
                          search_query = searchQuery)
    
    #Load origins as destinations using the network locations fields from 
    #origins. This is much faster than loading destinations from the store 
    #features using their geometry as their network locations have already been
    #calculated while loading them origins.
    arcpy.AddLocations_na(outNALayer,"Destinations",originsLayer,fieldMappings,
                          "")
    
    #Solve the od cost matrix layer. Halt the execution if there is an 
    #invalid location 
    arcpy.Solve_na(outNALayer,"HALT")
    
    #Save the solved na layer as a layer file on disk with relative paths
    arcpy.SaveToLayerFile_management(outNALayer,outLayer,"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)
    

环境

相关主题


7/10/2012