|
POST
|
'DeleteIdentical' is being applied to a specific feature layer in each case. I'm wondering if converting that 'SubLayer_pp_trans_GUJoin_UniqueSubs' feature class to a feature layer multiple times is somehow the culprit? Digging into it now...
... View more
07-13-2017
07:14 AM
|
0
|
7
|
2992
|
|
POST
|
Makes sense. I'll keep that in mind and will be sure to pay a bit more attention to where I am posting. Thanks again, and sorry about that!
... View more
07-12-2017
01:58 PM
|
0
|
2
|
2868
|
|
POST
|
Thanks for the suggestion. I projected the datasets being used to USA Contigous Albers Equal Area (linear unit: meters) and adjusted the search distance to an appropriate value in meters. However, this did not seem to affect the final output. After a bit more digging, it turns out that the spatial join is producing the correct output, though that feature class is 'losing records' throughout the rest of the script. The number of records is included as the printed integer in the screenshot below: Here is the structure of the code following the spatial join (beginning with Null/Zero line count): ###################################### Line Count 1000 #######################
#add in Line_Count_1000 field
arcpy.AddField_management(subLayer, "Line_Count_1000", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
#where clause
where_1000 = ' "VOLTAGE" = 1000 '
Join_1000_voltage_freq = defaultGdbPath + '\Join_1000_voltage_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinLineCountVoltage_1000", where_1000)
arcpy.Frequency_analysis("JoinLineCountVoltage_1000", Join_1000_voltage_freq, ["SUBID"])
search_feats_unique_voltage_1000 = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_1000_voltage_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","Line_Count_1000"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_unique_voltage_1000.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("Line_Count_1000 Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
########################## NULL or Zero Line Count ##################
#add in NULL_ZERO_LINE_COUNT field
arcpy.AddField_management(subLayer, "NULL_ZERO_LINE_COUNT", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
#where clause
NULL_ZERO_Voltage = ' "VOLTAGE" is NULL or "VOLTAGE" = 0 '
Join_null_zero_voltage_freq = defaultGdbPath + '\Join_null_zero_voltage_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinLineCount_Null_Zero_Voltage", NULL_ZERO_Voltage)
arcpy.Frequency_analysis("JoinLineCount_Null_Zero_Voltage", Join_null_zero_voltage_freq, ["SUBID"])
search_feats_null_zero_voltage = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_null_zero_voltage_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","NULL_ZERO_LINE_COUNT"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_null_zero_voltage.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("NULL_ZERO_LINE_COUNT Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
############################### PP_Line Count ##########################
#add in PP_LINE_COUNT field
arcpy.AddField_management(subLayer, "PP_LINE_COUNT", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
search_feats_PP_LINE_COUNT = {f[0]:f[1] for f in arcpy.da.SearchCursor(SubLayer_pp_trans_GUJoin,["SUBID","Join_Count"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","PP_LINE_COUNT"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_PP_LINE_COUNT.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("PP_LINE_COUNT Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
#################################### Generating Unit Count #############################
where_GU = ' "GEN_UNITS" > 0 '
#add in GU_COUNT field
arcpy.AddField_management(subLayer, "GU_COUNT", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
search_feats_GU_COUNT = {f[0]:f[1] for f in arcpy.da.SearchCursor(SubLayer_pp_trans_GUJoin,["SUBID","GEN_UNITS"], where_GU)}
with arcpy.da.UpdateCursor(subLayer,["SUBID","GU_COUNT","PP_Line_Count"]) as upd_cur:
for upd_row in upd_cur:
#if int(upd_row[2]) > 0:
if upd_row[2] is not None and int(upd_row[2]) > 0:
#if search_feats_GU_COUNT[1] > 0 and upd_row[2] > 0:
upd_row[1] = search_feats_GU_COUNT.get(upd_row[0], 0)/upd_row[2]
else:
upd_row[1] = 0
upd_cur.updateRow(upd_row)
print("GU_Count Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
############################## PP_COUNT ######################################
#add in PP_COUNT field
arcpy.AddField_management(subLayer, "PP_COUNT", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
search_feats_PP_COUNT = {f[0]:f[1] for f in arcpy.da.SearchCursor(SubLayer_pp_trans_GUJoin,["SUBID","Join_Count_PP"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","PP_COUNT"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_PP_COUNT.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("PP_Count Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
##########################################################################################################
arcpy.AddField_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "SUB1SUB2", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "SUB1SUB2",'!SUB_1! + "," + !SUB_2!', "PYTHON_9.3")
################################ UNIQUE SUBS BY VOLTAGE - 13.8 ########################
arcpy.AddField_management(subLayer, "UNIQUE_SUB_COUNT_13_8", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
Join_13_8_freq = defaultGdbPath + '\Join_13_8_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinUniqueSubs_13_8", where_13_8)
arcpy.DeleteIdentical_management("JoinUniqueSubs_13_8", ['SUBID', 'SUB1SUB2', 'VOLTAGE'])
arcpy.Frequency_analysis("JoinUniqueSubs_13_8", Join_13_8_freq, ["SUBID"])
search_feats_Unique_Subs_13_8 = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_13_8_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","UNIQUE_SUB_COUNT_13_8"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_Unique_Subs_13_8.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("UNIQUE_SUB_COUNT_13_8 Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
################################### UNIQUE SUBS BY VOLTAGE - 46 ########################
arcpy.AddField_management(subLayer, "UNIQUE_SUB_COUNT_46", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
Join_46_freq = defaultGdbPath + '\Join_46_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinUniqueSubs_46", where_46)
arcpy.DeleteIdentical_management("JoinUniqueSubs_46", ['SUBID', 'SUB1SUB2', 'VOLTAGE'])
arcpy.Frequency_analysis("JoinUniqueSubs_46", Join_46_freq, ["SUBID"])
search_feats_Unique_Subs_46 = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_46_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","UNIQUE_SUB_COUNT_46"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_Unique_Subs_46.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("UNIQUE_SUB_COUNT_46 Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
######################################### UNIQUE SUBS BY VOLTAGE - 69 ########################
arcpy.AddField_management(subLayer, "UNIQUE_SUB_COUNT_69", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
Join_69_freq =defaultGdbPath + '\Join_69_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinUniqueSubs_69", where_69)
arcpy.DeleteIdentical_management("JoinUniqueSubs_69", ['SUBID', 'SUB1SUB2', 'VOLTAGE'])
arcpy.Frequency_analysis("JoinUniqueSubs_69", Join_69_freq, ["SUBID"])
search_feats_Unique_Subs_69 = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_69_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","UNIQUE_SUB_COUNT_69"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_Unique_Subs_69.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("UNIQUE_SUB_COUNT_69 Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
#################################################### UNIQUE SUBS BY VOLTAGE - 115 ########################
arcpy.AddField_management(subLayer, "UNIQUE_SUB_COUNT_115", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
Join_115_freq =defaultGdbPath + '\Join_115_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinUniqueSubs_115", where_115)
arcpy.DeleteIdentical_management("JoinUniqueSubs_115", ['SUBID', 'SUB1SUB2', 'VOLTAGE'])
arcpy.Frequency_analysis("JoinUniqueSubs_115", Join_115_freq, ["SUBID"])
search_feats_Unique_Subs_115 = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_115_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","UNIQUE_SUB_COUNT_115"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_Unique_Subs_115.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("UNIQUE_SUB_COUNT_115 Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
#################################################### UNIQUE SUBS BY VOLTAGE - 138 ########################
######################################## UNIQUE_SUBS_COUNT ########################
arcpy.AddField_management(subLayer, "UNIQUE_SUBS_COUNT", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
Join_all_freq =defaultGdbPath + '\Join_all_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinUniqueSubs_all",)
arcpy.DeleteIdentical_management("JoinUniqueSubs_all", ['LATITUDE', 'LONGITUDE', 'SUB1SUB2'])
arcpy.Frequency_analysis("JoinUniqueSubs_all", Join_all_freq, ["SUBID"])
search_feats_Unique_Subs_all = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_all_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","UNIQUE_SUBS_COUNT"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_Unique_Subs_all.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("UNIQUE_SUBS_COUNT Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
#### additonal Unique Sub Count segments of the code have been omitted for breity #####
################################################# UNIQUE VOLTAGE COUNT ###################################
arcpy.AddField_management(subLayer, "UNIQUE_VOLTAGE_COUNT", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
Join_voltage_freq = defaultGdbPath + '\Join_voltage_freq'
# Make feature layer
arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "JoinUniqueVoltage",)
arcpy.DeleteIdentical_management("JoinUniqueVoltage", ['VOLTAGE','SUBID'])
arcpy.Frequency_analysis("JoinUniqueVoltage", Join_voltage_freq, ["SUBID"])
search_feats_Unique_Voltage = {f[0]:f[1] for f in arcpy.da.SearchCursor(Join_voltage_freq,["SUBID","Frequency"])}
with arcpy.da.UpdateCursor(subLayer,["SUBID","UNIQUE_VOLTAGE_COUNT"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats_Unique_Voltage.get(upd_row[0], 0)
upd_cur.updateRow(upd_row)
print("UNIQUE_VOLTAGE_COUNT Updated")
del upd_cur
RecordCount = arcpy.GetCount_management(SubLayer_pp_trans_GUJoin_UniqueSubs)
count = int(RecordCount.getOutput(0))
print(count)
end = time.time()
print((end - start)/60)
#if __name__ == '__main__':
# entry() Any ideas on how the feature class may be losing records? Thanks!
... View more
07-12-2017
12:41 PM
|
0
|
9
|
2992
|
|
POST
|
Agreed. For some reason, I do not have the 'Mark as Correct' option. I am viewing the discussion in All Places > Developers > GIS Developers > Python > Discussions in Chrome. I have also tried accessing it from both the email notification link and from my profile. I am logged in. I also referred to this document, and the button is not showing up on my discussion screen as shown. ...I don't remember the button not showing up for past discussions and have used it frequently in the past. Maybe I'm missing something. I apologize for any inconveniences.
... View more
07-12-2017
10:53 AM
|
0
|
4
|
2868
|
|
POST
|
I am trying to perform a spatial join that will join all my join features (along with their attributes), within a specified distance, to my target features. Given the nature of the datasets, this should more than double the number of records in the target feature class (taking into account that not all of the join features are within the specified search radius). However, this join appears to rarely be functioning accurately. My target feature class consists of ~7000 records and when joined accurately via a 'JOIN_ONE_TO_MANY', 'KEEP_ALL' spatial join contains ~16000 records. However, at least ~90% of the time the spatial join produces just under 8000 records. This has been frustrating, as this join is an integral part of a long script, and incorrect joins propagate into subsequent calculations. I am able to get the spatial join tool to run correctly using the same layers and options in ArcMap 10.4 or in ArcPro 1.4. Though, the python script seems to be producing unreliable results when ran in Visual Studio leveraging arcpy.SpatialJoin_analysis. The script was originally using Python 2 and ArcGIS 10.4. I switched to Python 3 (3.5.2) using a fresh Conda 3 download and the ArcPro Python package hoping that if the tool was buggy, this may fix it. No luck. Does anyone have any recommendations? Here is the line of code for the spatial join: arcpy.SpatialJoin_analysis ("SubLayer_Layer_2", "pp_trans_GUJoin_Layer_2", SubLayer_pp_trans_GUJoin_UniqueSubs, 'JOIN_ONE_TO_MANY', 'KEEP_ALL', "#", 'WITHIN_A_DISTANCE', .000002)
... View more
07-11-2017
12:12 PM
|
0
|
11
|
4427
|
|
POST
|
This seemed to do the trick. Thanks! arcpy.CalculateField_management(SubLayer_pp_trans_GUJoin_UniqueSubs, "SUB1SUB2",'!SUB_1! + "," + !SUB_2!', "PYTHON_9.3")
... View more
07-11-2017
11:29 AM
|
0
|
6
|
2868
|
|
POST
|
I did switch from ArcMap to Pro. It sounds like Python expressions would be best. Makes sense. Thanks!
... View more
07-11-2017
10:34 AM
|
0
|
0
|
2868
|
|
POST
|
After updating a script from Python 2 to Python 3, I am now getting an 'ERROR 00539: Indentation Error: Unexpected indent <<expression>, line 1' on a line in my script. The line is not indented, and I tried removing all spaces and also re-adding spaces (ensuring no tabs were used). I am not sure where the error is. The line ran without error using Python 2. This is the original line: arcpy.CalculateField_management (SubLayer_pp_trans_GUJoin_UniqueSubs, "SUB1SUB2", ' [SUB_1] + "," + [SUB_2] ') I've tried: arcpy.CalculateField_management(SubLayer_pp_trans_GUJoin_UniqueSubs,"SUB1SUB2",' !SUB_1! +","+ !SUB_2! ') and (and various renditions of removing spaces) arcpy.CalculateField_management(SubLayer_pp_trans_GUJoin_UniqueSubs,"SUB1SUB2",' [SUB_1] + "," + [SUB_2] ') with no luck. Any suggestions? Thanks!
... View more
07-11-2017
10:15 AM
|
0
|
10
|
5170
|
|
POST
|
Any ideas on ways to select line features that have an endpoint/node within a distance of a point feature class? I have been using arcpy.SpatialJoin_analysis and arcpy.SelectLayerByLocation_management to achieve selecting all lines that fall within a specified distance of a point feature class; though, I want to make sure I do not capture lines that may fall within the search radius of a point but do not have and endpoint within the same search radius (e.g. just passing nearby within the search radius). I don't see this type of selection as a built in function for either arcpy.SpatialJoin_analysis or arcpy.SelectLayerByLocation_management, but I may have missed something. This would be a very useful functionality if it exists.
... View more
06-12-2017
02:55 PM
|
0
|
3
|
1982
|
|
POST
|
Thanks! This totally helps. The following ended up doing the trick and replaces lines 13-16. upd_row[1] = search_feats_13_8.get(upd_row[0], 0)
... View more
06-06-2017
12:21 PM
|
0
|
0
|
659
|
|
POST
|
I'm new to dictionaries and am still a Python beginner. I'm trying to update field(s) based off of field values in another table using the OID field as a key. The search cursor dictionary has been filtered down (in an effort to conditionally update the values in the Line_Count_13_8 field) with a where clause for the portion of the script where I am receiving an error. I am getting a KeyError: [0] error on this line: if search_feats_138[0] == upd_row[0]: Here is the whole block: import arcpy
from arcpy import env
import time
start = time.time()
print start
print "Start"
arcpy.env.OverwriteOutput = True
subLayer='C:\Topo_Check_Tess_V5.gdb\Sub'
transLayer='C:\Topo_Check_Tess_V5.gdb\TL'
ppLayer='C:\Topo_Check_Tess_V5.gdb\PP'
pp_trans_GUJoin ='C:\Topo_Check_Tess_V5.gdb\pp_trans_GU_SpatialJoin'
SubLayer_pp_trans_GUJoin = 'C:\Topo_Check_Tess_V5.gdb\SubLayer_pp_trans_GUSpatialJoin'
arcpy.SpatialJoin_analysis ("SubLayer_Layer", "pp_trans_GUJoin_Layer", SubLayer_pp_trans_GUJoin, 'JOIN_ONE_TO_ONE', 'KEEP_ALL', fieldMappings, 'WITHIN_A_DISTANCE', .000002) This section works: #add in Line_Count field
arcpy.AddField_management(subLayer, "Line_Count", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
search_feats = {f[0]:f[1] for f in arcpy.da.SearchCursor(SubLayer_pp_trans_GUJoin,["OBJECTID","Join_Count"])}
with arcpy.da.UpdateCursor(subLayer,["OBJECTID","Line_Count"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats[upd_row[0]]
upd_cur.updateRow(upd_row)
print "Line_Counts Updated"
del upd_cur This section does not work - KeyError: [0] on line 13: #add in Line_Count_13_8 field
arcpy.AddField_management(subLayer, "Line_Count_13_8", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
#where clause
where_13_8 = ' "VT" = 13.8 '
#arcpy.MakeFeatureLayer_management(SubLayer_pp_trans_GUJoin, "Sub_PP_Trans_Join_13_8", where_13_8)
search_feats_13_8 = {f[0]:f[1] for f in arcpy.da.SearchCursor(SubLayer_pp_trans_GUJoin,["OBJECTID","Join_Count"], where_13_8)}
with arcpy.da.UpdateCursor(subLayer,["OBJECTID","Line_Count_13_8"]) as upd_cur:
for upd_row in upd_cur:
if search_feats_13_8[0] == upd_row[0]:
upd_row[1] = search_feats_13_8[upd_row[0]]
else:
upd_row[1] = 0
upd_cur.updateRow(upd_row)
print "Line_Count_13.8 Updated"
del upd_curl
end = time.time()
print (end - start)/60 Any suggestions? Thanks in advance!
... View more
06-06-2017
09:20 AM
|
0
|
2
|
1189
|
|
POST
|
I am trying to update a field (UNIQUE_SUB_COUNT_13_8) in a (point) feature class (e.g. subLayer) using attributes and spatial relationships to another (line) feature class. For this, I'm currently leveraging arcpy tools, selections, and an update cursor. This section is currently taking over 30 minutes to run. The subLayer feature class contains 7000 records and transLayer contains 7500 records; so these aren't massive feature classes, though they are continually growing as they are developed. Any suggestions on how to optimize this code? I do want to update each row with a value specific to that row. I am wondering if indexing or dictionaries may be of value. A spatial join may also be a better route. However, this script is part of an over a 1000 line script with similar block structures as this for many varying field updates based on varying attribute and spatial relationships among three feature classes (included here for reference: Optimizing a Script Using Python Cursors and Dictionaries ). It would be helpful if the search distance and attribute parameters in the selections can be easily modified. The script was originally built largely utilizing Model Builder and was highly dependent on spatial joins. I have been trying to move to a more streamlined and optimized script that can be more easily edited and adaptive to changes within the source datasets. So far the new script has all the functionality of the model builder code, but is MUCH slower. This section of the script seems like a good place to start with optimization. I will appreciate any tips anyone may have! Thanks! import arcpy
from arcpy import env
import time
start = time.time()
arcpy.env.OverwriteOutput = True
defaultGdbPath = 'C:\Topo_Check_V5.gdb'
subLayer='C:\Topo_Check_V5.gdb\Subs' #point feature class
transLayer='C:\Topo_Check_V5.gdb\TLS' # line feature class
ppLayer='C:\Topo_Check_V5.gdb\PPS' #point feature class
#######################################################################
#add in UNIQUE_SUB_COUNT_13_8 field
arcpy.AddField_management(subLayer, "UNIQUE_SUB_COUNT_13_8", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
UNIQUE_SUB_COUNT_13_8 = "UNIQUE_SUB_COUNT_13_8"
# Make feature layer
arcpy.MakeFeatureLayer_management(transLayer, "transLayer_uniquesubs")
arcpy.AddField_management("transLayer_uniquesubs", "SUB1SUB2", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management ("transLayer_uniquesubs", "SUB1SUB2", ' [SUB_1] + "," + [SUB_2] ')
#where clause
where_unique_13_8 = ' "VLTS" = 13.8 '
result=int(arcpy.GetCount_management("transLayer_uniquesubs").getOutput(0))
with arcpy.da.UpdateCursor (subLayer, [UNIQUE_SUB_COUNT_13_8, "SHAPE@"]) as UNIQUE_SUB_COUNT_13_8_List:
for subrow in UNIQUE_SUB_COUNT_13_8_List:
arcpy.SelectLayerByLocation_management("transLayer_uniquesubs", 'WITHIN_A_DISTANCE', subrow[1], .000002, "NEW_SELECTION")
arcpy.SelectLayerByAttribute_management ("transLayer_uniquesubs", "SUBSET_SELECTION", where_unique_13_8)
arcpy.DeleteIdentical_management("transLayer_uniquesubs", ['SUB1SUB2'])
subrow[0] = result
UNIQUE_SUB_COUNT_13_8_List.updateRow(subrow)
print "UNIQUE_SUB_COUNT_13_8 Updated"
########################################################################
end = time.time()
print (end - start)/60
... View more
05-23-2017
12:28 PM
|
0
|
0
|
826
|
|
POST
|
Thanks. Maybe going back to spatial joins will end up being more efficient. I was hoping to maybe optimize the cursor route. Thanks for bearing with me. I really appreciate the advice.
... View more
05-19-2017
08:26 AM
|
1
|
0
|
810
|
|
POST
|
Hmm, this seems to start but never finishes. I must be missing something. Thanks again for your help. import arcpy
from arcpy import env
import time
start = time.time()
arcpy.env.OverwriteOutput = True
defaultGdbPath = 'C:\Topo_Check_V5.gdb'
subLayer='C:\Topo_Check_V5.gdb\Subs' #point feature class
transLayer='C:\Topo_Check_V5.gdb\TLS' # line feature class
ppLayer='C:\Topo_Check_V5.gdb\PPS' #point feature class
#add in Line_Count field
arcpy.AddField_management(subLayer, "Line_Count", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
#TLineCountField = "Line_Count"
IDs = []
with arcpy.da.SearchCursor(transLayer, ['OBJECTID']) as cursor:
for row in cursor:
IDs.append(row[0])
with arcpy.da.UpdateCursor (subLayer, ["Line_Count"]) as LineCountList:
for subrow in LineCountList:
for i in IDs:
arcpy.MakeFeatureLayer_management(transLayer, "transLayer_lyr", """OBJECTID = %s""" %i)
arcpy.SelectLayerByLocation_management("transLayer_lyr", 'WITHIN_A_DISTANCE', subLayer, .000002, "NEW_SELECTION")
result=int(arcpy.GetCount_management("transLayer_lyr").getOutput(0))
#print result
subrow[0] = result
LineCountList.updateRow(subrow)
arcpy.Delete_management("transLayer_lyr")
print "Line_Count Updated"
del LineCountList
del cursor
end = time.time()
print (end - start)/60
... View more
05-16-2017
01:45 PM
|
0
|
2
|
810
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-19-2018 11:46 AM | |
| 1 | 04-10-2018 03:47 PM | |
| 1 | 10-01-2018 08:50 AM | |
| 1 | 02-15-2017 07:50 AM | |
| 1 | 10-19-2018 04:08 PM |
| Online Status |
Offline
|
| Date Last Visited |
09-22-2025
08:12 AM
|