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 ...
whuber's user avatar
  • 69.4k
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
user2856's user avatar
  • 64k
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 '...
Pierre Racine's user avatar
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("...
umbe1987's user avatar
  • 3,737
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 ...
user2856's user avatar
  • 64k
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 ...
Steven Kay's user avatar
  • 20.2k
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 ...
Evil Genius's user avatar
  • 6,221
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) #...
user2856's user avatar
  • 64k
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 ...
RoperMaps's user avatar
  • 2,126
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 ...
traggatmot's user avatar
  • 2,010
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.
cl3's user avatar
  • 1,936
3 votes
Accepted

Changing raster value based on point feature

Add an attribute of 1 to the points and use this for step 2. Convert the points to raster using the same extent (environment settings > extent> Raster 1 as extent) and same resolution (environment ...
If you do not know- just GIS's user avatar
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)
Ken's user avatar
  • 596
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 ...
Thomas's user avatar
  • 1,187
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, " ...
jon_two's user avatar
  • 1,834
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): ...
Joseph's user avatar
  • 75k
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 ...
Hornbydd's user avatar
  • 42.6k
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 ...
RoperMaps's user avatar
  • 2,126
3 votes

ArcGIS Raster Calculator Con-Statement

@FelixIP comment is correct, you need to convert your raster file to a raster object using arcpy.Raster() before using Con(). Here is the code that worked for me: import arcpy from arcpy.sa import * ...
ahmadhanb's user avatar
  • 40.3k
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 ...
Ian Turton's user avatar
  • 79.9k
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 ...
gianfranco di pietro's user avatar
2 votes

Adding Rasters with multiple Field Values using Map Algebra in ArcGIS for Desktop?

Use the Lookup function: Lookup("Raster1", "FieldX") + Lookup("Raster2", "FieldY") + Lookup("Raster3", "FieldZ")
user2856's user avatar
  • 64k
2 votes
Accepted

Raster result is different for arcpy.sa CON and arcpy.gp.Con_sa

As mentioned by @Luke, set arcpy.env.scratchWorkspace before running Spatial Analysis tool will redirect that result to scratch workspace.
Henri Lim's user avatar
  • 149
2 votes
Accepted

Problem with algebra formulas for work with gdal_calc.py

the test yields either 1 (true) or 0 (false). So you can make an "and" by multiplying the results, and the othe cases using 1-(condition). Here ismy suggestion B*(A==212)*(B==20) + A*(1-(A==212)*(B==...
radouxju's user avatar
  • 49.3k
2 votes

Map Algebra syntax

Depends on what you want to create. If you want a raster where your goodslope areas are "1" and the rest are NoData, Con is a good way to go about it: slope = Slope("elevation") # elevation is the ...
Curtis Price's user avatar
  • 1,560
2 votes

PostGis's ST_MapAlgebra rasters do not have the same alignment

To work, rasters passed to the two rasters variant of ST_MapAlgebra() must: 1) be in the same coordinate system. You can reproject one raster to the coordinate system of the other raster with ...
Pierre Racine's user avatar
2 votes
Accepted

Looping Map Algebra using Python

You must put a slash after the "work.gdb" on that last line. It is assuming you are saving it as a work.gdbraster file name (e.g. it is appending whatever string "raster" represents to "work.gdb". ...
jbchurchill's user avatar
  • 4,489
2 votes

Working with 2 rasters, having different extents but same resolution, in ArcGIS raster calculator?

If you set your environment extent correctly to raster 1, then the extent of the output raster will be that of raster 1, but you will only get data where raster 2 has data (because Value + NoData == ...
user2856's user avatar
  • 64k
2 votes

Showing two sets of points from two different fields in QGIS?

If the two source layers have the same fields, you could combine them together using the merge tool. Using the data you currently have, you would have to rely on the coalesce function to handle the ...
JGH's user avatar
  • 39.8k
2 votes
Accepted

What is this Map Algebra expression performing in ArcGIS ModelBuilder?

The Set Null tool takes the following parameters: SetNull (in_conditional_raster, in_false_raster_or_constant, {where_clause}) which are described in the tool's documentation as follows: ...
Marcelo Villa's user avatar

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