|
POST
|
I have usually only used reclassify to reclassify one set of integers to another. Seems to me a another approach to try would be to try the Lookup() tool instead. (Logging an incident request with support may be a good idea too!) For example (untested code - ymmv)
remap = \
[0, 0.00], \
[12, 0.00], \
(...)
[232, 1151.31], \
[233, 768.34]]
rmDict = dict(zip(i[0] for i in remap],[j[1] for j in remap]))
arcpy.AddField("myrast","REMAP","DOUBLE")
Rows = arcpy.UpdateCursor("myrast")
for Row in Rows:
val = rmDict[int(Row.VALUE)]
Row.REMAP = val
del Row, Rows
from arcpy.sa import *
outRast = Lookup("myrast","REMAP")
outRast.save("rmrast")
... View more
03-06-2013
07:35 PM
|
0
|
0
|
1656
|
|
POST
|
Caleb, you inspired me to drop some info about SQL expressions in arcpy scripts into this thread... The help docs say that you need to always have double quotes around field names but I hardly ever do that anymore and it still works (may just be for shapefiles?). Anyways, you only need the single quotes after an operator (AND, OR, <>, = etc) if it is a text string type. Yes, single quotes are required in SQL for all string literals. Double quotes are needed in SQL to protect your field name from parsing, for example, to make sure reserved words or embedded operators in field names (for example: "COUNT"; "FIELD-1") do not break your SQL expression. That's why you often see double-quotes used in examples -- it's best practice just in case your field names are not legal. This is especially important if your field name came in as a tool parameter (you as the script developer can't control what people will try to do!). Personal geodatabase and some ODBC-sourced tables always require brackets around field names:
[CITY] = 'CHICAGO'
There is an arcpy method that will automatically add the appropriate field delimiter based on the workspace, just in case someone decides to ignore or can't take your good advice to avoid personal GDB's. Using this method will keep your script from breaking.
>>>> print arcpy.AddFieldDelimiters("C:\\work\\mypersonal.mdb","CITY")
[CITY]
Last but not least, I want to encourage using substitution SQL expressions, as they make dealing with all this easier:
field = "CITY"
cityname = "Chicago"
wks = "C:/Data/MyWorkspace.mdb"
where_expr = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(wks,field),cityName)
... View more
03-06-2013
07:15 PM
|
0
|
0
|
1569
|
|
POST
|
Having given up on ModelBuilder and Script Tools due to repeated Arc Desktop crashes, I have arrived down at the bare-metal: the promising Python Toolbox. Hate to tell you Brad, but I've found .pyt to be pretty unstable compared to script toolboxes until you have enough experience to get the syntax exactly right. Also, if you were doing things with script tool validation etc that was crashing ArcMap, the same validation code will crash ArcMap just as effectively. As far as I can tell, the tbx is simply a slightly different implementation of the same framework used in the pyt file. You do have a little more control with value table parameters than the tbx property sheets support. (Maybe an Esri person can chime in, as I haven't gotten into that yet.) What datatype to set for the parameters? Should I make them all string instead of Workspace, feature class, etc Is there an enumeration for the arcpy parameter datatypes so I don't have to type the bloody things and spell them correctly? How to detect the appropriate change-events? This is the same as it is with the validation code for tbx script tools. For datatypes that have string representation like Field, you can generate picklists as strings and then apply them to a filter. ".value" is the arcpy data type you have set it to be (that may or may not have an easy string representation you can use. Depends on the data type). Arc 10.1 Help: '>Understanding validation in script tools Customizing tool behavior in a Python toolbox So far I haven't been convinced to abandon the .tbx format in my work because 1) the tbx can store tool documentation inside the file and a .pyt doc hangs out in parallel .xml files, 2) I have 10.0 users to support, and 3) I am one of those lazy people that likes it when someone does my work for me with property sheet interfaces so I don't have to write the code myself. (OK, I'll come clean, the folks that implemented the tbx properties are far better Python programmers than me.) Honestly if you're getting started with Python toolboxes, I feel the best approach to start with is to make a good old fashioned tbx script tool with validation set up for you from the script tool's property sheets (and maybe a little of your own in the Validation tab), then convert to a pyt using this conversion tool. Once you've done this you'll have auto-generated code to start with so you can get familiar with how it works with your particular application.
... View more
02-28-2013
07:50 AM
|
0
|
0
|
870
|
|
POST
|
I think that could do the trick. The only thing that I can't figure out is how to execute the merge based on the first feature. The only merge options I can find work with multiple datasets instead of the features in a single dataset. I can't find any useable options in the environments as well. Sorry, I was wrong about the Merge tool in step 4. The field mappings work across one row at a time, not across multiple rows. The tool you need to use instead of Merge is Summary Statistics (Statistics_analysis), specifying LAST for each field of interest (after the sort, LAST is the one with largest area) and dissolvepolyID as a case_field.
... View more
02-28-2013
07:09 AM
|
0
|
0
|
1133
|
|
POST
|
I'm trying to derive Enhanced Vegetation Index (EVI) from Landsat 5 TM data using the raster calculator and I can't seem to get the output I want. Here is a link to the description and formula for EVI: http://en.wikipedia.org/wiki/Enhanced_vegetation_index The output should be a raster with values ranging from -1 to 1, but I get values from like 30-40 which is incorrect. The coefficients you are using are hard-coded for MODIS data sets (as stated in the wikipedia article). Additionally, the values required are not raw Landsat dataset DN values (0-255) but instead must be atmospherically-corrected reflectance values. Here's a journal article that discusses the processing involved. http://southwestnwrsnatresources.files.wordpress.com/2011/12/sesnie-et-al-2011.pdf
... View more
02-27-2013
07:28 PM
|
0
|
0
|
7464
|
|
POST
|
if the same technique can be used for tools based on models (and/or Python script tools)? I don't know how it's done for custom tools, but for script and model tools you can alter the dialog by using a custom stylesheet - not very well documented, but you can start from Esri's which are in the install folder. The stylesheet may be specified on the script or model tool property's General tab.
... View more
02-27-2013
07:11 PM
|
0
|
0
|
1711
|
|
POST
|
Check to see exactly what is getting passed. Repr() is very handy for this.
arcpy.AddMessage("newlayer: " + repr(newlayer))
it sounds from your error message that "AnnexationAreas_SOI" is what got passed. If your script is running within the ArcMap context (ie as a script tool in Arcmap) the Describe should be able to identify that string as a layer and successfully find it and retrieve it's spatialReference. If not, it's just a string and what you should have passed a dataset instead.
... View more
02-27-2013
02:36 PM
|
0
|
0
|
743
|
|
POST
|
An approach I can think of is this: Dissolve your input by your single attribute Run an Identity_analysis of your input against the dissolved output. Sort (the tool, not just in table view) the identity output table by dissolvepolyID and area Merge this sorted table using FIRST for your attributes. Use the field map control to name the output fields as you need to. Join this result to your dissolve output table by dissolvepolyID
... View more
02-27-2013
02:18 PM
|
0
|
0
|
1133
|
|
POST
|
or look at the mxd that I am working on and allow the direct implementation of layers. The ArcMap command window is a python shell launched within the ArcMap application, so it can see the layers within the MXD. A python shell (whether it be from a command window, IDLE, PythonWin, etc.) is in a separate process, and cannot "see" the layers or properties of your running ArcMap application.
... View more
02-26-2013
09:30 AM
|
0
|
0
|
1501
|
|
POST
|
The tool ref doesn't say it is honoring raster environment settings - but maybe you should check the extent and mask, just to be sure.
... View more
02-26-2013
09:11 AM
|
0
|
0
|
2587
|
|
POST
|
The original data file that I have projected in ArcMap has only the lat, lon, time, date, and uid as attributes in chronological order. To do the speed filtering I need to calculate the distance between consecutive points then using this and the times calculate a rough estimate of speed. To get accurate distances, you need to project your data and run Add XY Coordinates, as you can't measure speed accurately in degrees / time. The Sort tool can be used to sort your point features so they are in consecutive order. You could then use the Calculate Field tool to calculate speed for the 2nd through nths point. See this example from the help to get started. Desktop Help 10.1: Calculate Field Examples / Accumulative and sequential calculations Calculate the percentage increase of a numeric field.
Parser:
Python
Expression:
percentIncrease(float(!FieldA!))
Code Block:
lastValue = 0
def percentIncrease(newValue):
global lastValue
if lastValue:
percentage = ((newValue - lastValue) / lastValue) * 100
else:
percentage = 0
lastValue = newValue
return percentage
... View more
02-26-2013
07:58 AM
|
0
|
0
|
823
|
|
POST
|
I have a class that is working with Rasters stored in a Geodatabase. Somewhat randomly, many tools (even basic raster calculator expressions) are failing (Background Processing Error screen appears) when the inputs are Geodatabase rasters, but when we use equivalent rasters that are stored in a folder, there are no problems at all. Has anyone else experienced issues like these? ArcGIS 10.0 SP4, Windows7. Thanks. Heath You may get some helpful error messages in the results tab (that's where they are written when you use background processing). I recommend turning off background processing for students so they can see what's going on and have easy up-front access to error messages. Are you using file geodatabase or personal geodatabase? Personal geodatabase (.mdb) should be avoided if possible.
... View more
02-26-2013
07:49 AM
|
0
|
0
|
754
|
|
POST
|
I thought it was because it might not be possible to do a point distance calculation on only one point data set (as I want to know the distance between points within the same layer)? The tool does support providing the same point feature class for from and to inputs. I agree you should project your point feature classs to UTM or some other appropriate coordinate system before you run Point Distance so your distances will be in meters.
... View more
02-26-2013
07:39 AM
|
0
|
0
|
2689
|
|
POST
|
I was successful running the entire script using the same test data set before converting to a script tool. Seems to be behaving differently in the script tool. You are using GetParameter(), which returns an arcpy Field object, not a field name -- if you set it up as a script tool. From the command line, or IDLE, etc., the parameter is always a string, but from a toolbox, ArcGIS can pass the argument as a bona-fide arcpy object. If this is a Field parameter you should use GetParameterAsText() if you want the field name as text - for example, for use in a Calculate Field expression. Python's sys.argv and arcpy.GetParameterAsText are fairly equivalent, although I am pretty sure GetParameterAsText can handle a longer string. (In code examples, you usually see GetParameterAsText because this allows the script to used easily inside or outside ArcGIS.) Note, there is a new tool in 10x that does DMS to DD conversion, at least many of the conversions you'd want: ConvertCoordinateNotation_management. (I had been asking for this tool since the 1980's!)
... View more
02-25-2013
10:18 AM
|
0
|
0
|
2022
|
|
POST
|
I am following the steps in the book and replacing PD_Buffer with PD_%Incident%_Buffer and i keep getting an error that tells me "The name contain invalid character" and it executes no further. If the element "Incident" does not exist in your model, no substitution takes place and the tool gets a path with a "%" character in it, which will generate the error you mention. I'd carefully check your spelling of the model element against where you entered it in the tool.
... View more
02-25-2013
09:32 AM
|
0
|
0
|
2202
|
| 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
|