|
POST
|
What is the syntax I should be using? Thanks. Fortunately, scripts written for 9.3 (using arcgisscripting) should work fine at 10.x. This includes scripts dropped into the Calculate Value tool. Here's it is set up for arcpy, anyway, just so you can see the slight difference.
import arcpy
def CalcDiff(tbl,valField,diffField):
procFields = valField + ";" + diffField
sortField = valField
Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField)
lastVal = 0
while Row:
val = float(Row.getValue(valField))
# calc the difference between the last value and this one
diff = val - lastVal
Row.setValue(diffField,diff)
Rows.updateRow(Row)
lastVal = val
del Row, Rows
return tbl
ArcGIS 10.1 has a new cursor that is faster (arcpy.da.SearchCursor) if speed is an issue.
... View more
04-15-2013
01:45 PM
|
0
|
0
|
5183
|
|
POST
|
Well, that makes good sense. My problem is I am new to ArcGIS and don't know how to set ARCTMPDIR. This is covered in the KB article I referenced above, under a link labeled "show me". The easiest way to get to user environment variables in Win 7 is to enter "env" in the search box on the start menu.
... View more
04-12-2013
07:20 AM
|
0
|
0
|
2844
|
|
POST
|
Thanks for the note. Yes, it did have to do with to do with administrative permissions. When I run ArcGIS as Administrator it is ok. Anna/Donald: That's because as administrator you do can write garbage to the aformentioned system32 folder. Not that you really want to,and not that you want to be logged in as administrator while doing your work (this is extremely hazardous to your computer's security). You should only use admin accounts while installing software or making system tweaks, and DEFINITELY not when not browsing the web or reading email. It's a much better fix to set the environment variable ARCTMPDIR to a writeable location (best practice- a local disk drive).
... View more
04-11-2013
11:52 AM
|
0
|
0
|
2844
|
|
POST
|
I'm using the expression: ((Con("Results" < -4, -4, "Results")) (Con("Results" > 1, 1, "Results"))) You need to nest the function to do what you want. My example before required one more parenthesis, sorry. Con("Results" < -4, -4, Con("Results" > 1, 1, "Results"))
... View more
04-11-2013
11:49 AM
|
0
|
0
|
1462
|
|
POST
|
I'm still having some trouble getting this to work for me. I'm getting a couple of error messages when I try to run the raster calculator with SetNull. When I use both limiting values (-4 and 1), with this calculation SetNull("results" <-4 >1, "results"), I get this error message: ERROR 000539: Error running expression: rcexec() <type 'exceptions.ValueError'>: The truth value of a raster is ambiguous. Here are two different ways to do this that should work (at least one anyway): SetNull("results" < -4 or "results" > 1, "results")
SetNull("results", "results", "VALUE < -4 OR VALUE > 1") I limited the calculation to only limit to < -4 with this calculation SetNull("results" <-4, "results") and got this error message: 000539: Error running expression: rcexec() <type 'exceptions.RuntimeError'>: ERROR 010240: Could not save raster dataset to <Save Location> with output format IMAGINE Image I think this second error has to do with your output path. make sure your output pathname is not the same as an existing dataset with the same name - and that the output location is a folder not a geodatabase workspace.
... View more
04-10-2013
11:19 AM
|
0
|
0
|
1462
|
|
POST
|
I am trying to run IDW interpolation with barriers. The process fails to convert the barrier into a shapefile in the Windows\System32 folder (where I don't have full write permission). Have you tried either setting ARCTMPDIR to a writeable location, or starting ArcMap in a folder you have write access to? This has been an issue with topological processing in ArcGIS and the IDW barriers functionality may use some of that code. KB 29559 - Problem: Certain geoprocessing tools will not execute or work unless the user is an administrator (By the way, setting the current and scratch workspace to the same location [preferably a folder workspace] is best practice for heavy raster processing, so even if it didn't help you this time, it's a good idea anyway.)
... View more
04-10-2013
11:07 AM
|
0
|
0
|
2844
|
|
POST
|
Here's an implementation of William Huber's neat idea of using the FlowAccumulation tool to generate xmap and ymap. This uses the current processing environment, it will generate an error if the arcpy.env.extent or cellSize are not explicitly set. (this code has a bug fixed - thanks Cameron! from arcpy.sa import *
from arcpy import env as E
# Calculate $$NROWS and $$NCOLS from current environment
cellSize = float(E.cellSize)
nrows = int((E.extent.YMax - E.extent.YMin) / float(E.cellSize))
ncols = int((E.extent.XMax - E.extent.XMin) / float(E.cellSize))
# Bill Huber's method for $$XMAP and $$YMAP: "1" flows "right", "64" (63+1) flows "up"
tmpg = CreateConstantRaster(1)
xmap = (FlowAccumulation(tmpg) + 0.5) * cellSize + E.extent.XMin
ymap = (FlowAccumulation(tmpg + 63) + 0.5) * cellSize + E.extent.YMin
# applying the same method for $$ROWMAP and $$COLMAP
colmap = Int(FlowAccumulation(tmpg))
rowmap = Int(FlowAccumulation(tmpg + 3)) # flowdir "4" is "down" (top row is 0)
... View more
04-10-2013
10:39 AM
|
2
|
2
|
3860
|
|
POST
|
However, if I go from the console and set up something like:
rows = arcpy.UpdateCursor(fc)
for row in rows:
if '\r\n' in row.TextString:
row.setValue('TextString', row.TextString.replace('\r\n', ' '))
rows.updateRow(row)
del row, rows
It works exactly as one would expect. But I would love to know more about why this doesn't seem to work from the Field Calculator window. The problem is that you cannot use Python escape codes like "\r" in the Field Calculator code block or the Calculate Value code block. I'm assuming this has something to do with the parsing of python arguments into string representation in the arcpy/gp messaging framework. If you need to access escape characters, use the chr() function instead. This will probably work fine:
rows = arcpy.UpdateCursor(fc)
for row in rows:
newline = chr(13) + chr(10)
if newline in row.TextString:
row.setValue('TextString', row.TextString.replace(newline, ' '))
rows.updateRow(row)
del row, rows
... View more
04-10-2013
10:34 AM
|
0
|
0
|
4498
|
|
POST
|
Have a look of the Create Fishnet tool. you can get evenly spaced points. Then you can use Spatial Join tool to see how many points are 'CONTAINED' by each polygon. Another approach is to convert the feature class to raster using your separation distance at the cell size and the extent set to your polygon(s), then convert back to points -- then run the spatial join.
... View more
04-09-2013
09:27 AM
|
0
|
0
|
8380
|
|
POST
|
Which license level do you have - ArcGIS Basic, Editor, or Advanced?
... View more
04-09-2013
09:20 AM
|
0
|
0
|
830
|
|
POST
|
Your attachment does not display. If the data type of "Output raster" is Raster Dataset or Raster Layer, the next thing I'd check is its content. You may have to modify your script so it will return a value (raster dataset pathname?) that tools can recognize. (Note that since Make Raster layer did not work either, this isn't a problem with the Raster Calculator tool; it's with the value or type of Output raster. Hope this helps! UPDATE: I found the tool you are using, from the Marine Geospatial Ecology tools: Convert SDS in HDF to ArcGIS Raster I saw that the current version of this tool has a map algebra expression argument you can use. Maybe if you do it that way you can get this thing iterating as you wish!
... View more
04-08-2013
03:20 PM
|
0
|
0
|
4642
|
|
POST
|
Are you sure your script tool is returning a variable of type Raster Dataset? I think the problem is with the validation... This is how raster calculator looks to me when I have a raster data element in the model: [ATTACH=CONFIG]23304[/ATTACH] If Output raster is in the list, it's not necessarily a raster dataset. if you can't get your script tool to return a variable of type raster dataset, workarounds I can think of are - Connect your Output Raster to the Make Raster Layer tool and try to use that in Map Algebra (you may get the same error from that tool) Use Calculate Value (CV) to convert the variable contents (say, a path string) to a raster dataset - use the CV expression: r"%Output raster%" and set the output Data Type to Raster Dataset.
... View more
04-08-2013
09:43 AM
|
0
|
0
|
4642
|
|
POST
|
This is a really odd system - if you're meant to be following the steps in the help section then why would the tools default to a format that won't work with the help steps? ArcGIS is exceedingly complex - which does make writing bulletproof tutorials very difficult. If you have an issue with a tutorial in the help not working, please go to the online help page and post feedback. They do read the feedback and may be able to fix the steps in the help for the next person. Did my suggestions help?
... View more
04-08-2013
07:38 AM
|
0
|
0
|
2055
|
|
POST
|
GetParameterAsText() is the more general purpose solution, and it's easier to debug as what you get is text so you can print it! You should use Describe() instead of Raster(), as that will successfully deal with either a raster layer or path to a raster dataset. Also - Clip_analysis will give you features out, not a raster:
import arcpy
inLines = arcpy.GetParameterAsText(0)
inRaster = arcpy.GetParameterAsText(1)
outLines = arcpy.GetParameterAsText(2)
pnt_array = arcpy.Array()
extent = arcpy.Describe(inRaster).extent
pnt_array.add(extent.XMin)
pnt_array.add(extent.YMin)
pnt_array.add(extent.XMin)
pnt_array.add(extent.YMin)
poly = arcpy.Polygon(pnt_array)
arcpy.Clip_analysis(inLines, poly, outLines)
Also this would work just as well, as Wayne mentioned:
import arcpy
inLines = arcpy.GetParameterAsText(0)
inRaster = arcpy.GetParameterAsText(1)
outLines = arcpy.GetParameterAsText(2)
arcpy.env.extent = inRaster
arcpy.CopyFeatures_management(inLines, outLines)
... View more
04-07-2013
04:44 PM
|
0
|
0
|
891
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-11-2021 01:26 PM | |
| 5 | 12-10-2021 04:58 PM | |
| 1 | 02-27-2017 09:30 AM | |
| 2 | 12-04-2023 01:05 PM | |
| 1 | 04-12-2016 10:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-19-2024
12:10 AM
|