POST
|
Here's my new code, although I managed to figure out the problem with capitalizing on my own. Now I'm trying to figure out how to put an if statement into the field calculator without using VBA (my python shell doesn't run it for some reason). Thanks for any help Bruce. import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.Workspace = "C:/Max/Bathymetry_Cleanup/Vector/zone17"
gp.OverWriteOutput = 1
vectorlist = gp.ListFeatureClasses ("17*", "all")
for vector in vectorlist:
print vector
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Units", "str(!Units!).title()", "PYTHON_9.3", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Units", "str(!Units!).replace('Meters', 'Metres')", "PYTHON_9.3", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Srvy_Meth", "str(!Srvy_Meth!).title()", "PYTHON_9.3", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Creat_Meth", "str(!Creat_Meth!).title()", "PYTHON_9.3", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Accuracy", "str(!Accuracy!).capitalize()", "PYTHON_9.3", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Depth", "abs(!Depth!)*-1", "PYTHON_9.3", "")
gp.AddField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Metres", "DOUBLE", "6", "1", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Metres", 'if str(!Units!) = "Metres": (!Metres!)=(!Depth!)', "PYTHON_9.3", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Metres", 'if str(!Units!) = "Feet": (!Metres!)=0.3048*(!Depth!)', "PYTHON_9.3", "")
gp.CalculateField_management("C:/Max/Bathymetry_Cleanup/Vector/zone17/" + vector, "Metres", 'if str(!Units!) = "Fathoms": (!Metres!)=1.8288*(!Depth!)', "PYTHON_9.3", "")
... View more
07-26-2011
12:14 PM
|
0
|
0
|
307
|
POST
|
Hi, thanks for the help! However, I'm now getting an error about a locator not existing, and I've triple checked that my location path is correct. Is there any way to deal with that?
... View more
07-26-2011
08:31 AM
|
0
|
0
|
307
|
POST
|
Hi Everyone: I'm hoping to get some assistance from minds that are better than my own. I'm new to python but I'm trying to cobble together a script that will let me capitalize first letters in certain fields of shapefiles that I have. Here is my code: import sys, string, os, arcgisscripting gp = arcgisscripting.create(9.3) gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.Workspace = "C:/Max/Bathymetry_Cleanup/vector/zone17" gp.OverWriteOutput = True vectorlist = gp.ListFeatureClasses ("17*", "all") for vector in vectorlist: updateRows = gp.UpdateCursor(vector) updateRow = updateRows.Next() while updateRow: newString = "" for word in updateRow.Units.split(" "): newString = word.capitalize() + " " + newString updateRow.Units = newString[:-1] updateRows.updaterow(updateRow) updateRow = updateRows.Next() del updateRow del updateRows updateRows = gp.UpdateCursor(vector) updateRow = updateRows.Next() while updateRow: newString = "" for word in updateRow.Units.split(" "): newString = word.capitalize() + " " + newString updateRow.Srvy_Meth = newString[:-1] updateRows.updaterow(updateRow) updateRow = updateRows.Next() del updateRow del updateRows updateRows = gp.UpdateCursor(vector) updateRow = updateRows.Next() while updateRow: newString = "" for word in updateRow.Creat_Meth.split(" "): newString = word.capitalize() + " " + newString updateRow.Creat_Meth = newString[:-1] updateRows.updaterow(updateRow) updateRow = updateRows.Next() del updateRow del updateRows gp.CalculateField_management(vector, "Accuracy", "str(!Accuracy!).upper()", "PYTHON", "") When I try to run this process, I get an error reading: Traceback (most recent call last): File "C:\Max\python.py", line 17, in <module> updateRows = gp.UpdateCursor(vector) RuntimeError: ERROR 999999: Error executing function. General function failure I also tried running it with quotation marks around vector but that gives me the following error: Traceback (most recent call last): File "C:\Max\python.py", line 17, in <module> updateRows = gp.UpdateCursor("vector") RuntimeError: ERROR 999999: Error executing function. A locator with this name does not exist. Thanks for any help, Max
... View more
07-26-2011
06:22 AM
|
0
|
6
|
3713
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|