Select to view content in your preferred language

How to transfer a query from R. Calculator to ArcPy

4572
16
03-16-2015 07:22 AM
KONPETROV
Occasional Contributor III

Hello,

I am using ArcGis 10.2. I have 3 classified rasters and i want to use the following query from r. calculator:

                  (rclslope>=45) & (rclmosaic>=2000) & (rclfocal>15) to arc.py

how can i write it?

Is it better to use local - combine tool with arc.py to do it?

Thank you very much.

0 Kudos
16 Replies
DarrenWiens2
MVP Honored Contributor

You could ​use the Con tool (see this page for relevant examples):

Con(("rclslope">=45)&("rclmosaic">=2000)&("rclfocal">15),1)

This returns a raster with pixel value = 1 which meets the criteria. If you're looking for a way to spatially query pixel values in ArcGIS, that doesn't exist to my knowledge.

KONPETROV
Occasional Contributor III

thanks a lot Mr. Darren Wiens. But i need a little more help if you can. The entire code should seem like;

0 Kudos
DarrenWiens2
MVP Honored Contributor

There are lots of arcpy examples using Con here​ - scroll to the bottom.

KONPETROV
Occasional Contributor III

So we mean something like that?

import arcpy

from arcpy import env

from arcpy.sa import *

env.workspace = "C:/sapyexamples/data"

outCon = Con(("rclslope">=45)&("rclmosaic">=2000)&("rclfocal">15),1)

outCon.save("C:/sapyexamples/output/outcon")

KONPETROV
Occasional Contributor III

Because with that i get an error

0 Kudos
DanPatterson_Retired
MVP Emeritus

well the error would help and you should have spaces between the grid names and the operands and perhaps it can't find the grids (assumed since there are no file extensions)   And the big one is that you didn't make raster objects from you grid names.  and please tell me that you have a path called c:/saexamples to test it in.

env.workspace = "C:/sapyexamples/data"

inRas1 = Raster("inRaster"

inRaster is inside the path

inRas1 is a Raster object which is needed by the Con statement

DarrenWiens2
MVP Honored Contributor

Agreed, mostly. What's this about spaces? AFAIK, they are irrelevant.

KONPETROV
Occasional Contributor III

Mr. Patterson i think i cannot understand you very well. I am still new in programming.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Please post the error.

0 Kudos