POST
|
Ugh. Not what I wanted to hear! But thank you for testing it and for your reply!! Amy
... View more
02-07-2012
05:47 AM
|
0
|
0
|
295
|
POST
|
I am trying to write a script in the Tool Validator so that the user can choose one of three options in the first parameter, and based on the user's choice, the other 3 parameters are either enabled or disabled. However, I cannot seem to get it to work properly. Nothing happens in the tool when I change the first parameter. My other 3 parameters are feature sets. The "Add Records Interactively" part is greyed out while the "Use records from" is enabled in all of them. My script is below: class ToolValidator:
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
import arcpy
self.params = arcpy.GetParameterInfo()
print self.params
def initializeParameters(self):
self.params[1].category = "Feature Types"
self.params[2].category = "Feature Types"
self.params[3].category = "Feature Types"
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
return
def updateParameters(self):
if self.params[0].altered:
if self.params[0].value == "Point":
self.params[1].enabled = 1
self.params[2].enabled = 0
self.params[3].enabled = 0
elif self.params[0].value == "Line":
self.params[1].enabled = 0
self.params[2].enabled = 1
self.params[3].enabled = 0
elif self.params[0].value == "Polygon":
self.params[1].enabled = 0
self.params[2].enabled = 0
self.params[3].enabled = 1
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parmater
has been changed."""
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return What am I doing wrong? I'm completely stumped! Thank you in advance for any help! Amy
... View more
02-06-2012
08:52 AM
|
0
|
3
|
399
|
POST
|
Answering my own question.... I changed: if type(elt) == list to: if isinstance(elt, list) and the code worked in the script tool.
... View more
11-30-2011
04:58 AM
|
0
|
0
|
170
|
POST
|
Not quite sure how to phrase this question succinctly... I have a really long code that is working just fine until it gets to a certain point where I am trying to format some list output. The elements of the list will then be used to populate a table in an Access database. I've split the list part of the code out and run it in PythonWin and it works. However, when I run the entire code through the toolbox as a script tool I get this error: 'unicode' object is not callable on this line: finalList = [elt[0] + " (" + elt[1] + ")" if type(elt) == list and elt[0] == "ETSc" else str(elt) for elt in outlist] Is the problem running it through a script tool? And how would I fix it? I can't post the entire code as it is over 300 lines but am posting the relevant part below: #Get ETSc tables
#
obstable = "L:\\Projects\\IFWapplications\\ETSc\\ETSc.mdb\\tblObservation"
LUtable = "L:\\IFW-Data\\ETSc.gdb\\tblSpatialLU"
SpTab = "L:\\Projects\\IFWapplications\\ETSc\\ETSc.mdb\\tblSpecies"
#Create empty lists
ObsIDList = []
SpeciesList = []
ImpactList = []
outlist = []
finalList = []
#Use Cursor to determine if there is an ETSc record
#
try:
HabCur = arcpy.SearchCursor(ProjectSF)
for row in HabCur:
VerId = row.getValue("ERVerID")
ImpactList.append(VerId)
habval = row.getValue("HABTYPE")
if row.HABTYPE == "ETSc":
EtscList = []
outetsclist = []
EtscList.append(habval)
FID = row.getValue("FEATID")
fld = "ShapeID"
whereclause = fld + "=" + "'" + FID + "'"
LUCur = arcpy.SearchCursor(LUtable, whereclause)
for row in LUCur:
obsnum = row.getValue("ObsID")
ObsIDList.append(obsnum)
del LUCur, row
for obs in ObsIDList:
scr = arcpy.SearchCursor(obstable)
for row in scr:
if row.getValue("ObsID") == obs:
sp = row.getValue("Species")
SpeciesList.append(sp)
del scr, row
for species in SpeciesList:
spcur = arcpy.SearchCursor(SpTab)
for row in spcur:
if row.getValue("SciName") == sp:
CommonName = row.getValue("CommonName")
del spcur, row
EtscList.append(CommonName)
for element in EtscList:
if element not in outetsclist:
outetsclist.append(element)
ImpactList.append(outetsclist)
else:
ImpactList.append(habval)
#get a list with unique values
for I in ImpactList:
if I not in outlist:
outlist.append(I)
arcpy.AddMessage(str(outlist))
#format elements in list
finalList = [elt[0] + " (" + elt[1] + ")" if type(elt) == list and elt[0] == "ETSc" else str(elt) for elt in outlist]
... View more
11-29-2011
09:41 AM
|
0
|
1
|
795
|
POST
|
when you join a table, the field names change - Try making the join permanent and using the update cursor (use copy features) on the newly created feature class. When I do this, I lose the two different Shape_Area fields. I need the Shape_Area field from the buffer layer and the Shape_Area field from the habitat layer to do the calculation in the update cursor. Amy
... View more
11-10-2011
10:24 AM
|
0
|
0
|
627
|
POST
|
Thank you. That was a portion of a much larger program. The entire program works pretty well up until the update cursor. I will try your suggestions (some of which I have already done in the program). Thanks for your help! Amy
... View more
11-10-2011
09:55 AM
|
0
|
0
|
627
|
POST
|
IntersectLyr = arcpy.MakeFeatureLayer_management(BufferPoly, "buffpolylyr")
fcList = arcpy.ListFeatureClasses("selfts_*", "Polygon")
for fc in fcList:
desc = arcpy.Describe(fc)
outFC = desc.baseName.strip("selfts_") + "_Intersect"
in_features = [IntersectLyr, fc]
#Perform Intersect between bufferpoly and selected features in each habitat feature class
arcpy.Intersect_analysis(in_features, outFC)
arcpy.AddField_management(outFC, "PERCENTAGE", "Double")
des = arcpy.Describe(outFC)
outFClyr = des.baseName + "lyr"
arcpy.MakeFeatureLayer_management(outFC, outFClyr)
arcpy.AddMessage("The Intersect Layer is: " + str(outFClyr))
arcpy.AddJoin_management(outFClyr, "FID_ProjectRadius", IntersectLyr, "OBJECTID")
fldList = arcpy.ListFields(outFClyr, "*.PERCENTAGE")
for fld in fldList:
percentfld = fld.name
arcpy.AddMessage(fld.name)
fldList2 = arcpy.ListFields(outFClyr, "*.Shape_Area")
for fld in fldList2:
if fld.name == "ProjectRadius.Shape_Area":
arcpy.AddMessage(fld.name)
buffareafld = fld.name
else:
arcpy.AddMessage(fld.name)
areafld = fld.name
cur = arcpy.UpdateCursor(outFClyr)
for row in cur:
buffarea = row.getValue(buffareafld)
habarea = row.getValue(areafld)
row.percentfld = (buffarea/habarea)*100
cur.updateRow(row)
del cur, row
... View more
11-10-2011
09:19 AM
|
0
|
0
|
627
|
POST
|
Ooops! Error in the program I just posted (but not the one I am trying to solve). Here is the correct program: IntersectLyr = arcpy.MakeFeatureLayer_management(BufferPoly, "buffpolylyr") fcList = arcpy.ListFeatureClasses("selfts_*", "Polygon") for fc in fcList: desc = arcpy.Describe(fc) outFC = desc.baseName.strip("selfts_") + "_Intersect" in_features = [IntersectLyr, fc] #Perform Intersect between bufferpoly and selected features in each habitat feature class arcpy.Intersect_analysis(in_features, outFC) arcpy.AddField_management(outFC, "PERCENTAGE", "Double") des = arcpy.Describe(outFC) outFClyr = des.baseName + "lyr" arcpy.MakeFeatureLayer_management(outFC, outFClyr) arcpy.AddMessage("The Intersect Layer is: " + str(outFClyr)) arcpy.AddJoin_management(outFClyr, "FID_ProjectRadius", IntersectLyr, "OBJECTID") fldList = arcpy.ListFields(outFClyr, "*.PERCENTAGE") for fld in fldList: percentfld = fld.name arcpy.AddMessage(fld.name) fldList2 = arcpy.ListFields(outFClyr, "*.Shape_Area") for fld in fldList2: if fld.name == "ProjectRadius.Shape_Area": arcpy.AddMessage(fld.name) buffareafld = fld.name else: arcpy.AddMessage(fld.name) areafld = fld.name cur = arcpy.UpdateCursor(outFClyr) for row in cur: buffarea = row.getValue(buffareafld) habarea = row.getValue(areafld) row.percentfld = (buffarea/habarea)*100 cur.updateRow(row) del cur, row
... View more
11-10-2011
08:19 AM
|
0
|
0
|
627
|
POST
|
Could somebody please tell me what is going wrong with this program? I keep getting an ERROR 999999 for the line with the cursor. But I've checked my syntax, spelling, capitalization, etc. and I can't figure out why it won't work!! I am trying to loop through a list of feature classes, intersect each of them with a buffer polygon, and then join the tables for the resulting intersect layer with the buffer polygon table. Then I need to set the "PERCENTAGE" field in each one to the bufferarea/habitat area * 100. Since it is looping through the list of feature classes, I have to use variable names for the fields. Is this what is clogging it up? I have been struggling with this for a week!!!! Hopefully this will keep the indentation, but here is the part of the program that is choking on the update cursor: IntersectLyr = arcpy.MakeFeatureLayer_management(BufferPoly, "buffpolylyr") fcList = arcpy.ListFeatureClasses("selfts_*", "Polygon") for fc in fcList: desc = arcpy.Describe(fc) outFC = desc.baseName.strip("selfts_") + "_Intersect" in_features = [IntersectLyr, fc] #Perform Intersect between bufferpoly and selected features in each habitat feature class arcpy.Intersect_analysis(in_features, outFC) arcpy.AddField_management(outFC, "PERCENTAGE", "Double") des = arcpy.Describe(outFC) outFClyr = des.baseName + "lyr" arcpy.MakeFeatureLayer_management(outFC, outFClyr) arcpy.AddMessage("The Intersect Layer is: " + str(outFClyr)) arcpy.AddJoin_management(outFClyr, "FID_ProjectRadius", IntersectLyr, "OBJECTID") fldList = arcpy.ListFields(outFClyr, "*.PERCENTAGE") for fld in fldList: percentfld = fld.name arcpy.AddMessage(fld.name) fldList2 = arcpy.ListFields(outFClyr, "*.Shape_Area") for fld in fldList2: if fld.name == "ProjectRadius.Shape_Area": arcpy.AddMessage(fld.name) buffareafld = fld.name else: arcpy.AddMessage(fld.name) areafld = fld.name cur = arcpy.UpdateCursor(Intersect) for row in cur: buffarea = row.getValue(buffareafld) habarea = row.getValue(areafld) row.percentfld = (buffarea/habarea)*100 cur.updateRow(row) del cur, row A multitude of thanks in advance to anyone who can help!! Amy Meehan Maine Dept. Inland Fisheries and Wildlife
... View more
11-10-2011
08:14 AM
|
0
|
7
|
1456
|
POST
|
I'm trying to write a subroutine for the first time and I'm getting very confused. I'm trying to create a tool where users would interactively add a point to a feature class (using a feature set and appending it to the original feature class). The tool uses the interactive feature input control. So far I've gotten that part to work and to append the new feature to the original feature class. Now I'm trying to add in some functionality so that if the user forgets to enter a project id for the point, an error message will be printed and then a subroutine is called so they can then enter the project id. Here is my code: # Import arcpy module import arcpy from arcpy import env #Set workspace # env.workspace = "L:/Projects/HMAP/EnvironmentalReview.gdb" # Script arguments Feature_Set = arcpy.GetParameterAsText(0) if Feature_Set == '#' or not Feature_Set: Feature_Set = "in_memory\\{C6359898-F410-49FF-96DD-0EB59C98516A}" # provide a default value if unspecified # Local variables: ##ProjectPoints = Feature_Set ##ProjectPoints__2_ = "ProjectPoints" #define subroutine if user forgot to enter a project identifier # def subroutine1(): cur = arcpy.UpdateCursor(Feature_Set) for row in cur: newVal = arcpy.GetParameterAsText(1) idValue = row.setValue(newVal) row.updateRow(row) del cur, row return #Check to make sure user entered a project identifier for point # cur = arcpy.SearchCursor(Feature_Set) for row in cur: idValue = row.getValue("ProjectID") if idValue == None: arcpy.AddError("PLEASE ENTER A VALUE(S) FOR PROJECT ID") subroutine1 else: arcpy.Append_management(Feature_Set, "ProjectPoints", "TEST", "", "") # Process: Append I know I'm doing something wrong as far as the subroutine is concerned. When I run the tool, it allows me to click the mouse to add a point. Then I hit "o.k" on the interactive input window to simulate someone forgetting to input the project id. Then the rest of the script starts to run but I get an error stating that "the name Feature_Set is not defined". I've tried reading all kinds of documentation on defining functions but I apparently still don't quite get it. Can anyone help? Thanks much! Amy Meehan MDIFW Bangor, Maine
... View more
10-26-2011
07:27 AM
|
0
|
2
|
387
|
POST
|
I managed to get my data into the format Chris suggested and then the Convert to Time field tool actually worked. Thank you!! Amy
... View more
10-14-2011
06:34 AM
|
0
|
0
|
509
|
POST
|
I have a rather unique problem. Not sure if Python is the right way to solve it, but here goes: I have some satellite (radiotelemetry) location data that I am trying to analyze for movement patterns, etc. I want to animate certain time periods. However because of the way the data are downloaded, I have a date field for the date but for the time, I had to make a text field and convert the time into the following format: hh:mm am/pm I think I need a singe field to make the animation work the way I want (showing consecutive locations on a map). I'm not overly familiar with the datetime functions in Python. Is there a way to combine these two fields into a single datetime field? Would it be somehow easier to do this with the field calculator? Thanks for any suggestions. Amy Meehan Wildlife Biologist Maine Dept. Inland Fisheries and Wildlife
... View more
10-12-2011
08:18 AM
|
0
|
6
|
2399
|
POST
|
Thanks! That mostly works better than what I had written. I thought that since my "layer" that I'm selecting on is actually a feature class that I had to change it into a layer using MakeFeatureLayer. But I couldn't even get it to select a feature correctly. Your code does select the feature, but it still does not zoom to the selected feature. Wondering if this is some type of bug in ArcMap 10 or if I keep doing something wrong. Thanks again! Amy
... View more
08-26-2011
06:47 AM
|
0
|
0
|
1706
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|