A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

# Tag Info

10

You can access individual bands by joining the band name to the raster path - i.e. path/to/raster/band_name. Often using path/to/raster/Band_[band number] works (i.e os.path.join(rasterpath, 'Band_1'), but not always. I use Landsat 8 imagery quite a bit and ArcGIS names the bands 'CoastalAerosol', 'Blue', 'Green', 'Red', etc... If you don't know what the ...

9

The problem was that I had run out of space to write to disk, and the map algebra commands I was using were attempting to generate and write large temporary raster files.

8

I don't use arcpy but I know Python. This only means that you need to import the Python module with Con (and it is not arcpy alone) If I look at, Con (Spatial Analyst), I see that it is a function of the Spatial Analyst module and the examples provide the solution. You have forgotten to import the module: from arcpy.sa import * But the "pythonic" way to ...

8

What you want is a conditional calculation: return the value of r whenever r and r1 are equal and otherwise set the output to NA. The cell-by-cell arithmetic operations seem to be fastest. (They are much faster than, say, using mask or the reclassification functions.) Since they do not appear to offer an actual conditional operator, use two time-honored ...

7

Pick was created for problems like this. Think of it as the "switch" (or "case") version of "con", which is the map algebra implementation of "if...else." If there are 3 overlapping rasters, for instance, the (Python) syntax would look like inPositionRaster = 1 + int(3 * CreateRandomRaster()) Pick(inPositionRaster, [inRas01, inRas02, inRas03]) Note that ...

7

You can now work and do map algebra with rasters of almost unlimited size in a spatial database with PostGIS. I personnaly work with SRTM and climate data at the scale of Canada. I can do intersection between raster and vector layers in a very fast and transparent way. I can also use a whole set of map algebra functions.

6

My initial thought is that you must have assigned the variable pente_Rclass to a string representation of a raster instead of a raster object. This would cause your first error. See below: pente_Rclass = "myRasterName" represents a string... if you are using this in arcpy methods, it will automatically assume that this string is the name of a dataset in ...

6

You could sum the rasters and test whether the total is greater than 0. list_of_rasters = [Raster(a), Raster(b), Raster(c)] z = CellStatistics(list_of_rasters, "SUM") > 0

6

Additional arguments are passed as the 6th, and so on, arguments, after the custom function signature: ST_MapAlgebra(b1.rast, -- raster to operate on 1, -- band 'generate_random_raster(double precision[], integer[], text[])'::regprocedure, -- custom function signature pixeltype, -- can be null ...

6

This is how I would do it (it requires the Spatial Analyst extension which I think you have): import arcpy from arcpy.sa import * arcpy.CheckOutExtension = "Spatial" ndvi_raster = Raster("ndvivaluefrompixel") grey_raster = Raster("grayscalepixelvalue") output_raster = Con(ndvi_raster >= -0.000005 * grey_raster + 0.314367, 2, 1) output_raster.save("C:/...

5

My favourite way to deal with this would be to use a Con(IsNull) statement... Basically, using a Con statement allows you to define a condition; if it is true, do this, if it is false, do this - including leaving the values as they were. So in this case, I would be tempted to do something like Con(IsNull(myRaster), myRaster, 1) Which basically states: ...

5

In the line Temp4 = FocalStatistics('RasterImage', NbrRectangle (9, 9, 'CELL'), "RANGE", "DATA"), you need to remove the single-quotes around RasterImage -- it is being treated as a string literal and looking for a file called RasterImage. Edit: Thinking about this some more, I'm wondering if the script is failing because you initialize Temp4 as a string ...

5

I presume you're using ArcGIS Desktop which uses python 2x, not ArcGIS Pro which uses python 3x. Side note: this is one example of why it's important to specify the software you are using. In python 2x, when both operands are integers, division returns an integer result rounded towards minus infinity. This was changed in Python 3x so division returns a ...

4

Using python and ArcGIS 10 and using the con function which has the following syntax: Con (in_conditional_raster, in_true_raster_or_constant, {in_false_raster_or_constant}, {where_clause}) The idea here is to see if the value in the random raster is less than 0.5, if it is choose raster1, otherwise choose raster2. NoData + data = NoData so first set these ...

4

Have you tried using the Image analysis window? I know it gives you less control, but still allows for some useful calculations. And it is computationally more efficient - so if your dealing with a large data-set it may speed things up for you. Little Tutorial I put together. http://www.thadwester.com/1/post/2012/05/ndvi-calculation-in-arcgis-10.html

4

sooorry guys! I already found the solution... in GRASS GIS using the map calculator if(rasterA == 1, rasterB == 0, rasterB) soo easy... :)

4

If you try to output the iterate raster tool directly into raster calculator, you will only see the last iteration in the raster calculator layers and variables list. To get around this nuisance in model builder, use Collect Values to generate a list that you can pass off to Cell Statistics to do your calculations. Simply choose the "MEAN" overlay ...

4

Arcpy use the Numpy array format (hidden to the users) as PyGGIS that uses the Python GDAL module. provider = raster.dataProvider() # path the original file filePath = str(provider.dataSourceUri()) # open the original file from osgeo import gdal raster_or = gdal.Open(filePath) # create a numpy array numpy_array = raster_or.ReadAsArray() # shape ...

4

arcpy.ListRasters() is returning a list of raster filenames not Raster objects. In your loop you're trying to multiply a string (the raster filename) by the float value which causes the TypeError exception. You need to multiply a Raster object by the float value. Convert your file name to a Raster object using arcpy.sa.Raster from arcpy.sa import * rasters ...

4

Using only open source software, you will almost certainly need to do some programming yourself. GDAL is the de facto open source raster I/O library, so you will probably be using it or one of its many wrappers. You could use Python (e.g. rasterio + numpy/scipy) or node.js, e.g. node-gdal (though beware it is currently synchronous/blocking). As for actually ...

4

I think this is an issue with ArcGIS having open file handles on the files in your temp folder. As discovered in our comments, you could delete the Python variables and then use the Delete tool to remove the temporary directory (but not the del statement, that just deletes the variable), but you would still have to explicitly delete each result object... ...

4

You don't need to write code if you have GDAL installed (if you have QGIS installed that should be the case, but you can install GDAL seperately if you want/need to) This assumes you want a separate stddev for each image. If you want the stddev across ALL the images, you'll need to do a Raster Merge to combine them into a single raster. The gdalinfo tool ...

4

The \$\$RowMap, \$\$ColMap, \$\$XMap and \$\$YMap variables (and some others) are no longer (directly) supported as of ArcGIS 10.0. You can use it via python: arcpy.env.extent = arcpy.Extent(0, 0, 10, 10) #Change to suit # Or arcpy.env.extent = "path to raster" arcpy.env.cellSize = 1 #Change to suit arcpy.gp.SingleOutputMapAlgebra_sa("\$\$ROWMAP + 1"), "...

4

Are the red_band_raster and the nir_band_raster values integers? It seems likely that you should move the float() commands around each raster variable call in your equations, and not around the result of the addition/subtraction as you have it now.

4

You can do this just by using the Mosaic to New Raster geoprocessing tool. Just choose maximum for your Mosaic Operator and the new raster will use the high value anywhere that they overlap.

3

NoData is defined different ways depending on the raster source, including numerically. (You can look it up in raster properties if you are curious what the actual value is for your particular datasets.) I suggest instead using Reclassify instead of Raster Calculator, which can either explicitly ignore NoData values (leaving them NoData) or explicitly ...

3

As @nmpeterson says, the first issue comes down to the quotes around the RasterImage variable name. However the big thing is that you are overwriting the variable Temp4 with the contents of the raster. Instead, according to the FocalStatistics documentation from ESRI, the raster object returned has a save(path) method. I'm assuming you don't want to ...

3

I'm afraid you HAVE to use full paths in ArcGIS10. It doesn't seem help to specify the default geodatabase in the map document properties to try shortening the path (I tried that too).

3

Use this r.mapcalc expression: r.mapcalc "output = not(if(Road))*Slope" because: if(Road)is equal to 1 if Road not zero, 0 otherwise. not(if(Road))is equal to 0 if Road not zero, 1 otherwise.

3

You will need to write your own aggregate function: CREATE OR REPLACE function sum_raster_state(raster, raster) returns raster language sql as \$f\$ SELECT CASE \$1 WHEN NULL THEN \$2 ELSE ST_MapAlgebra( \$1, \$2, '([rast1] + [rast2])', NULL, 'UNION', '[rast2]', '[rast1]', NULL) END;...

Only top voted, non community-wiki answers of a minimum length are eligible