|
POST
|
You should not use "%" signs within raster calculator. You should use model variables which are either raster datasets or raster layers, for example: Con( "Noview value" == 1 &
((("Beview value" == 0) & ("HHview value" == 0)) |
(("Beview value" == 1) & ("HHview value" == 1))), 1, 0)
When you open Raster Calculator from inside the model, the valid model elements should be there in the dialog at the upper left with an icon identifying them as model variables (as opposed to raster layers in the current map). I don't know how the gdb works into this, unless you have temporary dataset names that are confusing things. Note, if you're working in modelbuilder, it's best to just attach the model (i.e. a tbx file with a model in it) - the python export is very difficult to interpret.
... View more
06-01-2013
01:02 PM
|
0
|
0
|
1969
|
|
POST
|
For reference, this is taking a set of building classes from a building outline polygon file and adding them to a land-use/land-cover dataset. Here's an attempt to keep your temp datasets temporary (and have them deleted by default). I also set things up to work withou tthe sa prefixes so the map algebra is easier to read.
from arcpy.sa import *
from arcpy.env import env
env.overwriteOutput = 1
# for best performance of map algebra, scratch and current should be the same
env.workspace = arcpy.env.scratchWorkspace = workingFGDB.gdb
lulc = Raster(lulcName) # convert to raster object for use in map algebra
...
bldgtileName = "bldg{0}_{1}".format(i,j)
lulctileName = "lulc{0}_{1}".format(i,j)
arcpy.PolygonToRaster_conversion(bldglayer, "BLDGTYPE", bldgtileName)
bldgtile = Raster(bldgtileName) # convert to raster object (note, this is a permanent raster)
nobldgtile = Con(IsNull(lulc), 0, lulc) # convert any null LULC cells to zero
# replace null cells in bldgtile with lulc cells
lulctile = Con(IsNull(bldgtile), nobldgtile, bldgtile)
lulctile.save(lulctileName) # this is the only one you want to save
# arcpy.Delete_management(bldgtile) # uncomment to delete
Note, the details on handling raster objects are documented here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/The_interaction_of_the_Raster_object_in_ArcGIS/00p60000000v000000/ My understanding is that the way to delete raster objects created using map algebra is not using arcpy.Delete. You should use del or just let Python delete it when you reassign the variable on the next iteration and when the script closes after the last iteration.
... View more
06-01-2013
12:48 PM
|
0
|
0
|
3422
|
|
POST
|
I have gotten very few scripts to actually run correctly in the 64 bit window. There are unsupported tools and data types that must be kept in mind when developing for 64 bit arcpy. Desktop 10.1 help: Background Geoprocessing (64-bit)
... View more
05-28-2013
08:04 AM
|
0
|
0
|
2548
|
|
POST
|
The machine I am running is a 64 bit machine, but I am not accessing the data through ArcCatalog. Is there a way to work around the 64 bit problem. I have included the piece of my adjusted script. I don't think 64 bits is the issue. Let me try an approach that may work for you better. Both in formatting your pathnames, and using a list of arcpy raster objects instead of putting monster strings together: # Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Path names for input and output data
path = "S:\\MODIS\\DATA_v05\\modis016_0250_ndvi\\us\\or"
output_path = "B:\\MODIS_NDVI\\Avg_per_period"
env.workspace = env.scratchWorkspace = output_path
rasList = []
for period in range (1,3): # [1,2]
for m in range(1,13): # 1..12
rasPath = "{p}{month}{per:02d}ndvius".format(
p=path, month=m, period)
if arcpy.Exists(rasPath):
rasList.append(Raster(rasPath))
else:
raise Exception("Raster {0} not found".format(rasPath))
outCellStatistics = CellStatistics(rasList, "MEAN", "DATA")
outName = "avg{0:02d}".format(period)
outCellStatistics.save(outName)
... View more
05-24-2013
11:58 AM
|
0
|
0
|
2548
|
|
POST
|
Why is the name invalid? And one more thing...why is it dropping that '.0" at the end of the name? The value its pulling from the field is '27240', where is the '.0' coming from?? The name is invalid because names in the gdb cannot contain ".". The ".0" is appearing I would guess because if the input field is float or double, the string representation in Python includes the ".0".
... View more
05-24-2013
09:46 AM
|
0
|
0
|
1859
|
|
POST
|
Zonal statistics could not be computed for feature 26 (zone = 26) ERROR 000601: Cannot delete C:\Research\Projects\xxxwk1\xx.gdb\workfeat. May be locked by another application. Failed to execute (CopyFeatures). Manisha, I don't think the above error has do with my tool. There have been reports of antivirus software locking ArcGIS files while they are being scanned, and making things miserable for everyone. I honestly don't have any good ideas for you. Can you try on a different machine that may have different security set up?
... View more
05-22-2013
12:54 PM
|
0
|
0
|
2425
|
|
POST
|
Well I got further along in my model and decided to try running it for multiple values just to see if it worked and it didn't - it just ran the first one. I think it's because there' no arrow from "value" to a process - all of ARC's examples have that as the case. Jacob, I think you are using the wrong iterator, passing the output of iterate field values into a select by attribute. What you want to use here is Iterate Field Selection, this will output a layer with a active selection to pipe into your processing chain, each unique value (or combination, if you specify more than one) can then be processed in sequence. I moved this to a new thread in the Geoprocessing forum... I apologize for not really knowing how iterations work, but it seems like ARC is sort of a learning through doing thing. Yes, but that said, there are some very useful free resources at http://training.esri.com -- and the online help chapter on iterators keeps improving (along with the software).
... View more
05-20-2013
09:17 PM
|
0
|
0
|
594
|
|
POST
|
You need to print a bit more:
import arcpy, ArcHydroTools
outpath = arcpy.env.workspace = \
r'E:\Projects\H109355_2\ArcHydro\Model3\Nigeria03.gdb\Layers'
arcpy.env.overwriteOutput = True
fdr = r'E:\Projects\H109355_2\ArcHydro\GRID\Layers.gdb\Fdr'
watshed = "Watershed"
with arcpy.da.SearchCursor(watshed,("Name",)) as scur:
for row in scur:
cuindex = row[0]
sqlexp = """{0} = '{1}'""".format(
arcpy.AddFieldDelimiters(watshed,"Name"),cuindex)
watshedind = arcpy.FeatureClassToFeatureClass_conversion(
watshed,outpath,"watshed",sqlexp)
try:
longflowpath1 = ArcHydroTools.LongestFlowPath(
watshedind,fdr,r"in_memory\longestflowpath")
except Exception, msg:
arcpy.AddWarning(
"LongestFlowPath failed for cuindex {0}".format(cuindex) +
+ "\n" + str(msg))
... View more
05-20-2013
09:05 PM
|
0
|
0
|
699
|
|
POST
|
It looks to me like you're getting an error somewhere in the code so "cur" never gets set. Your except block is setup to report geoprocessing errors but not python errors, so you aren't seeing them. try this:
import arcpy
import os
try:
outputFC = arcpy.GetParametersAsText(0)
fClassTemaplate = arcpy.GetParametersAsText(1)
f = open(arcpy.GetParameterAsText(2),'r')
arcpy.CreateFeatureclass_management(os.path.split(outputFC)[0], os.path.split(outputFC[1]), "point", fClassTemplate)
lstFires = f.readlines()
cur = arcpy.InsertCursor(outputFC)
cntr = 1
for fire in lstFires:
if 'Latitude' in fire:
continue
vals = fire.split(",")
latitude = float(vals[0])
longitude = float(vals[1])
confid = int(vals[2])
pnt = arcpy.Point(longitude, latitude)
feat = cur.newRow()
feat.shape = pnt
feat.setValue("CONFIDENCEVALUE", confid)
cur.insertRow(feat)
arcpy.AddMessage("Record number" + str(cntr) + "written to feature class")
cntr = cntr + 1
except arcpy.ExecuteError:
print arcpy.GetMessages()
except Exception, msg
print msg
finally:
try:
del cur
f.close()
except:
pass
... View more
05-20-2013
08:47 PM
|
0
|
0
|
766
|
|
POST
|
Have both the streams and schools layers in my active arcmap session. I am using arcmap's Python window to run this script in a python tutorial that finds schools within a specified distance from streams. Here's the code, error is on line 9:
import arcpy
>>> arcpy.env.workspace = "c:/GIS/Python/data/TravisCounty"
>>> try:
... streams = "Streams.shp"
... streamBuffer = "StreamsBuffer.shp"
... distance = "2640 Feet"
... schools2mile = "Schools.shp"
... arcpy.Buffer_analysis(streams,streamBuffer,distance,'FULL','ROUND','ALL')
... arcpy.MakeFeatureLayer_management(schools2mile,'Schools2Mile_lyr')
... arcpy.SelectLayerByLocation_management('Schools2Mile_lyr','intersect',streamBuffer)
... except:
... print 'Error'
...
Parsing error SyntaxError: invalid syntax (line 9) Turned out the Streams layer wasn't valid for whatever reason, but the error message in the Arcpy window wasn't letting me know it. As Wayne noted, your ArcMap python window version failed because you didn't indent it properly in, you guessed it, line 9. Using an IDE like IDLE does indeed help with syntax issues like this; the python window is really best for running a single tool or trying out a few lines of code, not for entering/writing scripts. There are many useful IDE's to use -- IDLE is just the one that ships with all Python distributions -- it's the "vi" of Python IDE's - quick, minimal, always there. Here's your indentation, fixed:
import arcpy
>>> arcpy.env.workspace = "c:/GIS/Python/data/TravisCounty"
>>> try:
... streams = "Streams.shp"
... streamBuffer = "StreamsBuffer.shp"
... distance = "2640 Feet"
... schools2mile = "Schools.shp"
... arcpy.Buffer_analysis(streams,streamBuffer,distance,'FULL','ROUND','ALL')
... arcpy.MakeFeatureLayer_management(schools2mile,'Schools2Mile_lyr')
... arcpy.SelectLayerByLocation_management('Schools2Mile_lyr','intersect',streamBuffer)
... except:
... print 'Error'
...
... View more
05-19-2013
08:46 PM
|
0
|
0
|
1530
|
|
POST
|
I have a mask of the smaller area composed of 1's where I want to keep values and NODATA in the background. (the mask is a single USGS quad sheet, the LULC is for an entire watershed). I use raster calculator to multiply the mask * LULC. The output is subset to the extent of the mask, but it is assigned a value of zero for all pixels where the mask has values of 1. Multiplying rasters can run you into bit depth issues that make the NoData codes invalid. I would instruct your students to use your 1/NoData grid with Extract By Mask tool, or simply set the GP mask environment to the 1/nodata grid and just enter the input raster into the raster calculator. If the point is to teach map algebra, an approach with tools like Con,IsNull,SetNull is more flexible than masking by multiplication anyway.
... View more
05-19-2013
08:21 PM
|
0
|
0
|
3815
|
|
POST
|
The input for kriging should be your x,y points, not a raster you created somewhere else. The setting for overwriting existing rasters, if you want to do that is in the menu choice Geoprocessing / Geoprocessing Options.
... View more
05-19-2013
08:13 PM
|
0
|
0
|
1077
|
|
POST
|
I am not sure how to include Curt's code into the Tool Validator. This is complex enough you really need to read the online help before you go any further: Desktop 10.1 Help: Customizing script tool behavior The code I gave you is designed to be used in the code box you see when you right click on a script tool and select Properties and go to the Validation tab.
... View more
05-17-2013
07:21 AM
|
0
|
0
|
2490
|
|
POST
|
That issue [indent][#NIM066910 A script run from Task Scheduler with the setting "run whether user is logged on or not" fails to initialize ArcPy when the license is single-use.] [/indent] seems very similar to what I'm experiencing. In the server I have both AG Server and AG Desktop 10.1 installed with single use license. What changes you had to make, besides the license, to run the tasks? (I have exchanged a private message with tribeiro about this.) Just to update everyone, we've determined that: This issue exists in ArcGIS 10.0 and 10.1. At 10.0 only, if you modify the Desktop license configuration from Single-Use to Concurrent licensing, the scheduled task will run even the user is not logged in. (This change equires running ArcGIS Administrator with elevated privileges. I have a VBScript script that can do this by modifying registry keys, but it also requires elevated privileges to run.) The 10.0 workaround does not work at 10.1. Our USGS user that was having this problem is doing a less optimal workaround: leaving her workstation logged on at night (screen locked of course!) so her scheduled task can successfully launch arcpy. Esri thinks this is reportedly fixed at 10.2 and I am trying to get around to testing it.
... View more
05-16-2013
08:05 AM
|
0
|
0
|
6660
|
|
POST
|
Michelle, sounds like your fix is to update to 10.1, or delete the fields -- or avoid using shapefiles, which are most useful today as a transfer format. (GDB feature classes support null values, domains, subtypes, and process and draw faster, among other benefits.) Service packs are available to you - even if you aren't up to date on maintenance, so I highly recommend you update to 10.0 SP 5.
... View more
05-15-2013
10:12 PM
|
0
|
0
|
3060
|
| 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
|