CheckIntersectingFeatures

概要

Indicates whether the number of edge source features from the specified network dataset that are intersected by the features within the specified feature layer is less than or equal to the specified cutoff. If the number of intersecting features is less than or equal to the allowed limit, the function returns True. If the number of intersecting features exceeds the allowed limit, the function returns False. The function is useful to restrict the number of features that can be loaded as line or polygon barriers into a network analysis layer.

ディスカッション

The function is used to restrict the number of features that can be loaded into sublayers, especially line and polygon barriers, of network analysis layers. While loading polygon barriers, the software needs to determine the intersection between the polygon features and the edge sources from the network dataset. This process can be slow if the polygon features intersect many edge sources such as a state or county boundary. For example, while authoring a geoprocessing service that performs routing analysis, you may want to restrict the features that are loaded as polygon barriers. To have a reasonable service response time, you could restrict loading of polygon barriers if they intersect more than 5,000 edge source features from the network dataset. This function can be easily used to perform such a check.

構文

CheckIntersectingFeatures (network_dataset_path, feature_layer, {cutoff})
パラメーター説明データ タイプ
network_dataset_path

The input network dataset, referenced as a catalog path, network dataset layer object, or layer name. Each edge source in this network dataset will be considered while performing the check.

String
feature_layer

A variable that references a catalog path, feature set, layer object, or layer name containing the features you want to test for intersection with the network dataset edges. Any selection set or definition query present on the Layer object is honored and can be used to specify only a subset of features.

Layer
cutoff

An integer value used as a cutoff while performing the check.

(デフォルト値は次のとおりです 5000)

Long
戻り値
データ タイプ説明
Boolean

If the specified features that intersect the edge source features from the network dataset are less than or equal to the cutoff value, the function returns True; otherwise, it returns False.

コードのサンプル

CheckIntersectingFeatures example (workflow)

The example shows how to find the best route between some store locations considering weather conditions as slowdown areas. It illustrates how to use the CheckIntersectingFeatures function to test that the weather polygons to be used as polygon barriers do not intersect more than a specified number of edge source features from the network dataset. If the condition is not met, the script raises a standard error message.

import arcpy
from arcpy import env
import os

#Check out the Network Analyst extension license
arcpy.CheckOutExtension("network")

#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 up variables
network = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
polygon_barriers = "C:/Data/SanFrancisco.gdb/Analysis/WeatherSlowDownAreas"
stops = "C:/Data/SanFrancisco.gdb/Analysis/Stores"
cutoff = 3000

#Make a feature layer from the catalog path to the shapefile
barriers_layer = arcpy.management.MakeFeatureLayer(polygon_barriers,
                                        "PolygonBarriersLayer").getOutput(0)

#Check if fewer than 3000 edge features are intersected by barrier features
if arcpy.na.CheckIntersectingFeatures(network, barriers_layer, cutoff):
    
    #Proceed with creating a new route layer and loading the barriers
    route_layer = arcpy.na.MakeRouteAnalysisLayer(network, "WeatherRoute",
                                         "Driving Time").getOutput(0)
                                         
    #Get na class names based on the layer
    naClasses = arcpy.na.GetNAClassNames(route_layer, "INPUT")
    
    #Create field mappings for loading barriers as scaled cost polygon barriers
    #with a slow down of 40%
    fieldMappings = arcpy.na.NAClassFieldMappings(route_layer,
                                                  naClasses["PolygonBarriers"])
    fieldMappings["BarrierType"].defaultValue = 1
    #Figure out the layer's impedance attribute
    solver_props = arcpy.na.GetSolverProperties(route_layer)
    impedance = solver_props.impedance
    fieldMappings["Attr_" + impedance].defaultValue = 1.4
    #Load weather polygons as slow down barriers
    arcpy.na.AddLocations(route_layer, naClasses["PolygonBarriers"],
                          polygonBarriers, fieldMappings)
                          
    #Load stops
    arcpy.na.AddLocations(route_layer, naClasses["Stops"], stops)
    
    #Solve the route
    arcpy.na.Solve(route_layer)

else:
    #Return a standard error message if the test fails.
    arcpy.AddIDMessage("ERROR", 30095, "Polygon Barriers", cutoff)

arcpy.AddMessage("Completed")