BLOG
|
This information has been very helpful, Thanks Richard. I replaced a Join Field process that was taking ~40 minutes with arcpy.da.TableToNumPyArray and arcpy.da.ExtendTable which now completes in 6 seconds. I wonder why the standard tools aren't implemented with this faster performing module?
... View more
03-30-2015
11:30 AM
|
2
|
0
|
19119
|
POST
|
Arcpy.mapping parameters can't be skipped with empty quotes. In Python, if you want to skip parameters, you must call out the parameter name and set it appropriately. Once you do that, all subsequent parameters must be set the same way. Jeff Forgive me, as I'm not a programmer and my experience comes from coding with ArcGIS 9.x, but that seems to be inconsistant. Within my code I have defined variables for the first three parameters and don't specifically call them (i.e., map_document = mxd, out_png = out_png1, {data_frame} = "PAGE_LAYOUT"). The original code used empty quotes so that I wouldn't be skipping parameters, but keeping optional parameters blank. The sixth parameter I did want to set, but to get it to work I needed to call the parameter by name like Jim and you have indicated. So that I understand the logic better, why is it not required to call the first three parameters when setting their values? Is it becasue parameters 1 and 2 are required and 3 on are optional?
... View more
04-12-2013
09:21 AM
|
0
|
0
|
452
|
POST
|
Thanks Jim, That seemed to fix the error. I didn't realize that some parameters require keywords even when setting up the place holders for all parameters within a function.
... View more
04-11-2013
10:05 AM
|
0
|
0
|
452
|
POST
|
I'm using ArcGIS 10.0 sp5 on a Win7 PC and need help with a script to turn layers on/off and export the page layout to an image file. The script works until the ExportToPNG(). I have 281 layers with up to 10 attributes I have to map (static extent) so scripting the arduous task of changing each layers visibility is preferred. I have a VBA tool to change the symbology between the 10 attributes of selected layers and now I'd like to take advantage of the arcpy.mapping functionalities. import os, sys, string, arcpy # define list of species spLst = ['0070','1320'] try: mxd = arcpy.mapping.MapDocument(r"C:/Workspace/Species.mxd") # check for broken paths brknList = arcpy.mapping.ListBrokenDataSources(mxd) if len(brknList) >= 1: print "Broken Paths Exist..." + brknList else: for sp in spLst: print "No broken paths, proceeding" lyrName = "ew20km_in" + str(sp) + "_2040" lyrList = arcpy.mapping.ListLayers(mxd, lyrName) for lyr in lyrList: # define variables out_png1 = r"C:/Workspace/pixels_500/rfbird_" + str(sp) + "_2040.png" out_png2 = r"C:/Workspace/pixels_800/rfbird_" + str(sp) + "_2040.png" resolution1 = 45 resolution2 = 72 lyr.visible = True # make layer visible, all other species should start as invisible arcpy.RefreshTOC() arcpy.RefreshActiveView() # export current layout view to png file # ExportToPNG (map_document, out_png, {data_frame}, {df_export_width}, {df_export_height}, {resolution}, {world_file}, {color_mode}, {background_color}, {transparent_color}, {interlaced}) arcpy.mapping.ExportToPNG(mxd, out_png1, "PAGE_LAYOUT", "", "", resolution1, "", "24-BIT_TRUE_COLOR", "", "", "") arcpy.mapping.ExportToPNG(mxd, out_png2, "PAGE_LAYOUT", "", "", resolution2, "", "24-BIT_TRUE_COLOR", "", "", "") lyr.visible = False except: arcpy.AddMessage(arcpy.GetMessages(2)) print arcpy.GetMessages (2) print "Exited with Errors.... Something is wrong"
... View more
04-11-2013
06:54 AM
|
0
|
4
|
777
|
POST
|
Try this - use 'NO' within triple-quotes. SOLUTION: Based on Jose suggestion I changed the "PYTHON_9.3" to "VB" and left the new field value alone (eg, "\"NO\"") which uses python syntax. Thanks for the help.
... View more
11-07-2011
10:44 AM
|
0
|
0
|
296
|
POST
|
Try this - use 'NO' within triple-quotes. This didn't work; the script kicks out after the first calculate field. I also don't see how this would work as the python syntax shows the """'NO'""" as a comment. Matt : did you tried changing gp.CalculateField_management(Output_Layer, "DISSOLVE", dis_exp, "PYTHON_9.3", "") "PYTHON_9.3" for "VB"? gp.CalculateField_management(Output_Layer, "DISSOLVE", dis_exp, "VB", "") I have tried to use the "VB" option in another script I wrote with a series of if/else statements and since the rest of the script is written in python the gp didn't like the VB code. However I could have written the VB commands wrong.
... View more
11-07-2011
09:50 AM
|
0
|
0
|
296
|
POST
|
I need the help of the online community. I have a series of shapefile (polygons) representing forest cover and want to automate the following: add field, calculate field, select by attribute, select by location, calculate field. I'm using 9.3 and run my scripts with cygwin. I have been able to implement everything except the calculate fields. The script runs and kicks out after the calculate field (line 37) with no errors. Any help is greatly appreciated as I'm not a programmer and I have tried suggestions from other posts and ESRI help docs. # ArcMap 9.3
# Import system modules
import sys, string, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
gp.loghistory = False
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
#Set the input workspace where the files are to be processes are located
gp.Workspace = "C:\\Data\\ForConnect\\TEST"
try:
#List all feature classes and load the first one
fcs = gp.ListFeatureClasses()
fcs.reset()
fc = fcs.Next()
gp.overwriteoutput = 1
while fc:
Output_Layer = fc[:-4] + "_lyr"
print "Making feature layer: " + fc
# Process: Make Feature Layer...
gp.MakeFeatureLayer_management(fc, Output_Layer, "", "", "")
print "Adding fields: DISSOLVE and PROCESSED "
# Process: Add Field
gp.addfield(Output_Layer, "DISSOLVE", "TEXT", "", "", "20", "", "", "", "")
gp.addfield(Output_Layer, "PROCESSED", "TEXT", "", "", "5", "", "", "", "")
print "Calculating field: " + Output_Layer + "$PROCESSED "
# Process: Calculate Field
gp.CalculateField_management(Output_Layer, "PROCESSED", "\"NO\"", "PYTHON_9.3", "")
print "creating search cursor " + fc
rows = gp.searchcursor(fc, "", "", "", "")
row = rows.next() # get the first record
i = 1
while row:
rowid = row.ID
sba_exp = "\"ID\" = " + str(rowid) + " AND \"PROCESSED\" = \'NO\'"
dis_exp = str(int(row.ID)) + "_" + str(i)
print "Selecting records where " + sba_exp
# Process: Select Layer By Attribute...
gp.SelectLayerByAttribute_management(Output_Layer, "NEW_SELECTION", sba_exp) # selection type {NEW_SELECTION | ADD_TO_SELECTION | REMOVE_FROM_SELECTION | SUBSET_SELECTION | SWITCH_SELECTION | CLEAR_SELECTION}
print "Selecting records that touch the record of focus "
gp.SelectLayerByLocation(Output_Layer, "BOUNDARY_TOUCHES", Output_Layer, "", "ADD_TO_SELECTION")
gp.SelectLayerByLocation(Output_Layer, "BOUNDARY_TOUCHES", Output_Layer, "", "ADD_TO_SELECTION")
gp.SelectLayerByLocation(Output_Layer, "BOUNDARY_TOUCHES", Output_Layer, "", "ADD_TO_SELECTION")
# Process: Calculate Field
print "Calculating field: DISSOLVE " + dis_exp
gp.CalculateField_management(Output_Layer, "DISSOLVE", dis_exp, "PYTHON_9.3", "")
print "Calculating fields: PROCESSED "
gp.CalculateField_management(Output_Layer, "PROCESSED", "\"YES\"", "PYTHON_9.3", "")
i = i + 1
row = rows.next()
fc = fcs.next()
except:
gp.AddMessage(gp.GetMessages(2))
print gp.GetMessages (2)
print chr(7)
print "Exited with Errors.... Something is wrong",printime()
print 'Script has finished'
... View more
11-07-2011
05:45 AM
|
0
|
4
|
422
|
Title | Kudos | Posted |
---|---|---|
2 | 03-30-2015 11:30 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|