Skip To Content

CheckIntersectingFeatures

Summary

Returns a Boolean indicating 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.

Discussion

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 might 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.

Syntax

CheckIntersectingFeatures (network_dataset_path, feature_layer, {cutoff})
ParameterExplanationData Type
network_dataset_path

A variable that references the catalog path of the network dataset. Each edge source in this network dataset will be considered while performing the check. The catalog path of a network dataset can be obtained from the dataSource property of a network dataset layer or a network analysis layer object. It can also be obtained from the catalogPath property of a network dataset Describe object.

The parameter also accepts a network dataset layer object.

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.

(The default value is 5000)

Long
Return Value
Data TypeExplanation
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.

Code sample

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

#Set up the environment
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("network")

#Set up variables
networkDataset = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
polygonBarriers = "C:/Data/WeatberSlowDownAreas.shp"
stops = "C:/Data/SanFrancisco.gdb/Analysis/Stores"
cutoff = 3000
impedanceAttribute = "TravelTime"
outputLayer = "C:/Data/WeatherRoute.lyr"

#Make a feature layer from the catalog path to the shapefile
barriersLayer = arcpy.management.MakeFeatureLayer(polygonBarriers,
                                                  "PolygonBarriersLayer").getOutput(0)
#Check if edge features intersected by barrier features are less than 3000
if arcpy.na.CheckIntersectingFeatures(networkDataset, barriersLayer, cutoff):
    #Proceed with creating a new route layer and loading the barriers
    routeLayer = arcpy.na.MakeRouteLayer(networkDataset, "WeatherRoute",
                                         impedanceAttribute).getOutput(0)
    #Get na class names based on the layer
    naClasses = arcpy.na.GetNAClassNames(routeLayer, "INPUT")
    #Create field mappings for loading barriers as scaled cost polygon barriers
    #with a slow down of 40%
    fieldMappings = arcpy.na.NAClassFieldMappings(routeLayer,
                                                  naClasses["PolygonBarriers"])
    fieldMappings["BarrierType"].defaultValue = 1
    fieldMappings["Attr_" + impedanceAttribute].defaultValue = 1.4
    #Load weather polygons as slow down barriers
    arcpy.na.AddLocations(routeLayer, naClasses["PolygonBarriers"],
                          polygonBarriers, fieldMappings)
    #Load stops
    arcpy.na.AddLocations(routeLayer, naClasses["Stops"], stops)
    #Solve the route
    arcpy.na.Solve(routeLayer)
    #Save the solved layer as a layer file
    arcpy.management.SaveToLayerFile(routeLayer, outputLayer)
else:
    #Return a standard error message if the test fails.
    arcpy.AddIDMessage("ERROR", 30095, "Polygon Barriers", cutoff)

arcpy.AddMessage("Completed")