import arcpy # Check out any necessary licenses arcpy.CheckOutExtension("Network") # Local variables: van_roadsND = "van_roadsND" van_grocery = "van_grocery" dauid = "dauid" van_grocery_routes = "van_grocery_routes" van_grocery_routes__2_ = "van_grocery_routes" van_grocery_routes__3_ = "van_grocery_routes" # Process: Make Closest Facility Layer arcpy.MakeClosestFacilityLayer_na(van_roadsND, "van_grocery_routes", "Length", "TRAVEL_TO", "", "1", "", "ALLOW_UTURNS", "", "NO_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "", "NOT_USED") # Process: Add Locations arcpy.AddLocations_na(van_grocery_routes, "Facilities", van_grocery, "Name Name #", "5000 Meters", "", "public_streets SHAPE;van_roadsND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "public_streets #;van_roadsND_Junctions #") # Process: Add Locations (2) arcpy.AddLocations_na(van_grocery_routes__2_, "Incidents", dauid, "", "5000 Meters", "", "public_streets SHAPE;van_roadsND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "public_streets #;van_roadsND_Junctions #")
################################################ #--Berechnung--# ################################################ arcpy.Delete_management("ODMATRIX") arcpy.Delete_management("intersect") arcpy.Delete_management("A_Shape") arcpy.Delete_management("S_Shape") arcpy.MakeFeatureLayer_management(A_Shape, "A_Shape") if NMIV == True: ODLayer = arcpy.MakeODCostMatrixLayer_na(Network, "ODMATRIX", Kosten, Max_Kosten, 1, [Kosten, "tFuss", "Meter"], "", "", "", "", "NO_LINES") else: ODLayer = arcpy.MakeClosestFacilityLayer_na(Network, "ODMATRIX", Kosten, "", Max_Kosten, 1, [Kosten, "Meter"], "", "", "", "", "NO_LINES") if NMIV == True: field_mappings = "Name " + A_Shape_ID + " 0; SourceID SourceID_NMIV 0;SourceOID SourceOID_NMIV 0;PosAlong PosAlong_NMIV 0;SideOfEdge SideOfEdge_NMIV 0" else: field_mappings = "Name " + A_Shape_ID + " 0; SourceID SourceID_MIV 0;SourceOID SourceOID_MIV 0;PosAlong PosAlong_MIV 0;SideOfEdge SideOfEdge_MIV 0; Attr_tAkt tAb 1" if NMIV == True: arcpy.AddLocations_na(ODLayer, "Origins", "A_Shape", field_mappings, "", "", "", "", "", "", "", "EXCLUDE") else: arcpy.AddLocations_na(ODLayer, "Incidents", "A_Shape", field_mappings, "", "", "", "", "", "", "", "EXCLUDE") r = []
if arcpy.CheckExtension("NETWORK") == "Available": arcpy.CheckOutExtension("NETWORK") else: quit() inIncidents = folder_path + r'\Results\User Location.shp' inFacilities = folder_path + r'\Results\Charging_Stations_Copy.shp' closest_layer = arcpy.MakeClosestFacilityLayer_na( in_network_dataset=folder_path + r'\Geog170_Street_Dataset\streets', out_network_analysis_layer="Closest Facility", impedance_attribute="Time", travel_from_to="TRAVEL_TO", default_cutoff="", default_number_facilities_to_find="3", accumulate_attribute_name="", UTurn_policy="ALLOW_UTURNS", restriction_attribute_name="TurnRestriction;OneWay", hierarchy="USE_HIERARCHY", hierarchy_settings="", output_path_shape="TRUE_LINES_WITH_MEASURES", time_of_day="", time_of_day_usage="NOT_USED") out_CL = closest_layer.getOutput(0) subLayerNames = arcpy.na.GetNAClassNames(out_CL) facilitiesLayerName = subLayerNames["Facilities"] incidentsLayerName = subLayerNames["Incidents"] arcpy.na.AddLocations(out_CL, facilitiesLayerName, inFacilities, "", "")
def closest_facility(network, rdv_name, facilities, incidents, table, oneway_restriction=False): """ Execute the Closest Facility tool - Produce Closest Facility Layer * facilities = destiny points * incidents = start/origins points """ from glass.pys.oss import fprop from gesri.dct.fmshp import shp_to_lyr from gesri.dct.toshp import tbl_to_tbl """if arcpy.CheckExtension("Network") == "Available": arcpy.CheckOutExtension("Network") else: raise ValueError('Network analyst extension is not avaiable')""" if oneway_restriction: oneway = "Oneway" else: oneway = "" nName = str(os.path.basename(network)) junc = nName + '_Junctions' cf_lyr = "cf_{}".format(fprop(incidents, 'fn')) arcpy.MakeClosestFacilityLayer_na( in_network_dataset=network, out_network_analysis_layer=cf_lyr, impedance_attribute="Minutes", travel_from_to="TRAVEL_TO", default_cutoff="", default_number_facilities_to_find="1", accumulate_attribute_name="", UTurn_policy="NO_UTURNS", restriction_attribute_name=oneway, hierarchy="NO_HIERARCHY", hierarchy_settings="", output_path_shape="TRUE_LINES_WITH_MEASURES", time_of_day="", time_of_day_usage="NOT_USED" ) lyr_fa = shp_to_lyr(facilities) arcpy.AddLocations_na( cf_lyr, "Facilities", lyr_fa, "", "5000 Meters", "", "{_rdv} SHAPE;{j} NONE".format(_rdv=str(rdv_name), j=str(junc)), "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "{_rdv} #;{j} #".format(_rdv=str(rdv_name), j=str(junc)) ) lyr_in = shp_to_lyr(incidents) arcpy.AddLocations_na( cf_lyr, "Incidents", lyr_in, "", "5000 Meters", "", "{_rdv} SHAPE;{j} NONE".format(_rdv=str(rdv_name), j=str(junc)), "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "{_rdv} #;{j} #".format(_rdv=str(rdv_name), j=str(junc)) ) arcpy.Solve_na(cf_lyr, "SKIP", "TERMINATE", "") tbl_to_tbl(cf_lyr + "\\Routes", table) return table
def get_batiments_isoles(rr_dataset, centroides_batiments, point_depart, clip_rr_zi, id_field): # NETWORK ANALYST ####################################################################### # Process: Make Closest Facility Layer out_na_layer = arcpy.MakeClosestFacilityLayer_na( rr_dataset, "Closest Facility 2", "Length", "TRAVEL_TO", "", "1", "", "ALLOW_UTURNS", "", "NO_HIERARCHY", "", "STRAIGHT_LINES", "", "NOT_USED") ######################## # Get the layer object from the result object. The route layer can now be # referenced using the layer object. out_na_layer = out_na_layer.getOutput(0) ######################## # Process: Add Locations arcpy.AddLocations_na( out_na_layer, "Incidents", centroides_batiments, "", "5000 Meters", "", "Reseau_routier_SJSR SHAPE;Reseau_SJSR_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Reseau_routier_SJSR #;Reseau_SJSR_ND_Junctions #") # Process: Add Locations (3) arcpy.AddLocations_na( out_na_layer, "Facilities", point_depart, "Name Name #", "5000 Meters", "", "Reseau_routier_SJSR SHAPE;Reseau_SJSR_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Reseau_routier_SJSR #;Reseau_SJSR_ND_Junctions #") # Process: Add Locations (4) arcpy.AddLocations_na( out_na_layer, "Line Barriers", clip_rr_zi, "", "5000 Meters", "", "Reseau_routier_SJSR SHAPE;Reseau_SJSR_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Reseau_routier_SJSR #;Reseau_SJSR_ND_Junctions #") # Process: Solve arcpy.Solve_na(out_na_layer, "SKIP", "TERMINATE", "") ######################## # List sublayers in NALayer Group and export each for lyr in arcpy.mapping.ListLayers(out_na_layer): if lyr.isGroupLayer: continue if lyr.name == "Routes": arcpy.CopyFeatures_management( lyr, os.path.join(arcpy.env.workspace, lyr.name)) ######################## # GEOTRAITEMENTS ####################################################################### # Conversion des vertex des trajets en points et selection inverse pour selectionner # les batiments inaccessibles par la route in_routes = os.path.join(arcpy.env.workspace, "Routes") r_vertex = 'RVertex' arcpy.FeatureVerticesToPoints_management(in_routes, r_vertex, "ALL") r_vertex_layer = 'RVertexLayer' cent_layer = 'CentLayer' arcpy.MakeFeatureLayer_management(r_vertex, r_vertex_layer) arcpy.MakeFeatureLayer_management(centroides_batiments, cent_layer) arcpy.SelectLayerByLocation_management(cent_layer, "INTERSECT", r_vertex_layer) arcpy.SelectLayerByAttribute_management(cent_layer, "SWITCH_SELECTION") # Listes des ID des batiments isoles + zone inondee (inaccessibles car segments de routes inondes) list_isole_zi = [] rows = arcpy.da.SearchCursor(cent_layer, [id_field]) for row in rows: list_isole_zi.append(row[0]) del rows return list_isole_zi