|
POST
|
Now that I got my tool running as a standalone script I set it to work as an ArcToolbox tool. It throws an error at line 62 (numerator) where the standalone does not...looks line another bug. Error Info: ERROR 000824: The tool is not licensed. ArcPy ERRORS: try:
import arcpy, os, sys, traceback
from arcpy.sa import *
from arcpy import env
arcpy.SetProduct("ArcInfo")
arcpy.CheckOutExtension("Spatial")
arcpy.AddMessage("\n\nCalculate Slope Factor of Safety")
arcpy.AddMessage("beta by Gerry Gabrisch, 5-4-2012")
#Get input parameters using ArcToolbox tool
degreesSlope = arcpy.GetParameterAsText(0)
totalSoilThickness = arcpy.GetParameterAsText(1)
saturatedSoilThickness = arcpy.GetParameterAsText(2)
treeRootStrength = arcpy.GetParameterAsText(3)
treeSurcharge = arcpy.GetParameterAsText(4)
soilCohesion = float(arcpy.GetParameterAsText(5))
effectiveInternalAngleofFriction = float(arcpy.GetParameterAsText(6))
drySoilUnitWeight = float(arcpy.GetParameterAsText(7))
moistSoilUnitWeight = arcpy.GetParameterAsText(8)
saturatedSoilUnitWeight = float(arcpy.GetParameterAsText(9))
waterUnitWeight = float(arcpy.GetParameterAsText(10))
rastercalc = arcpy.GetParameterAsText(11)
##Use For hardcoding
##Grids
#degreesSlope = r"C:\gtemp\FS_test\slope_degree"
#totalSoilThickness = r"C:\gtemp\FS_test\soildepth"
#saturatedSoilThickness = r"C:\gtemp\FS_test\dw"
#treeRootStrength = r"C:\gtemp\FS_test\rootcohesion"
#treeSurcharge = r"C:\gtemp\FS_test\surcharge"
#moistSoilUnitWeight = r"C:\gtemp\FS_test\moist_uw"
##Constants...
#soilCohesion = 10.0
#effectiveInternalAngleofFriction = 10.0
#drySoilUnitWeight = 10.0
#saturatedSoilUnitWeight = 10.0
#waterUnitWeight = 10.0
#Set the output cell size, mask, and cell registration...
arcpy.env.cellSize = degreesSlope
arcpy.env.extent = degreesSlope
arcpy.env.snapeRaster = degreesSlope
#Cast input rasters to in-memory raster layers...
degreesSlope = Raster(degreesSlope)
totalSoilThickness = Raster(totalSoilThickness)
saturatedSoilThickness = Raster(saturatedSoilThickness)
treeRootStrength = Raster(treeRootStrength)
treeSurcharge = Raster(treeSurcharge)
moistSoilUnitWeight = Raster(moistSoilUnitWeight)
numerator = "numerator"
denominator = "denominator"
result = "result"
numerator =(treeRootStrength + soilCohesion + Square(Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness)+ (saturatedSoilUnitWeight-waterUnitWeight)*saturatedSoilThickness)*Tan(effectiveInternalAngleofFriction))
denominator =((Sin(degreesSlope)*Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness) + drySoilUnitWeight * saturatedSoilThickness))
#Do the last division....
result = numerator/denominator
#Save the in-memory results to disk...
result.save(rastercalc)
arcpy.AddMessage("Done!")
#Catch ESRI errors here...
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
print msgs
#Catch Python errors here...
except:
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)
print pymsg + "\n"
print msgs
... View more
05-11-2012
12:32 PM
|
0
|
0
|
788
|
|
POST
|
Thanks, Jake. Setting the env properties to a grid worked.
... View more
05-11-2012
11:38 AM
|
0
|
0
|
788
|
|
POST
|
OK, I removed the raster calculator functions from the script. According to the literature I can use raster calculator like expression (+,-,/...) as long as I cast the raster as 'rasters'. I can get something like the below to work without error, but I cant get passed 'numerator' in the code below without getting the cell size and extent not set error. Raster("test1") Raster(test2") thesum = test1 + test2
try:
import arcpy, os, sys, traceback
from arcpy.sa import *
from arcpy import env
arcpy.CheckOutExtension("Spatial")
arcpy.AddMessage("\n\nCalculate Slope Factor of Safety")
#Grids
degreesSlope = Raster(r"C:\gtemp\FS_test\slope_degree")
totalSoilThickness = Raster(r"C:\gtemp\FS_test\soildepth")
saturatedSoilThickness = Raster(r"C:\gtemp\FS_test\dw")
treeRootStrength = Raster(r"C:\gtemp\FS_test\rootcohesion")
treeSurcharge = Raster(r"C:\gtemp\FS_test\surcharge")
moistSoilUnitWeight = Raster(r"C:\gtemp\FS_test\moist_uw")
numerator = "numerator"
denominator = "denominator"
result = "result"
#Constants...
soilCohesion = 10.0
effectiveInternalAngleofFriction = 10.0
drySoilUnitWeight = 10.0
saturatedSoilUnitWeight = 10.0
waterUnitWeight = 10.0
rastercalc = r"C:\gtemp\FS_test\dwrastercalc"
arcpy.env.cellSize = "MAXOF"
arcpy.env.extent = "MAXOF"
numerator =((treeRootStrength + soilCohesion + Square(Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness)+ (saturatedSoilUnitWeight-waterUnitWeight)*saturatedSoilThickness)*Tan(effectiveInternalAngleofFriction)))
denominator =((Sin(degreesSlope)*Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness) + drySoilUnitWeight * saturatedSoilThickness), denominator)
result =(numerator/denominator)
result.save(rastercalc)
# Process: Raster Calculator
#arcpy.gp.RasterCalculator_sa("treeRootStrength + soilCohesion + Square(Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness)+ (saturatedSoilUnitWeigh-waterUnitWeight)*saturatedSoilThickness)*Tan(effectiveInternalAngleofFriction))/((Sin(degreesSlope)*Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness) + drySoilUnitWeight * saturatedSoilThickness))", rastercalc)
arcpy.AddMessage("Done!")
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
print msgs
except:
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)
print pymsg + "\n"
print msgs
... View more
05-11-2012
10:37 AM
|
0
|
0
|
788
|
|
POST
|
My Python code throws an error at the first raster calculator statement claiming that no cell size or extent are set. I don't see why this is necessary in this script but I put in some extent and cell size statements anyway. That didn't help, the code still throws the same error at the first raster calculator statement. Any help is welcomed. try:
import arcpy, os, sys, traceback
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
degreesSlope = Raster(r"C:\gtemp\FS_test\slope_degree")
totalSoilThickness = Raster(r"C:\gtemp\FS_test\soildepth")
saturatedSoilThickness = Raster(r"C:\gtemp\FS_test\dw")
treeRootStrength = Raster(r"C:\gtemp\FS_test\rootcohesion")
treeSurcharge = Raster(r"C:\gtemp\FS_test\surcharge")
moistSoilUnitWeight = Raster(r"C:\gtemp\FS_test\moist_uw")
numerator = "numerator"
denominator = "denominator"
#Constants...
soilCohesion = 10.0
effectiveInternalAngleofFriction = 10.0
drySoilUnitWeight = 10.0
saturatedSoilUnitWeight = 10.0
waterUnitWeight = 10.0
rastercalc = r"C:\gtemp\FS_test\dwrastercalc"
arcpy.env.cellSize = "MAXOF"
arcpy.env.extent = "MAXOF"
arcpy.gp.RasterCalculator_sa((treeRootStrength + soilCohesion + Square(Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness)+ (saturatedSoilUnitWeight-waterUnitWeight)*saturatedSoilThickness)*Tan(effectiveInternalAngleofFriction)), numerator)
arcpy.gp.RasterCalculator_sa((Sin(degreesSlope)*Cos(degreesSlope))*(treeSurcharge + moistSoilUnitWeight*(totalSoilThickness - saturatedSoilThickness) + drySoilUnitWeight * saturatedSoilThickness), denominator)
arcpy.gp.RasterCalculator_sa(numerator/denominator, rastercalc )
arcpy.AddMessage("Done!")
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
print msgs
except:
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)
print pymsg + "\n"
print msgs
... View more
05-11-2012
07:22 AM
|
0
|
6
|
1064
|
|
POST
|
I have a Python script that mines a directory (and sub directories) for mxds and writes the fine names and data paths to a text file. The script works fine as a stand alone. I am trying to attach the tool to a Toolbox tool and notice some odd behavior. I have the output parameter set to type = Text File in my toolbox tool. After I fill in the input parameter (a directory) the output path is auto-completed using a .dbf file. Does anyone have any clues on how to fix this so that it defaults to a .csv or a .txt?
... View more
05-04-2012
12:25 PM
|
0
|
1
|
642
|
|
POST
|
FYI, if you open your tools parameters in ArcToolbox and go to the General tab, you can enter valid HTML code in the Description box which is a simple way to create nice looking help.
... View more
04-26-2012
01:09 PM
|
0
|
0
|
2473
|
|
POST
|
If they are points, just calculate xy values by calling the ArcToolbox tool, and populate the attribute table with lat/long. Then use a search cursor to extract the lat long for each point. Sorry, what I meant to say was reproject the data into WGS84 and use the AddXY Coordinates tool to populate the attribute table with lats/longs, then use the cursor to step through the records.
... View more
02-23-2012
09:01 AM
|
0
|
0
|
1886
|
|
POST
|
Use a search cursor and append all the values from that attribute to a new Python list. Sort the list. The first item in the list is the min value and the last is the last value. theitems = []
rows = arcpy.SearchCursor(inlayer)
for row in rows:
theitems.append(row.getValue(somefieldname))
del rows
theitems.sort()
min = theitems[0]
max = theitems[-1]
... View more
01-30-2012
06:43 AM
|
1
|
0
|
2657
|
|
POST
|
def SciNoteToFloat(x):
'''Takes a string writen in scientific notation and
returns a float'''
x = x.lower()
x = x.partition("e")
return (float(x[0])) * (int("1" + "0" * (-1 * int(x[2]))))
mynum = "0.223E-7"
print SciNoteToFloat(mynum)
... View more
01-26-2012
09:45 AM
|
0
|
0
|
488
|
|
POST
|
The metric you want is called the isoperimetric quotient. http://mathforum.org/library/drmath/view/55406.html
... View more
11-21-2011
07:37 AM
|
0
|
0
|
903
|
|
POST
|
The toolbox tool you are looking for is called Add Surface Information in the 3D Analyst Tools. This tool will populate your selected (Null Value) points with the raster value at each point.
... View more
11-21-2011
07:34 AM
|
0
|
0
|
506
|
|
POST
|
Here is a Python script to do just that... http://arcscripts.esri.com/details.asp?dbid=14127
... View more
11-04-2011
07:46 AM
|
0
|
0
|
1230
|
|
POST
|
Stacy, thanks for the tip. When I run the tool in Komodo I get this for the str(geometry1) and type(geometry 1) <geoprocessing describe geometry object object at 0x0ECA3D28> <class 'arcpy.arcobjects.geometries.Polygon'> <geoprocessing describe geometry object object at 0x0ECA3D28> In ArctoolBox I get this: i <type 'unicode'>
... View more
10-14-2011
01:33 PM
|
0
|
0
|
652
|
|
POST
|
Here is a portion of the code that returns the error. Again, it works fine as a stand alone where it is taking the inFC as text just like the arcpy.GetParameterAsText(0) try:
print "go"
import arcpy, os, sys, string, traceback, operator
inFC = arcpy.GetParameterAsText(0)
g1 = arcpy.Geometry()
geometrylist1 = arcpy.CopyFeatures_management(inFC, g1)
g2 = arcpy.Geometry()
geometrylist2 = arcpy.CopyFeatures_management(inFC, g2)
for geometry1 in geometrylist1:
for geometry2 in geometrylist2:
if (geometry1.touches(geometry2) or geometry1.overlaps(geometry2)):
print "Do more stuff here..."
print "done"
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
print msgs
except:
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)
print pymsg + "\n"
print msgs
... View more
10-14-2011
12:01 PM
|
0
|
0
|
652
|
|
POST
|
I made a four color map algorithm for Python. When I execute the script in PythonWin, Komodo, or Idle, with the path to the feature class hard-coded into the script, things run fine. I know the syntax is correct. Once I add the script to ArcToolbox it throws an error (error message posted below). The error occurs at this line. if (geometry1.touches(geometry2) or geometry1.overlaps(geometry2)) and counter != counter1: File "E:\SCRIPT~1\MINIMU~1\minimumpolygoncolor.py", line 46, in <module> if (geometry1.touches(geometry2) or geometry1.overlaps(geometry2)) and counter != counter1: Error Info: 'unicode' object has no attribute 'touches' ArcPy ERRORS: I also developed a tool to remap data paths in an mxd. Again, things run fine if I post the code into the Python window. All the broken links are fixed. When I convert this tool to a Toolbox script, the paths get updated...and then removed from the mxd. Does anyone know why a script would act differently once they are brought into ArcToolbox?
... View more
10-14-2011
11:11 AM
|
0
|
4
|
2504
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-26-2025 08:30 AM | |
| 1 | 10-29-2024 03:51 PM | |
| 1 | 06-26-2024 08:32 AM | |
| 1 | 12-06-2023 11:53 AM | |
| 1 | 06-12-2012 07:42 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2025
02:21 PM
|