BLOG
|
Can you update this post for instructions using ArcGIS Pro?
... View more
12-06-2023
11:53 AM
|
0
|
0
|
362
|
POST
|
I have a Python script that executes a reclassification without issue. I can see in my output directory the file I create (called tanaka.tif). When I add these data to an ArcGIS Pro v3 project the file is listed in the contents pane as Reclass_tanakat1.tif. This is annoying. When I am in the Catalog pane and view the files properties I see no reference to or an alias for Reclass_tanakat1.tif. This also happens with a resulting hillshade. I get HillSha_tanaka.tif in the Pro contents when the file is named tanakaHS.tif in the directory. I see that there is no reference to these file names using gdal.Info() but I can see them in some resulting xml files that are exported by arcpy. I suppose the is the result of my missery. I do not need or want these outputs. How do I stop arcpy from outputting xml, tfw, CPG, dbf files. I only need the resulting geoTiff! This post suggests that setting log history to false will prevent xml create but this is not true as the xml are still being created with the linked code added to the script. https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/setloghistory.htm
... View more
11-08-2023
01:21 PM
|
0
|
0
|
186
|
POST
|
I have a Python scripting tool that will auto-export a layout to PDF or JPG, update a text box with the export YYMMDDHHMMSS, and log who-what-where-when info to a CSV file. I have been using this code in ArcGIS for years and recently upgraded the tool to work with Pro. Oddly, the Pro tool works just fine when executed from the Toolbox section of the Catalog View but fails at line 50 when executed from a Catalog Pane. Why would this be the case? Here is the error message: PYTHON ERRORS:
Traceback info:
File "Z:\GISpublic\GerryG\Python3\SuperSaverArcPro\A1-SuperSaver.atbx#Script_supersaver.py", line 51, in <module>
Error Info:
'NoneType' object has no attribute 'listElements' and here is the offending code: mapnumber = get_time()
#Get the name of the active map view....
view = aprx.activeView
ele = view.listElements("TEXT_ELEMENT", "mapnumber")[0]
#assign the mapnumber to the map....
ele.text = mapnumber Here is a link to the tool and the code: https://github.com/LummiGIS/Auto-Export-Pro-Layout
... View more
11-07-2023
10:07 AM
|
0
|
1
|
272
|
POST
|
This Python code seems to work just fine. There are heaps of possible contingencies with polygons so any errors would interest me. https://github.com/LummiGIS/Four-Color-Map-For-GIS
... View more
10-04-2023
08:14 AM
|
0
|
0
|
111
|
POST
|
I have the same issue but I get this at the command line: conda config --remove channels conda-forge 'conda' is not recognized as an internal or external command, operable program or batch file.
... View more
06-02-2023
07:31 AM
|
0
|
2
|
446
|
POST
|
Yes, adding the make feature layer and turning off the logging vastly improved code preformance.
... View more
01-08-2022
01:06 PM
|
0
|
0
|
1831
|
POST
|
Turning off geoprocessing logging is always a good idea to keep your CITRIX profile small. As far as code execution goes I am running this as a stand-alone Python script in WingIDE. ArcGIS Pro is not actively running.
... View more
01-07-2022
06:35 PM
|
0
|
2
|
1862
|
POST
|
Should I delete the feature layer for each selection after it has executed the code for that selection or just keep reassigning the variable each time the code makes a new feature layer?
... View more
01-07-2022
03:46 PM
|
0
|
0
|
1873
|
POST
|
Thanks, I am running the code in a Python IDE and not in a Python window in ArcGIS Pro. I am assuming there is no geoprocessing logging happening. Is this correct or is geoprocessing logging a basic function in arcpy?
... View more
01-07-2022
03:42 PM
|
0
|
0
|
1877
|
POST
|
This python script selects groups of data on specific days, processes those data, and selects another group of data to process. The code executes quickly when first executed. As the code chugs along it gets slower and slower. There are no nested cursors, no nested loops - just selections and data processing. Why is code execution getting slower over time? Any tips or tricks for preventing this type of slowdown is appreciated. import sys
import traceback
import os
import shutil
import arcpy
import shapefile
try:
arcpy.env.overwriteOutput = True
#The input shapefile...
in_fc = r"C:\GIS\telemetrytags\projected_data\telemetryUTM.shp"
#An empty directory to store the geometric average outputs
out_dir = r'C:\GIS\telemetrytags\individual_fish_individual_days'
#For the first cursor only these fields are needed...
fields = ['TagID', 'Date']
#A list to hold all of the tag ids...
tag_ids = []
#A list to hold the survey dates
ping_dates = []
#Iterate the shapefile and get a list of all unique dates and a list of all unique tags.
with arcpy.da.SearchCursor(in_fc, fields) as cursor:
for row in cursor:
if row[0] not in tag_ids:
tag_ids.append(row[0])
if row[1] not in ping_dates:
ping_dates.append(row[1])
#Do you need to delete row now with python 3? Doing so did not speed up the code which lags over time...
del row
#This is the field list for populating the rest of the attribute table of the mean center files...
fields = ['Origin','Stock','Sex','FL','Destinatio', 'Mortality_']
#Build the query to select individual tags on individual days...
for tag in tag_ids:
for ping in ping_dates:
#Build the query...
query = '\"TagID\" = ' + str(int(tag)) + ' And \"Date\" = timestamp ' +'\'' + str(ping).split(' ')[0] +'\''
print(query)
#Select all those tags on that particular day...
this_fish, ping_count = arcpy.management.SelectLayerByAttribute(in_fc, selection_type="NEW_SELECTION", where_clause=query)
print('ping return count = ', ping_count)
#If a fish was not found on a particular day then ignore that selection...
if ping_count == 0:
pass
#If there is only one ping then just rename the original file and move it to the out_dir.
if int(ping_count) == 1:
out_fc = out_dir + "\\" + str(int(tag)) + '_' + str(ping).split(' ')[0] + '.shp'
arcpy.CopyFeatures_management(this_fish, out_fc)
#Clean up that table for the final merging of shapefiles...
arcpy.DeleteField_management(out_fc, ['MEAS','Pos_ft','CumPos_ft','Pos_RM','CumPos_RM','Time','Channel','Antenna','Power','Latitude','Longitude','NEAR_FID','NEAR_DIST','NEAR_X','NEAR_Y','Data_Inclu'])
#More that one ping on a given day needs to be averaged...
if int(ping_count) > 1:
#Build the output file and path for the averaged data...
out_fc = out_dir + "\\" + str(int(tag)) + '_' + str(ping).split(' ')[0] + '.shp'
date = str(ping).split(' ')[0]
#Create the mean center file based on the geospatial locations...
arcpy.stats.MeanCenter(this_fish, out_fc, Weight_Field='Power')
#The mean center operation output does not preserve attributes. Create them now...
arcpy.AddField_management(out_fc, 'TagID', "SHORT")
arcpy.AddField_management(out_fc, 'Date_', "TEXT", field_length='12')
arcpy.AddField_management(out_fc, 'Origin', "TEXT", field_length='3')
arcpy.AddField_management(out_fc, 'Stock', "TEXT", field_length='20')
arcpy.AddField_management(out_fc, 'Sex', "TEXT", field_length='1')
arcpy.AddField_management(out_fc, 'FL', "SHORT")
arcpy.AddField_management(out_fc, 'Destinatio', "TEXT", field_length='10')
arcpy.AddField_management(out_fc, 'Mortality_', "TEXT", field_length='20')
#These values are all the same between records, get the values to populate the out_fc...
with arcpy.da.SearchCursor(this_fish, fields) as cursor:
for row in cursor:
Origin = row[0]
Stock = row[1]
Sex = row[2]
FL = int(row[3])
Destinatio = row[4]
Mortality_ = row[5]
del row
arcpy.CalculateField_management(out_fc, 'TagID', int(tag), "PYTHON3")
arcpy.CalculateField_management(out_fc, 'Date_', "'"+ date +"'", "PYTHON3")
arcpy.CalculateField_management(out_fc, 'Origin', "'"+Origin+"'", "PYTHON3")
arcpy.CalculateField_management(out_fc, 'Stock', "'"+Stock+"'", "PYTHON3")
arcpy.CalculateField_management(out_fc, 'Sex', "'"+Sex+"'", "PYTHON3")
arcpy.CalculateField_management(out_fc, 'FL', FL, "PYTHON3")
arcpy.CalculateField_management(out_fc, 'Destinatio', "'"+Destinatio+"'", "PYTHON3")
arcpy.CalculateField_management(out_fc, 'Mortality_', "'"+Mortality_+"'", "PYTHON3")
except Exception:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
... View more
01-07-2022
03:26 PM
|
0
|
9
|
1894
|
POST
|
I have a ArcGIS Pro v2.8 stand-alone Python script. This script create a new shapefile via the mean center tool. I use python to add a new field to this mean center output as a type short. After viewing the resulting shapefile in ArcGIS Pro I see that the attribute table is showing my TagID attribute but ArcGIS Pro is referring to the attribute as a long! I can confirm that QGIS 3.10 shows the TagID as an integer. I can confirm that I can populate the attribute table with a numeric value in both QGIS and ArcGIS Pro manually. After I try to populate the new attribute with a calculate field I get the following error. ERROR: ArcPy ERRORS: ERROR 160176: The index passed was not within the valid range. Failed to execute (CalculateField). Here is a link to the tool error...160176 error Here is the relevant code: arcpy.AddField_management(out_fc, 'TagID', "SHORT")
tagid = '"TagID"'
value = str(int(tag))
arcpy.CalculateField_management(out_fc, tagid, value, "PYTHON3") Thinking that an AddIndex might save the problem I execute the mean center tool then do an Add Index. This gets me to the CalculateField but passing that crashes arcpy. Why is ArcGIS Pro showing the attribute type as Long? Why am I getting this error? How can I fix the problem?
... View more
01-06-2022
12:22 PM
|
0
|
2
|
503
|
POST
|
I am trying to execute a calculate field in arcpy from ArcGIS Pro 2.7. Here is the relevant code. #a confirmed existing shapefile .... out_fc = r'C:\GIS\telemetrytags\individual_fish_individual_days\112_2019-04-12.shp' # a confirmed and working add field.... arcpy.AddField_management(out_fc, 'TagID', "SHORT") #The existing field name... tagid = "TagID" #The value to populate TagID with...in this case the value of tag is a float (with a value of 112.0) before I #convert it to an int and then string. value = str(int(tag)) #code fails here with the message below. arcpy.CalculateFields_management(out_fc, tagid, value, "PYTHON3") Error Info: Failed to execute. Parameters are not valid. ERROR 000800: The value is not a member of Python 3 | Arcade. ERROR 000728: Field 112 does not exist within table Failed to execute (CalculateFields). 112 is the value I am trying to populate field TagID with and not the field name so I do not understand what is up with that error. Another oddity - when I add my shapefile to ArcGIS pro and check the TagID field it returns that the field is a type Long with is not what I am doing with the calculate field. Why is this 'the most simple of calculations' failing in arcpy for ArcGIS Pro 2.7
... View more
01-06-2022
11:35 AM
|
0
|
1
|
670
|
POST
|
Allan, Yes, my IT department shut down open access to that FTP site. I moved the code and toolbox tool to Github. The link above is now valid.
... View more
03-06-2017
01:06 PM
|
0
|
0
|
2462
|
POST
|
That tool that I created will create a perpendicular line but the "perpendicular line" is perpendicular to an imaginary line that runs from the start node to the end node so some care is required to get what you want. If you want to create perps at specific places why not create a new line file where each line is tangent to your stream course at the intersect of the point locations, buffer the points some reasonable distance, clip the tangent lines so your tangents are centered on the points, then run the perpendicular lines tool creating new perps at the midpoint of your tangent line.
... View more
09-07-2016
11:53 AM
|
0
|
0
|
1327
|
Title | Kudos | Posted |
---|---|---|
1 | 06-12-2012 07:42 AM | |
1 | 06-02-2015 09:53 AM | |
1 | 06-09-2015 09:11 AM | |
1 | 10-23-2014 11:32 AM | |
1 | 09-12-2014 10:19 AM |
Online Status |
Offline
|
Date Last Visited |
Tuesday
|