Trying to use Con statement in Raster Function in Pro

4228
9
Jump to solution
03-25-2016 03:21 PM
MervynLotter
Regular Contributor

HI there

I would like to use a Con statement in a Raster Function so that I do not have create a new raster every time I want to query values in a raster (DEM). I am working in Pro 1.2.

For example, if I wanted to view all areas above 350 m above sea level, using the Raster Calculator in Spatial Analyst I would have traditionally inserted the following statement: Con("altitude1">350,1). This would create a new raster for my query.

Con statement.jpg

So I tried using a Raster Function. I am able to open the Con properties window for a raster function in Pro, but I cant figure out how to enter any parameters (other than what is provided in the screenshot, which deals with rasters, cell size and output extent). I am pretty sure Raster Functions should be able to extract the desired DEM values, perhaps I am using the wrong function or simply just not using it correctly? Can anyone point me in the right direction?

Thank you.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

Dan, these raster functions Melvyn​ is trying to use are a bit of a different animal - they work with rasters "on the fly" at the resolution of the screen, not as temporary raster datasets at full gp cell size like like Raster Calculator or raster tools.

Mervyn, you do need to chain by supplying your raster and a number to Greater Than and then pass that result into the Con function. Greater Than returns true or false, so the second argument to your Con would be the input elevation raster. The help pages you cite guide you through the process of chaining functions together.

Raster functions are more useful for web services than on the desktop IMHO. Rendering a raster using classification of a raster layer in ArcMap is pretty efficient too.

View solution in original post

9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

You are going overboard for such simple queries

Raster Calculator—Help | ArcGIS for Desktop

for example

>—Spatial Analyst module | ArcGIS for Desktop

will return a binary raster with 1 representing where the condition is true and 0 where the condition is false

So unless you need to 'do something' with the output, use the simple functions within the raster calculator.

For example "show me where all the elevations are > 300 meters"

That's it... just show me... it didn't say show me and also show me the actual elevations where elevation is > 300 meters AND also make those elevations 300m  equal to 0  OR whatever whatever...

Con is nice... but don't get conned into using Con everytime a conditional statement is being used.

MervynLotter
Regular Contributor

Hi Dan (and others)

I agree that using the Con statement is a bit of an overkill but I was

struggling to find a "function" that I could use to extract values

using *Raster

Functions*. I agree 100% with your suggestion if I used the Raster

Calculator tool to perform the analysis. In my call for help, the problem

with the Raster Calculator is that it creates an output raster to disk. I

am looking for a method to create a temporary feature that shows the

elevation (in my example), without creating an output raster. Raster

Functions are really great in creating these temporary products for

visualization and analysis and I am starting to use them more frequently

these days. So I was looking for an appropriate raster function that I

could use to extract values from a DEM. I just cant figure out how.

Under the Help menu in Pro (

https://pro.arcgis.com/en/pro-app/help/data/imagery/list-of-raster-functions.htm)

there is a section on Raster functions, specifically "*What are the

functions used by a raster or mosaic dataset*?", which lists the various

function available with a brief description of each. Some functions of

those listed only apply to overlapping rasters (like the arithmetic

function). The "basket" of functions which may include the answer to my

problem is probably under the Local Functions (

https://pro.arcgis.com/en/pro-app/help/data/imagery/local-function.htm).

The Greater than function only works on two or more rasters so I cant

consider this function as a solution.

I still think that the Con raster function may provide the necessary

output. There is also a Calculator Raster Function but I cant figure out

how it works. It would be great if the Help section provided some examples.

The help item on the Con function states "*When a Con operator is used,

there usually needs to be two or more local functions chained together,

where one local function states the criteria and the second local function

is the Con operator which uses the criteria and dictates what the true and

false outputs should be*." I have tried the Function Editor but no luck

in figuring out how to insert the statement or string together the Con

functions in any sensible manner.

To summarise, I am still hoping that it is possible to use Raster Functions

to extract values from a DEM, whether using Con functions or any other

function (or string of functions as a template). I have in the

past occasionally used Symbology to manually classify my elevation into

two classes using a certain elevation threshold,

but using a Raster Function would be far more efficient and elegant ....

Best wishes,

Mervyn

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

results persist on disk only if they are made so, Isn't there are a 'results are temporary' option in geoprocessing options like there is in ArcMap?  If they are, then the intermediate grids should be removed when the process is complete.  In the raster calculator, you don't have to assign an output filename to the raster.  Also, I haven't experimented with 'in_memory' as a destination with rasters in PRO, The in_memory workspace—ArcGIS Pro | ArcGIS for Desktop  but there seem to be some cavaets that aren't great, like you can't see them and when you use them in geoprocessing tool or python scripts, they get written to the geodatabase (if using one).  They don't mention modelbuilder, but I suspect this behaviour is similar.

curtvprice
MVP Esteemed Contributor

Dan, these raster functions Melvyn​ is trying to use are a bit of a different animal - they work with rasters "on the fly" at the resolution of the screen, not as temporary raster datasets at full gp cell size like like Raster Calculator or raster tools.

Mervyn, you do need to chain by supplying your raster and a number to Greater Than and then pass that result into the Con function. Greater Than returns true or false, so the second argument to your Con would be the input elevation raster. The help pages you cite guide you through the process of chaining functions together.

Raster functions are more useful for web services than on the desktop IMHO. Rendering a raster using classification of a raster layer in ArcMap is pretty efficient too.

View solution in original post

MervynLotter
Regular Contributor

Hi Curtis

Thank you for advice. I was able to successfully use the Greater than function using the function editor to extract all areas above a certain elevation (output had values of 0 or 1).  See below image. What I figured out was that I needed to add an elevation threshold under the second input raster. I would have thought there may be an option for providing a threshold but this worked. Is this the correct workflow or should I have added elevation threshold as a Constant instead of Raster Variable?

Greater than raster function.jpg

I did not need the Con function .... but I wanted to see if i could get it to work.  I managed to do so although I found that when stringing together two or more functions then I need to add altitude threshold as a constant as I could no longer edit the Raster2 in the Greater than function without opening the Function Editor and manually changing it. 

0 Kudos
MervynLotter
Regular Contributor

Sorry, hit send to soon.

For those of you interested in this discussion and using Raster Functions to extract values, I will end by adding in a screenshot of the Function Editor where I was able to use the Greater than and Con functions together that returned the actual elevation values above a certain threshold (1400 m in this example). If there a simpler way of doing so, I would love to hear from you, but it was possible :-).

Greater than and Con raster function.jpg

Thanks to Dan, Adrian and Curtis for helping.

0 Kudos
curtvprice
MVP Esteemed Contributor

I really like the Con tool because it makes your workflow very obvious. I think a constant for the GreaterThan tool is what you were looking for.

This is a really nice interface compared to Desktop!

0 Kudos
MervynLotter
Regular Contributor

Hi Curtis

The new interface is really great ... and I like the similarity to model builder as a workflow.

I have made the suggested changes my elevation raster function. I have also been trying to apply symbology to my custom raster functions and it is unfortunate that it does not accept Layer files. I am struggling to have my color ramps applied to my raster function.

Thanks for advice.

0 Kudos
EricRice
Esri Regular Contributor

A little late on this thread, but thought I'd throw this out there for anyone looking at this in the future.  I personally only use the Calculator function for this type of stuff.  Below will return elevation values for all values above 1400 and return 0's if false.

calc.jpg