wonder if anyone can help me.
I make a network analyst (Closest Facility) analysis. I will be driving from "Incidents" to "Facilities". My "Facilities" is the population center in a municipality. In "Facilities" I have a column "POP" that says how many residents who are in the population center. First, the Closest Facility analyses will go to the nearest "Facilities" and count how many residents that there are in the column "POP". So it should go to the second-nearest "Facilities" and count how many residents that are in the column "POP" there. For every "Facilities" it will count how many residents there are in the column "POP" and accumulate the result from the column "POP" to a column called cumulative. So that it accumulates results from column "POP" for each "Facilities". I've made it so far. But my problem is when the accumulation has reached the nearest sum over 5000 in the column accumulated I want the Closest Facility analyzes to stop and not go to all the "Facilities" in my dataset. Why I want the analysis to stop when it has reached the nearest sum over 5000 is to save time and computer power. Is it possible to get Closest Facility to stop the way I want, or must it go through all "Facilities" that I have?
Greeting Tom Anders
# -*- coding: utf-8 -*- Import arcpy module
import arcpy, os, sys
Check out any necessary licenses
arcpy.CheckOutExtension("Network")
arcpy.env.overwriteOutput = True
Local variables:
WS = "C:\Tom\Oppdrag_2015\KMD_NY" ELVEG_Nettverk_ND_2013 = "C:\Tom\Krd_2013\ELVEG_Nettverk_2013\ELVEG_Nettverk_2013.gdb\ELVEG_Nettverk\ELVEG_Nettverk_ND_2013" Til = r"C:\Tom\Oppdrag_2015\KMD_NY\04_Hedmark_Ut.gdb\Til" Fra = r"C:\Tom\Oppdrag_2015\KMD_NY\04_Hedmark_Ut.gdb\Fra" Ruter = r"C:\Tom\Oppdrag_2015\KMD_NY\Ruter.shp"
Routes = "Closest Facility\Routes" ODLines_Layer = "ODLines_Layer" NY = "TEST" Closest_Facility = "Closest Facility"
arcpy.MakeFeatureLayer_management(Fra, "FraLyr")
arcpy.MakeFeatureLayer_management(Til, "TilLyr")
Process: Add Field (2)
arcpy.AddField_management("TilLyr", "Innbyggere_NY", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management("FraLyr", "FraGkr", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "")
Process: Calculate Field (3)
arcpy.CalculateField_management("FraLyr", "FraGkr", "[GRUNNKRETS]", "VB", "")
rows = arcpy.da.SearchCursor("FraLyr", "TEST")
for row in rows: Gkr = str(row[0]) where = " \"TEST\" = " + "" + str(Gkr) + "" arcpy.SelectLayerByAttribute_management("FraLyr", "NEW_SELECTION", where)
closestBTP = "ClosestBTP" # Process: Make Closest Facility Layer outNALayer = arcpy.MakeClosestFacilityLayer_na(ELVEG_Nettverk_ND_2013, closestBTP, "Meters", "TRAVEL_TO", "", "50", "", "ALLOW_UTURNS", "Oneway", "USE_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "", "NOT_USED") # arcpy.AddFieldToAnalysisLayer_na (closestBTP,"Routes", "Gkr_nr", "TEXT", "", "", "50") # Process: Add Field (3) arcpy.AddField_management(closestBTP + "\\Routes", "Akkumulert", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(closestBTP + "\\Routes", "Grunnkrets", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "") # # Process: Add Locations arcpy.AddLocations_na(closestBTP, "Incidents", "FraLyr", "Name GRUNNKRETS #", "5000 Meters", "", "ELVEG_Vegnett_2013 SHAPE;ELVEG_Nettverk_ND_2013_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "ELVEG_Vegnett_2013 #;ELVEG_Nettverk_ND_2013_Junctions #") # Process: Add Locations (2) arcpy.AddLocations_na(closestBTP, "Facilities", "TilLyr", "Name GRUNNKRETS #", "5000 Meters", "", "ELVEG_Vegnett_2013 SHAPE;ELVEG_Nettverk_ND_2013_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "ELVEG_Vegnett_2013 #;ELVEG_Nettverk_ND_2013_Junctions #") # Process: Solve arcpy.Solve_na(closestBTP, "SKIP", "TERMINATE", "") # # Process: Calculate Field arcpy.CalculateField_management(closestBTP + "\\Routes", "Gkr_nr", "[Name]", "VB", "") # Process: Calculate Field (4) arcpy.CalculateField_management(closestBTP + "\\Routes", "Grunnkrets", "[Gkr_nr]", "VB", "") # Process: Calculate Field (2) arcpy.CalculateField_management(closestBTP + "\\Routes", "Gkr_nr", "Right( [Gkr_nr],8 )", "VB", "") # Process: Join Field arcpy.JoinField_management(closestBTP + "\\Routes", "Gkr_nr", "TilLyr", "GRUNNKRETS", "Innbyggere_NY") # Process: Calculate Field (5) arcpy.CalculateField_management(closestBTP + "\Routes", "Akkumulert", "cumsum( !Innbyggere_NY! )", "PYTHON_9.3", "total = 0\ndef cumsum(inc):\n global total\n total+=inc\n return total\n")
#where1 = " \"Akkumulert\" < 5000 " #where1 = " \"FraGkr\" = " + "" + str(Fra_Gkr) + "" #TEST = arcpy.SelectLayerByAttribute_management(closestBTP + "\\Routes", "NEW_SELECTION", where1) arcpy.SaveToLayerFile_management(closestBTP, "Grunnkrets" + "_" + Gkr, "RELATIVE")
أكثر...
I make a network analyst (Closest Facility) analysis. I will be driving from "Incidents" to "Facilities". My "Facilities" is the population center in a municipality. In "Facilities" I have a column "POP" that says how many residents who are in the population center. First, the Closest Facility analyses will go to the nearest "Facilities" and count how many residents that there are in the column "POP". So it should go to the second-nearest "Facilities" and count how many residents that are in the column "POP" there. For every "Facilities" it will count how many residents there are in the column "POP" and accumulate the result from the column "POP" to a column called cumulative. So that it accumulates results from column "POP" for each "Facilities". I've made it so far. But my problem is when the accumulation has reached the nearest sum over 5000 in the column accumulated I want the Closest Facility analyzes to stop and not go to all the "Facilities" in my dataset. Why I want the analysis to stop when it has reached the nearest sum over 5000 is to save time and computer power. Is it possible to get Closest Facility to stop the way I want, or must it go through all "Facilities" that I have?
Greeting Tom Anders
# -*- coding: utf-8 -*- Import arcpy module
import arcpy, os, sys
Check out any necessary licenses
arcpy.CheckOutExtension("Network")
arcpy.env.overwriteOutput = True
Local variables:
WS = "C:\Tom\Oppdrag_2015\KMD_NY" ELVEG_Nettverk_ND_2013 = "C:\Tom\Krd_2013\ELVEG_Nettverk_2013\ELVEG_Nettverk_2013.gdb\ELVEG_Nettverk\ELVEG_Nettverk_ND_2013" Til = r"C:\Tom\Oppdrag_2015\KMD_NY\04_Hedmark_Ut.gdb\Til" Fra = r"C:\Tom\Oppdrag_2015\KMD_NY\04_Hedmark_Ut.gdb\Fra" Ruter = r"C:\Tom\Oppdrag_2015\KMD_NY\Ruter.shp"
Routes = "Closest Facility\Routes" ODLines_Layer = "ODLines_Layer" NY = "TEST" Closest_Facility = "Closest Facility"
arcpy.MakeFeatureLayer_management(Fra, "FraLyr")
arcpy.MakeFeatureLayer_management(Til, "TilLyr")
Process: Add Field (2)
arcpy.AddField_management("TilLyr", "Innbyggere_NY", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management("FraLyr", "FraGkr", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "")
Process: Calculate Field (3)
arcpy.CalculateField_management("FraLyr", "FraGkr", "[GRUNNKRETS]", "VB", "")
rows = arcpy.da.SearchCursor("FraLyr", "TEST")
for row in rows: Gkr = str(row[0]) where = " \"TEST\" = " + "" + str(Gkr) + "" arcpy.SelectLayerByAttribute_management("FraLyr", "NEW_SELECTION", where)
closestBTP = "ClosestBTP" # Process: Make Closest Facility Layer outNALayer = arcpy.MakeClosestFacilityLayer_na(ELVEG_Nettverk_ND_2013, closestBTP, "Meters", "TRAVEL_TO", "", "50", "", "ALLOW_UTURNS", "Oneway", "USE_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "", "NOT_USED") # arcpy.AddFieldToAnalysisLayer_na (closestBTP,"Routes", "Gkr_nr", "TEXT", "", "", "50") # Process: Add Field (3) arcpy.AddField_management(closestBTP + "\\Routes", "Akkumulert", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(closestBTP + "\\Routes", "Grunnkrets", "LONG", "", "", "20", "", "NULLABLE", "NON_REQUIRED", "") # # Process: Add Locations arcpy.AddLocations_na(closestBTP, "Incidents", "FraLyr", "Name GRUNNKRETS #", "5000 Meters", "", "ELVEG_Vegnett_2013 SHAPE;ELVEG_Nettverk_ND_2013_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "ELVEG_Vegnett_2013 #;ELVEG_Nettverk_ND_2013_Junctions #") # Process: Add Locations (2) arcpy.AddLocations_na(closestBTP, "Facilities", "TilLyr", "Name GRUNNKRETS #", "5000 Meters", "", "ELVEG_Vegnett_2013 SHAPE;ELVEG_Nettverk_ND_2013_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "ELVEG_Vegnett_2013 #;ELVEG_Nettverk_ND_2013_Junctions #") # Process: Solve arcpy.Solve_na(closestBTP, "SKIP", "TERMINATE", "") # # Process: Calculate Field arcpy.CalculateField_management(closestBTP + "\\Routes", "Gkr_nr", "[Name]", "VB", "") # Process: Calculate Field (4) arcpy.CalculateField_management(closestBTP + "\\Routes", "Grunnkrets", "[Gkr_nr]", "VB", "") # Process: Calculate Field (2) arcpy.CalculateField_management(closestBTP + "\\Routes", "Gkr_nr", "Right( [Gkr_nr],8 )", "VB", "") # Process: Join Field arcpy.JoinField_management(closestBTP + "\\Routes", "Gkr_nr", "TilLyr", "GRUNNKRETS", "Innbyggere_NY") # Process: Calculate Field (5) arcpy.CalculateField_management(closestBTP + "\Routes", "Akkumulert", "cumsum( !Innbyggere_NY! )", "PYTHON_9.3", "total = 0\ndef cumsum(inc):\n global total\n total+=inc\n return total\n")
#where1 = " \"Akkumulert\" < 5000 " #where1 = " \"FraGkr\" = " + "" + str(Fra_Gkr) + "" #TEST = arcpy.SelectLayerByAttribute_management(closestBTP + "\\Routes", "NEW_SELECTION", where1) arcpy.SaveToLayerFile_management(closestBTP, "Grunnkrets" + "_" + Gkr, "RELATIVE")
أكثر...