Create service areas using Python using Calculate Locations

295
4
Jump to solution
04-10-2021 11:10 AM
Labels (1)
AndrewClark2
New Contributor III

Hi,

I am trying to create service areas in Python using the NAX library in ArcPy for ArcGIS Pro 2.7. I would like to make sure the locations snap to the road network, not unnamed parking lot lines / highways, etc. It seems the only way to create a query is with the CalculateLocations object, but there are no resources I can find to figure how to incorporate CalculateLocations with Load or the nax.ServiceArea objects.

Any suggestions would be appreciated.

 

# Create a network dataset layer and get hte desired travel mode
ap.nax.MakeNetworkDatasetLayer(nds,nd_layer_name)
nd_travel_modes = ap.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes['Driving']

# Instantiate a ServiceArea solver object
service_area = arcpy.nax.ServiceArea(nd_layer_name)

# Set properties
service_area.distanceUnits = ap.nax.DistanceUnits.Meters
service_area.travelMode = travel_mode
service_area.outputType = arcpy.nax.ServiceAreaOutputType.Polygons
service_area.geometryAtOverlap = arcpy.nax.ServiceAreaOverlapGeometry.Split

search_query=[['RoadsNetwork',"'STREET' IS NOT NULL And 'STREET' <> ''"]]
search_criteria=[['RoadsNetwork','SHAPE'],['NetworkDataSet_Junctions','NONE']]
search_tolerance = "200 Meters"

arcpy.nax.CalculateLocations(School,nds,search_tolerance,search_criteria=search_criteria,exclude_restricted_elements="EXCLUDE",search_query=search_query)

Impedance = [100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600]

for n in Impedance:
    service_area.defaultImpedanceCutoffs = [n]

    fm_fac = service_area.fieldMappings(ap.nax.ServiceAreaInputDataType.Facilities,True)
    fm_fac["Name"].mappedFieldName = 'ScNumber'
    
    # Load Inputs
    service_area.load(arcpy.nax.ServiceAreaInputDataType.Facilities, School,field_mappings=fm_fac, append=False)

    # Solve the analysis
    result = service_area.solve()

    # Export Feature Class
    result.export(arcpy.nax.ServiceAreaOutputDataType.Polygons, os.path.join(OutputFD,"Schools_Ntwk_"+str(n)+"m"))
    print('Calculated service area for {}-m service area buffer'.format(n))

 

0 Kudos
1 Solution

Accepted Solutions
MelindaMorang
Esri Regular Contributor

The ServiceArea class has properties for this: https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/servicearea.htm

The properties you want are "searchQuery", "searchTolerance", and "searchToleranceUnits". There is no property for search criteria, but from your script, it seems like you only want the default anyway, so that shouldn't be a problem.

View solution in original post

0 Kudos
4 Replies
DanPatterson
MVP Notable Contributor

I moved your question to the Network Analyst questions space.  Better chance of getting an answer here.


... sort of retired...
MelindaMorang
Esri Regular Contributor

The ServiceArea class has properties for this: https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/servicearea.htm

The properties you want are "searchQuery", "searchTolerance", and "searchToleranceUnits". There is no property for search criteria, but from your script, it seems like you only want the default anyway, so that shouldn't be a problem.

View solution in original post

0 Kudos
AndrewClark2
New Contributor III

Thank you so much Melinda!!!!!  This seems to have worked. I find the NAX very confusing to work with as there is so many different classes and objects that work together. Is there a diagram anywhere explaining how they work together? 

Andrew

0 Kudos
MelindaMorang
Esri Regular Contributor

Unfortunately there is not. With the upcoming release of Pro 2.8, we will have two new topics in the nax documentation layout out more detail on how to load inputs and access results, so hopefully that will be helpful.

We definitely want to continue improving our documentation to alleviate confusion! I would be interested to learn more about what specific things you have been confused about. If you don't want to leave more details here in the public comments, feel free to send me a private message. I will listen to whatever has confused you and see what I can do to fix it for the next release.

0 Kudos