POST
|
Just an update: I also tried with this syntax:
extract = arcpy.sa.ExtractByAttributes (raster, "\VALUE\ = 6 OR \VALUE\ = 8"
And received a different error, this time:
An expected Field was not found or could not be retrieved properly.
An expected Field was not found or could not be retrieved properly. [VAT_u01002020]
Failed to execute (ExtractByAttributes).
Which is also a SQL syntax problem.
... View more
01-18-2013
09:03 AM
|
0
|
0
|
174
|
POST
|
Hi all, I am trying to write a Python code block using Extract by Attributes with a SQL query including the "OR" operator that consistently will not work regardless of the syntax I try. As it is the code block looks like this:
for raster in arcpy.ListRasters():
outpoint = raster + "af"
extract = arcpy.sa.ExtractByAttributes (raster, "/\VALUE/\ = 6 OR /\VALUE/\ = 8")
extract.save (outpoint)
The SQL syntax is directly copied from the Results window, which ran successfully, but throws an error (at the end below) when run in IDLE. I had originally been using the option here (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000) to escape the double interior quotes with slashes, which did not throw an error but did not extract correctly (it extracted values of 2 and 0 in addition to 6 and 8). I've also tried enclosing the string in triple quotes or escaping the single interior quotes, which both threw errors; IDLE did not recognize the string using the escaping-interior-quotes syntax. Any help would be appreciated.
Traceback (most recent call last):
File "S:\FIRE\gdb.py", line 32, in <module>
extract = arcpy.sa.ExtractByAttributes (raster, "/\VALUE/\ = 6 OR /\VALUE/\ = 8")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1117, in ExtractByAttributes
where_clause)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
result = wrapper(*args, **kwargs)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1113, in wrapper
out_raster)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in <lambda>
return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used. [VAT_u01002020]
An invalid SQL statement was used. [SELECT * FROM VAT_u01002020 WHERE /\VALUE/\ = 6 OR /\VALUE/\ = 8]
Failed to execute (ExtractByAttributes).
... View more
01-18-2013
08:47 AM
|
0
|
1
|
368
|
POST
|
Hi all, I'm having an issue converting a raster to a polygon using Raster to Polygon. The raster was initially broken off from a larger dataset using the Split Raster tool and the other tiles created using that tool were all able to convert successfully; they're all roughly the same size, same projection and being run on the same machine. It's ArcGIS 10 on a 64-bit Windows 7 setup with 4GB of RAM, with service pack 4; it's an integer raster. I tried running on three other machines with no luck and also tried converting to an ESRI GRID from a TIFF. Any help is appreciated.
... View more
07-15-2012
06:08 PM
|
0
|
1
|
1415
|
POST
|
I've tried this, but it creates mostly null values. I'm looking into the error but was wondering if any of the other tools are comparable.
... View more
05-30-2012
07:13 AM
|
0
|
0
|
279
|
POST
|
Hi all, Just a quick question about how using a spatial join with "closest" as the match option works. I'm trying to spatially join a shapefile of world ecoregions with a shapefile of world country boundaries to get a country code for each ecoregion. Since ecoregions pass over country boundaries, I'd like to select the country code where most of the ecoregion falls, and I'm trying to figure out if "closest" is the best option for this; however the technical info on how "closest" works for polygon-to-polygon matches isn't very detailed. Can anyone give me more info on how this option works (i.e. does it use centroids or boundaries as the point of measurement, etc). anne
... View more
05-30-2012
06:38 AM
|
0
|
4
|
2109
|
POST
|
Extract by Attributes is working fine--it is hanging after that, on the Raster to Point conversion. The extracted rasters are being created correctly, but the script doesn't continue to move forward after that. Sorry if that was unclear.
... View more
04-17-2012
06:47 AM
|
0
|
0
|
238
|
POST
|
This code that I've written runs fine up until Extract by Attributes, then hangs (continues running, with no output). What did I do wrong?
import arcpy
arcpy.CheckOutExtension ("Spatial")
from arcpy import env
from arcpy.sa import *
#Allows overwriting
arcpy.env.overwriteOutput = True
##Set workspace; necessary for arcpy scripts
##note that following commands only work for the defined workspace: i.e., the ExtractbyAttributes command automatically convert all rasters in the geodatabase specified
arcpy.env.workspace = r"S:\FIRE\year1992to2000"
####iteratively defines each subfolder as a workspace; for each raster in each subfolder, converts to specified geodatabase
workspaces = arcpy.ListWorkspaces()
for workspace in workspaces:
arcpy.env.workspace = workspace
for raster in arcpy.ListRasters():
arcpy.RasterToGeodatabase_conversion (raster, r"S:\FIRE\t92to00.gdb")
#resets workspace to geodatabase mentioned above
#the "r" before the pathname tells python that this is an absolute pathname. Hard to explain, but some combinations of slashes and characters are read as commands (for example, /g means the end of a line) by arcgis and will cause it to parse the pathname incorrectly. The "r" prevents this.
arcpy.env.workspace = r"S:\FIRE\t92to00.gdb"
#adds table for final append operation
#table created manually--you could create one within the program if you wanted, using the CreateTable and AddField commands
outtable = r"S:\FIRE\73to80.gdb\y92to00"
#for each raster in geodatabase, extract by attributes to include only pixels with the correct values, in this case, 6 and 2
#rename resulting rasters; "af" refers to conversions from forest and ag only
for raster in arcpy.ListRasters():
outpoint = raster + "af"
extract = arcpy.sa.ExtractByAttributes (raster, " VALUE = 6 OR VALUE = 8")
extract.save (outpoint)
#"for" loop calls only rasters with "af" in the name
#RastertoPoint_conversion converts rasters to point files to enable use of Mean Center
#rename resulting shapefiles; keep original file information
for raster in arcpy.ListRasters ("af", "*"):
outpoint= raster[:8] + "p"
arcpy.RastertoPoint_Conversion (raster, outpoint)
#"for" loop calls only point feature classes in the workspace
#MeanCenter_stats creates a new point shapefile with a single point, the mean center of the points extracted in the previous step
#rename the resulting shapefiles
for fc in arcpy.ListFeatureClasses ("p", "Point"):
outmean= fc[:8] + "m"
arcpy.MeanCenter_stats (fc, outmean)
uid = fc[1:8]
arcpy.AddField_management(outmean, "UID", "TEXT")
arcpy.CalculateField_management(outmean, "UID", '"'+uid+'"')
#"for" loop calls only point feature classes with the phrase "mean" in their filename
#Near_analysis adds new columns to the mean center point file
#"infeat" is a single shapefile containing the borders of public lands in California
for fc in arcpy.ListFeatureClasses ("m", "Point"):
infeat= "S:\FIRE\ben_data\NPSFSBLM"
arcpy.Near_analysis (fc, infeat)
arcpy.MakeTableView (fc, "tv")
arcpy.AppendManagement ("tv", outtable, "NO_TEST", "", "")
... View more
04-16-2012
12:13 PM
|
0
|
3
|
543
|
POST
|
This was basically the same as the script I had, with the addition of the backslash. Mine looks like this:
arcpy.env.workspace = r"S:\FIRE\86to92.gdb"
workspace = arcpy.env.workspace
outtable = r"S:\FIRE\73to80.gdb\y86to92"
for raster in arcpy.ListRasters():
outpoint = workspace + "/" + raster + "af"
extract = arcpy.sa.ExtractByAttributes (raster, " VALUE = 6 OR VALUE = 8")
extract.save (outpoint)
However, now I am getting this error message:
Traceback (most recent call last):
File "S:\FIRE\gdb.py", line 33, in <module>
extract = arcpy.sa.ExtractByAttributes (raster, " VALUE = 6 OR VALUE = 8")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1117, in ExtractByAttributes
where_clause)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
result = wrapper(*args, **kwargs)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1113, in wrapper
out_raster)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in <lambda>
return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
Access denied
Access denied [GDB_Items]
No spatial reference exists.
ERROR 010302: Unable to create the output raster: S:\FIRE\86to92.gdb\Extract_u8001
ERROR 010067: Error in executing grid expression.
Failed to execute (ExtractByAttributes).
ERROR 010302 suggests that I don't have write permission or don't have enough space available. I checked and both of these are OK.
... View more
04-12-2012
11:38 AM
|
0
|
0
|
476
|
POST
|
On the following code block (specifically, the last line), IDLE throws this error: ERROR 010093: Output raster format UNKNOWN is unsupported.
for raster in arcpy.ListRasters():
outpoint = workspace + raster + "af"
extract = arcpy.sa.ExtractByAttributes (raster, " VALUE = 6 OR VALUE = 8")
extract.save (outpoint)
I feel like it shouldn't be necessary to specify a format since the output is saving into a geodatabase. Also, is there better documentation on extract.save somewhere? I've found very little on it and am just imitating the syntax example used on the Extract by Attributes tool page.
... View more
04-11-2012
12:04 PM
|
0
|
6
|
2526
|
POST
|
Hi all, I have a couple of questions related to the syntax for Extract by Attributes, related to the code block below (part of a larger script):
for raster in arcpy.ListRasters:
outpoint = workspace + raster + "af"
sqlclause = "VALUE" = 6 OR "VALUE" = 8
extract = arcpy.ExtractbyAttributes (raster, sqlclause)
extract.save (outpoint)
My understanding is that extract.save is the only way to save the output of Extract by Attributes. Do I need to create a full file pathname for this, or does it automatically save in the current workspace? (i.e., can I drop "workspace" from outpoint or is it understood to save within the current workspace?). Sorry if this is an obvious question, but I can't seem to find any documentation on this syntax. Also, I'm copying the syntax from the online example for the SQL query, but it looks totally incorrect; does it need to be enclosed in square brackets? Thanks.
... View more
04-03-2012
10:13 AM
|
0
|
1
|
326
|
POST
|
You're right, of course...serious case of the Mondays over here, apparently. Any thoughts on the "auto-fill" on the last line?
... View more
03-26-2012
12:32 PM
|
0
|
0
|
553
|
POST
|
I'm working on a longer piece of code and wanted to look at a list of rasters in a workspace to make sure I knew the formatting. Trying to create and print a list of raster names has continually raised a syntax error of 'unexpected EOF while parsing' for line six. (This would be followed by an indented "print raster" but I'm checking the syntax as I go). >>> import arcpy >>> from arcpy import env >>> env.workspace=r"S:\FIRE\ben_data\1973to1980\Eco01" >>> rasterlist=arcpy.ListRasters >>> >>> for raster in rasterlist: ... print raster Does anyone have insight about why such an error would be raised on such a simple piece of code? In addition, Python has continually auto-fills the last "raster" with "rasterlist" when I to execute the code block. Why is it doing this? (I understand I can just change that variable name--just wondering out of curiosity).
... View more
03-26-2012
12:09 PM
|
0
|
3
|
1430
|
POST
|
Bruce, thank you--that is exactly what I was looking for. Stacy, indexing incrementally shouldn't be necessary here, as the slicing operation will preserve the Unique ID in the filename, but I'll stash that idea for the future. I'll let you know how it goes!
... View more
03-26-2012
06:49 AM
|
0
|
0
|
356
|
POST
|
Hi all, Apologies if this has been answered elsewhere; I'm a relative newcomer to Python (know just enough to get myself in trouble, usually). I'm working on a large script to geoprocess hundreds of files which will require outputs for each tool to be named as the for loop goes over them. Here's an example of part of the code: for fc in arcpy.ListFeatureClasses ("*", "Point"): outmean= **** arcpy.MeanCenter_stats ('fc', 'outmean') Where the ***** definition must iteratively rename the output file based on the input filename. The input files contain unique identifiers in the filename, like so: samp01_0020_1986to1992_change_60m samp01_0074_1986to1992_change_60m samp05_0031_1992to2000_change_60m The output file needs to contain the first 22 characters (i.e. samp01_0020_1986to1992) in order to be identified in the final output. Therefore, CreateUniqueName and CreateScratchName seem inappropriate because this part of the path couldn't be preserved (unless I'm mistaken). I thought some operation using os.path.join would be most appropriate, but the syntax is unclear to me--do I need to create a list of filenames, or can I use something like this: for raster in arcpy.ListRasters: outpoint = os.path.join (raster, "out") arcpy.ExtractbyAttributes (raster, " VALUE = ", outpoint) In addition, if I wanted to strip the end of the file (say, take off "change_60m") and add another ending, where should I start with the syntax? os.path.split and os.path.splitext seem inappropriate here, as I'm not interested in the entire path or the extension (neither are relevant, as the workspace is a single geodatabase). Thanks in advance.
... View more
03-23-2012
11:44 AM
|
0
|
4
|
481
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|