Need help translating from VB to Python.

901
4
Jump to solution
01-12-2013 02:02 PM
AlexFlanagan
New Contributor
I'm currently completing the spatial analyst training but unfortunately it was made for 9.3, while I'm using 10.1.

While using the raster calculator I'm having trouble translating this to python.

Example is:
SetNull([Ownership] <> 200 OR [Soil] == 901, 1)
0 Kudos
1 Solution

Accepted Solutions
DavidPetrey1
New Contributor III
Try the following:

SetNull(("Ownership"<> 200) | ("Soil" == 901), 1)

The Vertical Bar represents OR now. And raster names are within quotation marks. And I always find putting logic in its own brackets helps as well.

David
simplyGIS. Making GIS simple.
www.simplygis.co.uk/GISTraining.html

If this post helped answer your query please mark as answered to let others know.

View solution in original post

0 Kudos
4 Replies
DavidPetrey1
New Contributor III
Try the following:

SetNull(("Ownership"<> 200) | ("Soil" == 901), 1)

The Vertical Bar represents OR now. And raster names are within quotation marks. And I always find putting logic in its own brackets helps as well.

David
simplyGIS. Making GIS simple.
www.simplygis.co.uk/GISTraining.html

If this post helped answer your query please mark as answered to let others know.
0 Kudos
curtvprice
MVP Esteemed Contributor

  • the "not equal" operator in Python is "!="

  • The names in quotes are (technically) raster layer names.


Here's my shot at it:

SetNull(("Ownership" != 200) | ("Soil" == 901), 1)


Arc 10.1 help:
Comparing Map Algebra between ArcGIS 9.x and 10
Building Expressions in Raster Calculator
0 Kudos
DavidPetrey1
New Contributor III
Ah yes, the new symbol for doesn't equal is !=, though I find <> still works (or is this just a random thing of my installation?), which I usually end up typing out of habit.

David
0 Kudos
curtvprice
MVP Esteemed Contributor
Ah yes, the new symbol for doesn't equal is !=, though I find <> still works


Learned something, thank you. 

[noparse][/noparse]his is an obsolete usage kept for backwards compatibility only. New code should always use !=.


Python docs: Built-in Types - Comparisons
0 Kudos