POST
|
Can we also expect to create the network dataset automatically in ArcGIS Pro? Like remembering the settings and use it for different scenarios.
... View more
09-02-2019
06:57 AM
|
0
|
3
|
845
|
POST
|
@Colin Zwicker and Marco Boeringa I tried to split the list into two and it works (See the scripts below ). This is a workaround. if fc1234_boolean.lower() != 'true':
arcpy.AddMessage("Making selection")
for fc in inputlist:
with arcpy.da.SearchCursor(fc, ["LINK_ID"]) as cursor:
for row in cursor:
linkidList.append(row[0])
linkidList1 = []
linkidList2 = []
linkidList1 = linkidList[:len(linkidList)//2]
linkidList2 = linkidList[len(linkidList)//2:]
arcpy.AddMessage(linkidList1)
arcpy.AddMessage(linkidList2)
where1 = '"LINK_ID" = {0}'.format(int(linkidList1[0]))
del linkidList1[0]
for linkid in linkidList1:
where1 += ' OR "LINK_ID" = {0}'.format(int(linkid))
where2 = '"LINK_ID" = {0}'.format(int(linkidList2[0]))
del linkidList2[0]
for linkid in linkidList2:
where2 += ' OR "LINK_ID" = {0}'.format(int(linkid))
arcpy.AddMessage(where1)
arcpy.AddMessage(where2)
arcpy.SelectLayerByAttribute_management(streets_nav, "NEW_SELECTION", where1)
arcpy.SelectLayerByAttribute_management(streets_nav, "NEW_SELECTION", where2)
arcpy.SelectLayerByAttribute_management(ows, "NEW_SELECTION", where1)
arcpy.SelectLayerByAttribute_management(ows, "NEW_SELECTION", where2)
arcpy.SelectLayerByAttribute_management(rdms, "NEW_SELECTION", where1)
arcpy.SelectLayerByAttribute_management(rdms, "NEW_SELECTION", where2) Therefore, the feedback is: 1. With this SQL where += ' OR "LINK_ID" = {0}'.format(int(linkid)) If the record is quite large, for example in this case 6090, then the arcpy function "SelectLayerByAttribute_management" can not handle it. arcpy.SelectLayerByAttribute_management(streets_nav, "NEW_SELECTION", where) However, if the record has been splitted, then it can handle it. It is a workaround to make the tool working but I did not figure it out the reason behind it. Regards, Fengchao
... View more
12-06-2018
06:04 AM
|
1
|
0
|
1438
|
POST
|
@ Colin Zwicker Thanks a lot! I will try this way to adjust my scripts a little bit. I will post the result later.
... View more
12-05-2018
02:50 AM
|
0
|
0
|
1438
|
POST
|
Thanks for the suggestion. I have tried to use Check Geometry to check all my input files and also use Repair Geometry to repair to make sure the quality is good. But I still face this crash problem. The problem is still the same, less number of input files, this tool can handle, but more... It crashes. The crash point is around 40-45 number of layers.
... View more
12-05-2018
02:47 AM
|
0
|
0
|
676
|
POST
|
@Marco Boeringa Here is the screenshot of ArcGIS Pro Diagnostic Monitor and the Performance (See the picture below). The first time I tired to give 50 layers as input but it crashed. And then I merged all the 50 layers into one layer. try it again but it still crashes. And the total size of the merged file(.shp) is 364KB. G M T Detect language Afrikaans Albanian Amharic Arabic Armenian Azerbaijani Basque Belarusian Bengali Bosnian Bulgarian Catalan Cebuano Chichewa Chinese (Simplified) Chinese (Traditional) Corsican Croatian Czech Danish Dutch English Esperanto Estonian Filipino Finnish French Frisian Galician Georgian German Greek Gujarati Haitian Creole Hausa Hawaiian Hebrew Hindi Hmong Hungarian Icelandic Igbo Indonesian Irish Italian Japanese Javanese Kannada Kazakh Khmer Korean Kurdish Kyrgyz Lao Latin Latvian Lithuanian Luxembourgish Macedonian Malagasy Malay Malayalam Maltese Maori Marathi Mongolian Myanmar (Burmese) Nepali Norwegian Pashto Persian Polish Portuguese Punjabi Romanian Russian Samoan Scots Gaelic Serbian Sesotho Shona Sindhi Sinhala Slovak Slovenian Somali Spanish Sundanese Swahili Swedish Tajik Tamil Telugu Thai Turkish Ukrainian Urdu Uzbek Vietnamese Welsh Xhosa Yiddish Yoruba Zulu Afrikaans Albanian Amharic Arabic Armenian Azerbaijani Basque Belarusian Bengali Bosnian Bulgarian Catalan Cebuano Chichewa Chinese (Simplified) Chinese (Traditional) Corsican Croatian Czech Danish Dutch English Esperanto Estonian Filipino Finnish French Frisian Galician Georgian German Greek Gujarati Haitian Creole Hausa Hawaiian Hebrew Hindi Hmong Hungarian Icelandic Igbo Indonesian Irish Italian Japanese Javanese Kannada Kazakh Khmer Korean Kurdish Kyrgyz Lao Latin Latvian Lithuanian Luxembourgish Macedonian Malagasy Malay Malayalam Maltese Maori Marathi Mongolian Myanmar (Burmese) Nepali Norwegian Pashto Persian Polish Portuguese Punjabi Romanian Russian Samoan Scots Gaelic Serbian Sesotho Shona Sindhi Sinhala Slovak Slovenian Somali Spanish Sundanese Swahili Swedish Tajik Tamil Telugu Thai Turkish Ukrainian Urdu Uzbek Vietnamese Welsh Xhosa Yiddish Yoruba Zulu Text-to-speech function is limited to 200 characters Options : History : Feedback : Donate Close
... View more
11-29-2018
01:00 AM
|
0
|
2
|
676
|
POST
|
@ Marco Boering, Kory Kramer I have tried to increase the size of virtual memory to 100GB. But unfortunately, I still get the same crash error. So it seems that because of the script itself.
... View more
11-26-2018
07:11 AM
|
0
|
4
|
836
|
POST
|
Thanks Marco! It is quite helpful and detailed. I am going to try to increase the memory.
... View more
11-15-2018
05:18 AM
|
0
|
6
|
836
|
POST
|
Hi Kory, Two of the dump files associated with this crash has been uploaded (See the attachment). And also, this error has been reported one week ago via "Report software errors" with including my system information in the error report. Regards, Fengchao
... View more
11-13-2018
01:29 AM
|
0
|
11
|
836
|
POST
|
Hi Jonathan, So far it is only this custom toolbox that failed. I have tried other custom toolboxes created by our team, and they works fine. Fengchao
... View more
11-13-2018
01:12 AM
|
0
|
0
|
836
|
POST
|
Hi I tried to move it to another directory with no spaces or special characters but it does not work. I got the same crash. And since it works in ArcGIS Pro with less number of input, and it only crash when there are more than 50 input. So I do not really think it is about this .xlsx template.
... View more
11-13-2018
01:08 AM
|
0
|
0
|
1438
|
POST
|
Thanks! I think this is also an option. So far I have tried GetParameter and I get it works. I will try this option too.
... View more
11-12-2018
01:03 PM
|
0
|
0
|
2582
|
POST
|
Yes, it is a specific layer in a specific map in an open ArcGIS Pro session. I just drag it from table of content as an input. The scripts is as blow. # ---------------------------------------------------------------------------
# NAV Combined tool
# Version 1.1
# ---------------------------------------------------------------------------
import arcpy
from arcpy import env
import os
import PopUp
from subprocess import Popen
# Users input
route_temp = arcpy.GetParameterAsText(0) # Testcode_route_temp
arcpy.env.overwriteOutput = True
aprx = arcpy.mp.ArcGISProject ("CURRENT")
aprxMap = aprx.listMaps("Map")[0]
# Define variables
route_temp_display = "route_temp_display.lyrx"
arcpy.MakeFeatureLayer_management(route_temp,"route_temp_lyr")
arcpy.SaveToLayerFile_management("route_temp_lyr", route_temp_display, "ABSOLUTE")
route_temp_lyr = arcpy.mp.LayerFile(route_temp_display)
working_f = os.path.split(route_temp_lyr.dataSource)[0]
arcpy.AddMessage(working_f)
test_f = os.path.split(working_f)[0]
testcode = os.path.split(test_f)[1]
codeshort = testcode.split("_")[0] + "_" + testcode.split("_")[3]
rt_shp = working_f + '\\' + testcode + '_route_temp.shp'
cl_f = test_f + r'\NAV\Clusters'
dr_f = test_f + r'\NAV\Drive_route'
streets = working_f + '\\' + testcode + '_Streets_NAV.shp'
fc5clusters = working_f + '\\' + testcode + '_FC5Clusters.shp'
stragglers = working_f + '\\' + testcode + '_stragglers.shp'
driveroute = dr_f + '\\' + testcode + '_driveroute.shp'
driveroute_display = dr_f + '\\' + testcode + '_driveroute.lyr'
zlevels = working_f + r'\Working.gdb\Zlevel_fd' + '\\' + testcode + '_Auto_Zlevels'
zlevels_rj = working_f + '\\' + testcode + '_Zlevels_route_join.shp'
mob = working_f + '\\' + testcode + '_mob.shp'
steets_df = test_f + r'\DATA'+ '\\' + testcode + '_Streets.shp'
navb = dr_f + '\\' + testcode + '_NAVBuffer.shp'
scrap_gdb = test_f + r'\DATA\scrap.gdb' And what I want is to get the data source of this input layer? I did not figure it out how to get it.
... View more
11-12-2018
05:25 AM
|
0
|
4
|
2582
|
POST
|
Here is the ArcGIS Pro version. import arcpy
from arcpy import env
import sys
import os
import openpyxl
from subprocess import Popen
env.overwriteOutput = True
# User imports
input = arcpy.GetParameterAsText(0)
fc1234_boolean = arcpy.GetParameterAsText(1)
xlsx_boolean = arcpy.GetParameterAsText(2)
# Other variables
inputlist = input.split(";")
inputfile_first = inputlist[0]
#inputlyr = arcpy.mapping.Layer(inputfile_first) # lyr
desc = arcpy.Describe(inputfile_first)
inputpath = desc.path
#inputpath = inputlyr.dataSource # path
inputpath0 = os.path.split(inputpath)[0]
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.listMaps("Map")[0]
home_f = os.path.dirname(aprx.filePath)
testcode = os.path.basename(home_f)
year = testcode.split("_")[0]
country = testcode.split("_")[1]
city_id = testcode.split("_")[2]
cityshort = testcode.split("_")[3]
city_index = testcode.split("_")[4]
testcodeshort = year + '_' + cityshort
working_f = home_f + '\\Working_folder\\'
working_space = arcpy.env.workspace # Default.gdb
dr_file = home_f + '\\NAV\\Drive_route\\' + testcode + "_driveroute.shp"
streets_nav = testcodeshort + "_Streets_NAV"
streets_nav_fc1234 = testcodeshort + "_Streets_NAV_FC1234"
streets_nav_fc1234_long = testcode + "_Streets_NAV_FC1234"
rdms = testcodeshort + "_RDM_line"
rdms_fc12 = testcodeshort + "_RDM_line_FC12"
rdms_fc34 = testcodeshort + "_RDM_line_FC34"
ows = testcodeshort + "_OW"
ows_fc12 = testcodeshort + "_OW_FC12"
ows_fc34 = testcodeshort + "_OW_FC34"
Geo_Stats = working_space + "\\Geo_Stats"
OW_Stats = working_space + "\\OW_Stats"
RDM_Stats = working_space + "\\RDM_Stats"
linkidList = []
# Preset/predefine calculation variables to '0' to prevent errors later in script with empty values
FC1len = 0
FC2len = 0
FC3len = 0
FC4len = 0
FC5len = 0
owFC1len = 0
owFC2len = 0
owFC3len = 0
owFC4len = 0
owFC5len = 0
rdmFC1cnt = 0
rdmFC2cnt = 0
rdmFC3cnt = 0
rdmFC4cnt = 0
rdmFC5cnt = 0
# Selecting all links in streets_nav or streets_nav_fc1234
if fc1234_boolean.lower() != 'true':
arcpy.AddMessage("Making selection")
for fc in inputlist:
with arcpy.da.SearchCursor(fc, ["LINK_ID"]) as cursor:
for row in cursor:
linkidList.append(row[0])
where = '"LINK_ID" = {0}'.format(int(linkidList[0]))
del linkidList[0]
for linkid in linkidList:
where += ' OR "LINK_ID" = {0}'.format(int(linkid))
arcpy.SelectLayerByAttribute_management(streets_nav, "NEW_SELECTION", where)
arcpy.SelectLayerByAttribute_management(ows, "NEW_SELECTION", where)
arcpy.SelectLayerByAttribute_management(rdms, "NEW_SELECTION", where)
else:
arcpy.AddMessage("Making selection FC1234")
layerList = []
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
layerList.append(lyr.name)
for fc in inputlist:
with arcpy.da.SearchCursor(fc, ["LINK_ID"]) as cursor:
for row in cursor:
linkidList.append(row[0])
where = '"LINK_ID" = {0}'.format(int(linkidList[0]))
del linkidList[0]
for linkid in linkidList:
where += ' OR "LINK_ID" = {0}'.format(int(linkid))
if streets_nav_fc1234 in layerList:
streets_layer = streets_nav_fc1234
elif streets_nav_fc1234_long in layerList:
streets_layer = streets_nav_fc1234_long
arcpy.SelectLayerByAttribute_management(streets_layer, "NEW_SELECTION", where)
if ows_fc12 in layerList:
arcpy.SelectLayerByAttribute_management(ows_fc12, "NEW_SELECTION", where)
if ows_fc34 in layerList:
arcpy.SelectLayerByAttribute_management(ows_fc34, "NEW_SELECTION", where)
if rdms_fc12 in layerList:
arcpy.SelectLayerByAttribute_management(rdms_fc12, "NEW_SELECTION", where)
if rdms_fc34 in layerList:
arcpy.SelectLayerByAttribute_management(rdms_fc34, "NEW_SELECTION", where)
# # Zoom to selection
# df.zoomToSelectedFeatures()
# df.scale = df.scale * 1.1
# Make .xlsx if optional output is given
if xlsx_boolean.lower() == 'true':
if fc1234_boolean.lower() == 'true':
arcpy.AddError(
"Not possible to write only FC1234 attributes to an .xlsx file. Run tool again without this option")
sys.exit()
arcpy.AddMessage("Calculating counts for .xlsx")
# Geo statistics per fc
arcpy.Statistics_analysis(streets_nav, Geo_Stats, "LEN SUM", "FUNC_CLASS")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '1'", "", "", "")
for row in rows:
FC1len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '2'", "", "", "")
for row in rows:
FC2len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '3'", "", "", "")
for row in rows:
FC3len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '4'", "", "", "")
for row in rows:
FC4len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '5'", "", "", "")
for row in rows:
FC5len = row.getValue("SUM_LEN")
geoLen12 = FC1len + FC2len
geoLen34 = FC3len + FC4len
geoLen5 = FC5len
# OW statistics per fc
arcpy.Statistics_analysis(ows, OW_Stats, "LEN SUM", "FUNC_CLASS")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '1'", "", "", "")
for row in rows:
owFC1len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '2'", "", "", "")
for row in rows:
owFC2len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '3'", "", "", "")
for row in rows:
owFC3len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '4'", "", "", "")
for row in rows:
owFC4len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '5'", "", "", "")
for row in rows:
owFC5len = row.getValue("SUM_LEN")
owLen12 = owFC1len + owFC2len
owLen34 = owFC3len + owFC4len
owLen5 = owFC5len
# RDM statistics per fc
arcpy.Statistics_analysis(rdms, RDM_Stats, "LEN SUM", "FUNC_CLASS")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '1'", "", "", "")
for row in rows:
rdmFC1cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '2'", "", "", "")
for row in rows:
rdmFC2cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '3'", "", "", "")
for row in rows:
rdmFC3cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '4'", "", "", "")
for row in rows:
rdmFC4cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '5'", "", "", "")
for row in rows:
rdmFC5cnt = row.getValue("FREQUENCY")
rdmCnt12 = rdmFC1cnt + rdmFC2cnt
rdmCnt34 = rdmFC3cnt + rdmFC4cnt
rdmCnt5 = rdmFC5cnt
# Drive_route number of links
count_dr = arcpy.GetCount_management(dr_file)
count_dr_int = int(count_dr.getOutput(0))
# Write outputs to .xlsx
# Using excel template or create new one if not there
if os.path.isfile(
r'C:\Program Files (x86)\ArcGIS\Desktop10.5\Styles\Prep_layer_definition\Calc_templates\calc_dr_selection_temp.xlsx'):
dr_selection_temp = openpyxl.load_workbook(
r'C:\Program Files (x86)\ArcGIS\Desktop10.5\Styles\Prep_layer_definition\Calc_templates\calc_dr_selection_temp.xlsx')
else:
dr_selection_temp = openpyxl.Workbook()
sheet = dr_selection_temp.get_active_sheet()
# Print numbers
sheet['D3'] = geoLen12
sheet['F3'] = geoLen34
sheet['H3'] = geoLen5
sheet['D4'] = owLen12
sheet['F4'] = owLen34
sheet['H4'] = owLen5
sheet['D5'] = rdmCnt12
sheet['F5'] = rdmCnt34
sheet['H5'] = rdmCnt5
sheet['D6'] = geoLen12
sheet['F6'] = geoLen34
sheet['H6'] = geoLen5
sheet['B13'] = count_dr_int
# Saving file to Working_folder
try:
arcpy.AddMessage("Selection saved in {0}_calc_dr_selection.xlsx (in Working_folder)".format(testcode))
dr_selection_temp.save(working_f + '\\' + testcode + '_calc_dr_selection.xlsx')
p = Popen(working_f + '\\' + testcode + '_calc_dr_selection.xlsx', shell=True)
except:
arcpy.AddError(testcode + "_calc_dr_selection.xlsx is already open. Close it first before running the tool")
sys.exit()
... View more
11-12-2018
04:39 AM
|
0
|
6
|
1438
|
POST
|
yes, sure. I will upload two different scripts, one is for ArcMap, and another one is for ArcGIS Pro. Below is the ArcMap version. import arcpy
from arcpy import env
import sys
import os
import openpyxl
from subprocess import Popen
env.overwriteOutput = True
# User imports
input = arcpy.GetParameterAsText(0)
fc1234_boolean = arcpy.GetParameterAsText(1)
xlsx_boolean = arcpy.GetParameterAsText(2)
# Other variables
inputlist = input.split(";")
inputfile_first = inputlist[0]
inputlyr = arcpy.mapping.Layer(inputfile_first) # lyr
inputpath = inputlyr.dataSource # path
inputpath0 = os.path.split(inputpath)[0]
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
home_f = os.path.dirname(mxd.filePath)
testcode = os.path.basename(home_f)
year = testcode.split("_")[0]
country = testcode.split("_")[1]
city_id = testcode.split("_")[2]
cityshort = testcode.split("_")[3]
city_index = testcode.split("_")[4]
testcodeshort = year + '_' + cityshort
working_f = home_f + '\\Working_folder\\'
working_space = arcpy.env.workspace # Default.gdb
dr_file = home_f + '\\NAV\\Drive_route\\' + testcode + "_driveroute.shp"
streets_nav = testcodeshort + "_Streets_NAV"
streets_nav_fc1234 = testcodeshort + "_Streets_NAV_FC1234"
streets_nav_fc1234_long = testcode + "_Streets_NAV_FC1234"
rdms = testcodeshort + "_RDM_line"
rdms_fc12 = testcodeshort + "_RDM_line_FC12"
rdms_fc34 = testcodeshort + "_RDM_line_FC34"
ows = testcodeshort + "_OW"
ows_fc12 = testcodeshort + "_OW_FC12"
ows_fc34 = testcodeshort + "_OW_FC34"
Geo_Stats = working_space + "\\Geo_Stats"
OW_Stats = working_space + "\\OW_Stats"
RDM_Stats = working_space + "\\RDM_Stats"
linkidList = []
# Preset/predefine calculation variables to '0' to prevent errors later in script with empty values
FC1len = 0
FC2len = 0
FC3len = 0
FC4len = 0
FC5len = 0
owFC1len = 0
owFC2len = 0
owFC3len = 0
owFC4len = 0
owFC5len = 0
rdmFC1cnt = 0
rdmFC2cnt = 0
rdmFC3cnt = 0
rdmFC4cnt = 0
rdmFC5cnt = 0
# Selecting all links in streets_nav or streets_nav_fc1234
if fc1234_boolean.lower() != 'true':
arcpy.AddMessage("Making selection")
for fc in inputlist:
with arcpy.da.SearchCursor(fc, ["LINK_ID"]) as cursor:
for row in cursor:
linkidList.append(row[0])
where = '"LINK_ID" = {0}'.format(int(linkidList[0]))
del linkidList[0]
for linkid in linkidList:
where += ' OR "LINK_ID" = {0}'.format(int(linkid))
arcpy.SelectLayerByAttribute_management(streets_nav, "NEW_SELECTION", where)
arcpy.SelectLayerByAttribute_management(ows, "NEW_SELECTION", where)
arcpy.SelectLayerByAttribute_management(rdms, "NEW_SELECTION", where)
else:
arcpy.AddMessage("Making selection FC1234")
layerList = []
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
layerList.append(lyr.name)
for fc in inputlist:
with arcpy.da.SearchCursor(fc, ["LINK_ID"]) as cursor:
for row in cursor:
linkidList.append(row[0])
where = '"LINK_ID" = {0}'.format(int(linkidList[0]))
del linkidList[0]
for linkid in linkidList:
where += ' OR "LINK_ID" = {0}'.format(int(linkid))
if streets_nav_fc1234 in layerList:
streets_layer = streets_nav_fc1234
elif streets_nav_fc1234_long in layerList:
streets_layer = streets_nav_fc1234_long
arcpy.SelectLayerByAttribute_management(streets_layer, "NEW_SELECTION", where)
if ows_fc12 in layerList:
arcpy.SelectLayerByAttribute_management(ows_fc12, "NEW_SELECTION", where)
if ows_fc34 in layerList:
arcpy.SelectLayerByAttribute_management(ows_fc34, "NEW_SELECTION", where)
if rdms_fc12 in layerList:
arcpy.SelectLayerByAttribute_management(rdms_fc12, "NEW_SELECTION", where)
if rdms_fc34 in layerList:
arcpy.SelectLayerByAttribute_management(rdms_fc34, "NEW_SELECTION", where)
# Zoom to selection
df.zoomToSelectedFeatures()
df.scale = df.scale * 1.1
# Make .xlsx if optional output is given
if xlsx_boolean.lower() == 'true':
if fc1234_boolean.lower() == 'true':
arcpy.AddError(
"Not possible to write only FC1234 attributes to an .xlsx file. Run tool again without this option")
sys.exit()
arcpy.AddMessage("Calculating counts for .xlsx")
# Geo statistics per fc
arcpy.Statistics_analysis(streets_nav, Geo_Stats, "LEN SUM", "FUNC_CLASS")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '1'", "", "", "")
for row in rows:
FC1len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '2'", "", "", "")
for row in rows:
FC2len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '3'", "", "", "")
for row in rows:
FC3len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '4'", "", "", "")
for row in rows:
FC4len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(Geo_Stats, "FUNC_CLASS = '5'", "", "", "")
for row in rows:
FC5len = row.getValue("SUM_LEN")
geoLen12 = FC1len + FC2len
geoLen34 = FC3len + FC4len
geoLen5 = FC5len
# OW statistics per fc
arcpy.Statistics_analysis(ows, OW_Stats, "LEN SUM", "FUNC_CLASS")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '1'", "", "", "")
for row in rows:
owFC1len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '2'", "", "", "")
for row in rows:
owFC2len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '3'", "", "", "")
for row in rows:
owFC3len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '4'", "", "", "")
for row in rows:
owFC4len = row.getValue("SUM_LEN")
rows = arcpy.SearchCursor(OW_Stats, "FUNC_CLASS = '5'", "", "", "")
for row in rows:
owFC5len = row.getValue("SUM_LEN")
owLen12 = owFC1len + owFC2len
owLen34 = owFC3len + owFC4len
owLen5 = owFC5len
# RDM statistics per fc
arcpy.Statistics_analysis(rdms, RDM_Stats, "LEN SUM", "FUNC_CLASS")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '1'", "", "", "")
for row in rows:
rdmFC1cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '2'", "", "", "")
for row in rows:
rdmFC2cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '3'", "", "", "")
for row in rows:
rdmFC3cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '4'", "", "", "")
for row in rows:
rdmFC4cnt = row.getValue("FREQUENCY")
rows = arcpy.SearchCursor(RDM_Stats, "FUNC_CLASS = '5'", "", "", "")
for row in rows:
rdmFC5cnt = row.getValue("FREQUENCY")
rdmCnt12 = rdmFC1cnt + rdmFC2cnt
rdmCnt34 = rdmFC3cnt + rdmFC4cnt
rdmCnt5 = rdmFC5cnt
# Drive_route number of links
count_dr = arcpy.GetCount_management(dr_file)
count_dr_int = int(count_dr.getOutput(0))
# Write outputs to .xlsx
# Using excel template or create new one if not there
if os.path.isfile(
r'C:\Program Files (x86)\ArcGIS\Desktop10.5\Styles\Prep_layer_definition\Calc_templates\calc_dr_selection_temp.xlsx'):
dr_selection_temp = openpyxl.load_workbook(
r'C:\Program Files (x86)\ArcGIS\Desktop10.5\Styles\Prep_layer_definition\Calc_templates\calc_dr_selection_temp.xlsx')
else:
dr_selection_temp = openpyxl.Workbook()
sheet = dr_selection_temp.get_active_sheet()
# Print numbers
sheet['D3'] = geoLen12
sheet['F3'] = geoLen34
sheet['H3'] = geoLen5
sheet['D4'] = owLen12
sheet['F4'] = owLen34
sheet['H4'] = owLen5
sheet['D5'] = rdmCnt12
sheet['F5'] = rdmCnt34
sheet['H5'] = rdmCnt5
sheet['D6'] = geoLen12
sheet['F6'] = geoLen34
sheet['H6'] = geoLen5
sheet['B13'] = count_dr_int
# Saving file to Working_folder
try:
arcpy.AddMessage("Selection saved in {0}_calc_dr_selection.xlsx (in Working_folder)".format(testcode))
dr_selection_temp.save(working_f + '\\' + testcode + '_calc_dr_selection.xlsx')
p = Popen(working_f + '\\' + testcode + '_calc_dr_selection.xlsx', shell=True)
except:
arcpy.AddError(testcode + "_calc_dr_selection.xlsx is already open. Close it first before running the tool")
sys.exit()
... View more
11-12-2018
04:38 AM
|
0
|
0
|
1438
|
Title | Kudos | Posted |
---|---|---|
1 | 12-06-2018 06:04 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|