10
votes
Accepted
Access individual bands and use them in map algebra
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')...
9
votes
Accepted
R giving error when attempting map algebra
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
votes
Accepted
Changing raster calculation values - shorten this script?
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 ...
6
votes
Accepted
ArcPy map algebra equivalent for "any"?
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
votes
Accepted
Passing additional arguments to ST_MapAlgebra callback?
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
'...
6
votes
Arcpy reclassify with function
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("...
5
votes
Nodata issues in map algebra
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 - ...
5
votes
Calculate NDVI using ArcPy Spatial Analyst
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 ...
4
votes
Accepted
How to do loops on raster cells with python console in QGIS?
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(...
4
votes
Performing raster map algebra in open source web GIS?
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 ...
4
votes
Accepted
Arcpy.Delete_management() not deleting folder?
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 ...
4
votes
Map algebra in QGIS
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 ...
4
votes
Identifying row and column location of a raster image using ArcGIS 10.1
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) #...
4
votes
Accepted
Adding two rasters using map algebra in ArcPy?
What @Joseph says. The Raster class needs a string containing the path to your raster. You've correctly assigned this to a variable, so you then need to pass those variables to instantiate your ...
4
votes
Accepted
Calculate NDVI using ArcPy Spatial Analyst
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 ...
4
votes
Accepted
Merging two rasters, obtain only highest values, overwrite raster in ArcGIS Desktop?
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
votes
Accepted
Alternative to nested Con statements in python
Not sure if this helps, but I have a script with many nested Con statements, and I find just using indentation helps. For example:
EWR_2015 = Con(
"ministerial_wetlands" > 0,
" ...
3
votes
Accepted
Map algebra in QGIS
One method which I used quite a while ago was to print the standard deviations in the Python Console in QGIS. I would first load all the raster layers (easier if they're kept in the same directory):
...
3
votes
Access individual bands and use them in map algebra
You can access an individual band from a multi-band raster by using the Make RasterLayer tool. This would create an "in-memory" raster which you can process with, it is not a new dataset.
3
votes
Accepted
PostGIS raster summation (map algebra)
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
...
3
votes
Nodata issues in map algebra
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 ...
3
votes
Accepted
Raster multiplication script not executing
You're inputting your variables as string. Try without the quotes.
outRas = Raster(in_raster1) * Raster(in_raster2) * Raster(in_raster3)
3
votes
Accepted
Getting rid of small objects on raster in ArcMap?
You can use the Majority Filter to remove cells that are surrounded by your green cells. This would also influence the boundary of your dominant green area as this tool works a local level.
In your ...
3
votes
Accepted
Gdal_calc NDVI for many rasters
Nearly there. Couple of small problems:
You've used the bash syntax instead of cmd. i.e. $ instead of %.
Your --outfile parameter isn't specified explicitly, and looks a bit jumbled.
Try:
for %i in ...
3
votes
Accepted
Creating custom Operation for encapsulating some map algebra using GeoTools?
It sounds like you need jiffle which is contained in the gt-process-raster module. Once you have constructed a Process you can pass in a list of source rasters and bands for it to process in the ...
3
votes
Accepted
Showing two sets of points from two different fields in QGIS?
Union (geoprocessing) feature make a "union" of 2 dataset (C = A united to B).
Probably you are tring to JOIN two dataset.
Try this:
Go to JOIN settings: (right click -> properties -> Join)
Add ...
2
votes
How to calculate cumulative sum conditionally across raster?
here is how I would do it in ArcGIS without coding:
build the raster attribute table of your raster (you may need to multiply by some number (e.g.1000) and round it into integers) : this will give ...
2
votes
Accepted
How to compare two rasters and reclass the greater value(python script)?
Assuming you have spatial analyst you can create a difference raster and then follow with a nested Con statement to produce your result.
Activate spatial analyst
if arcpy.CheckExtension("Spatial") ==...
2
votes
Performing raster map algebra in open source web GIS?
What you are looking for is an image server. ArcGIS for Server has this extension:
ArcGIS Image Extension for Server
i do not know of any open source equivalents.
2
votes
QGIS from console: raster algebra
Unfortunately the question is about PyQGIS and not GDAL (osgeo) (use rasterio, easier, see below in 3) and there are many examples in GIS Stack Exchange as How to evaluate raster calculator ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
map-algebra × 101arcpy × 33
raster-calculator × 33
raster × 31
spatial-analyst × 30
arcgis-desktop × 29
postgis × 9
python × 8
arcmap × 8
modelbuilder × 8
qgis × 7
arcgis-10.0 × 7
arcgis-10.2 × 6
arcgis-10.1 × 5
error-000539 × 5
gdal × 4
dem × 4
loop × 4
postgis-raster × 4
r × 3
grass × 3
ndvi × 3
reclassify × 3
error-000732 × 3
con × 3