import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\UpdateDevelopmentPython\ForDeveloping\ExistingHydrants.gdb"
Hydrant_FC = "Hydrants"
Streetmap = r"C:\UpdateDevelopmentPython\Streetmap Premium\FGDB\StreetMap_Data\NorthAmerica.gdb\Routing\Routing_ND"
EnterWaterSysID = arcpy.GetParameterAsText(0)
NewHydrants = arcpy.GetParameterAsText(1)
qry = "{0} = {1}".format(arcpy.AddFieldDelimiters(datasource= Hydrant_FC, field = 'WaterSysID'),EnterWaterSysID)
arcpy.SelectLayerByAttribute_management(in_layer_or_view=Hydrant_FC, where_clause=qry)
arcpy.SelectLayerByLocation_management(Hydrant_FC,"Within",NewHydrants,None,"SUBSET_SELECTION","NOT_INVERT")
arcpy.env.workspace = r"C:\UpdateDevelopmentPython\ForDeveloping\ForDeveloping.gdb"
Service_Area = arcpy.na.MakeServiceAreaAnalysisLayer(network_data_source=Streetmap,
layer_name="Service Area",
travel_mode="Driving Distance",
travel_direction="FROM_FACILITIES",
cutoffs=[0.189394],
time_of_day="",
time_zone="LOCAL_TIME_AT_LOCATIONS",
output_type="LINES",
polygon_detail="STANDARD",
geometry_at_overlaps="SPLIT",
geometry_at_cutoffs="RINGS",
polygon_trim_distance="100 Meters",
exclude_sources_from_polygon_generation=[],
accumulate_attributes=["Miles"],
ignore_invalid_locations="SKIP")[0]
Updated_Service_Area = arcpy.na.AddLocations(in_network_analysis_layer=Service_Area,
sub_layer="Facilities",
in_table=Hydrant_FC,
field_mappings="",
search_tolerance="5000 Meters",
sort_field="",
search_criteria=[["Routing_Streets", "SHAPE"],
["Routing_Streets_Override", "NONE"],
["Routing_ND_Junctions", "NONE"]],
match_type="MATCH_TO_CLOSEST",
append="APPEND",
snap_to_position_along_network="NO_SNAP",
snap_offset="5 Meters",
exclude_restricted_elements="EXCLUDE",
search_query=[])[0]
Solve_Succeeded = arcpy.na.Solve(in_network_analysis_layer=Updated_Service_Area,
ignore_invalids="SKIP",
terminate_on_solve_error="TERMINATE",
simplification_tolerance="",
overrides="")
This is the code that I have so far, and it works great when I enter in one WaterSysID number. However, I'd like to be able to enter in multiple WaterSysIDs and generate a road network from those. Like what's shown in the screenshot.
However when I do this I am then given this error:
Traceback (most recent call last):
File "C:\UpdateDevelopmentPython\DevelopmentScripts\ExtractStreets.py", line 13, in <module>
arcpy.SelectLayerByAttribute_management(in_layer_or_view=Hydrant_FC, where_clause=qry)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 10296, in SelectLayerByAttribute
If anyone has any suggestions that would be very much appreciated, still pretty new/green to Python and Arcpy. Thanks for the help!!!