GRASS GIS for ArcGIS users: Difference between revisions
⚠️Wenzeslaus (talk | contribs) (→Raster algebra: examples, upper case operator names and wording) |
|||
Line 20: | Line 20: | ||
== Raster algebra == | == Raster algebra == | ||
Current ArcGIS raster calculator | Current ArcGIS raster calculator is implemented in Python. Some parts of the syntax resembles Python while some others differ from it. In GRASS GIS the map algebra is available through {{cmd|r.mapcalc}} module (implemented in C) or its convenient GUI wrapper ''Raster Map Calculator''. The {{cmd|r.mapcalc}} syntax is specifically designed for raster map algebra and is based on C syntax (Python is C-like language as well). Both syntaxes are case sensitive as it is common for C-like languages. | ||
=== Quotes === | === Quotes === | ||
In ArcGIS map algebra layer names must be quoted. In GRASS GIS, the quotes are optional and usually not used. There is few cases where it is necessary to use quotes and that is when raster map name contains dashes (which would be interpreted as minus operator). However, best practice is not to use dashes in map names at all (since map name should be ideally also usable without quoting in SQL). When writing Python script and you want it to be really robust. Then you may want to use | In ArcGIS map algebra layer names must be quoted. In GRASS GIS, the quotes are optional and usually not used. There is few cases where it is necessary to use quotes and that is when raster map name contains dashes (which would be interpreted as minus operator). However, best practice is not to use dashes in map names at all (since map name should be ideally also usable without quoting in SQL). When writing Python script and you want it to be really robust. Then you may want to use quoting. | ||
=== Whitespace === | === Whitespace === | ||
In ArcGIS map algebra operators must be surrounded by spaces. In GRASS GIS, the spaces around operators are optional, however it is a best practice to use them. | In ArcGIS map algebra operators must be surrounded by spaces. In GRASS GIS, the spaces around operators are optional, however it is a best practice to use them (same as in Python or C). | ||
=== Operators === | === Operators === | ||
Line 40: | Line 40: | ||
| & | | & | ||
| && | | && | ||
| Boolean (logical) | | Boolean (logical) AND operator is one ampersand (<tt>&</tt>) in ArcGIS. In GRASS GIS, boolean AND operator is two ampersands (<tt>&&</tt>) which is the same as in C. Note that <tt>&</tt> means bitwise AND operator in GRASS GIS (as well as in Python or C). There is also <tt>&&&</tt> in GRASS GIS which doesn't propagate null values (which is the standard behavior) but instead, treats them as false. | ||
|- | |- | ||
| <nowiki>|</nowiki> | | <nowiki>|</nowiki> | ||
| <nowiki>||</nowiki> | | <nowiki>||</nowiki> | ||
| Difference between ArcGIS and GRASS GIS in boolean | | Difference between ArcGIS and GRASS GIS in boolean (logical) OR operator is the same as in the case of boolean AND operator. In GRASS GIS there is bitwise <tt>|</tt> and boolean (logical) <tt>||</tt> and <tt>|||</tt>. The <tt>||</tt> operator preserves nulls (as expected by default) and the <tt>|||</tt> operator evaluates null values as false which is often advantageous. | ||
|- | |- | ||
| ~ | | ~ | ||
| ! | | ! | ||
| In GRASS GIS the boolean | | In GRASS GIS the boolean NOT operator is (one) exclamation mark (<tt>!</tt>) which is the same as in C. The ArcGIS equivalent is tilde (<tt>~</tt>) while in GRASS GIS tilde is a bitwise NOT operator (one's complement) which is the same meaning as in C or Python. | ||
|- | |- | ||
| ^ | | ^ | ||
| xor() | | xor() | ||
| A caret (<tt>^</tt>) in ArcGIS means boolean exclusive | | A caret (<tt>^</tt>) in ArcGIS means boolean exclusive OR (XOR) operator while in GRASS GIS it means exponentiation (an arithmetic operation). Boolean exclusive OR is done using a function <tt>xor()</tt> in GRASS GIS. | ||
|} | |} | ||
See all operators in GRASS GIS in {{cmd|r.mapcalc}} manual. | ArcGIS map algebra expression for the Raster Calculator in GUI for computing NDVI (output name is entered separately): | ||
Float("lsat7_40" - "lsat7_30") / Float("lsat7_40" + "lsat7_30") | |||
The same expression in GRASS GIS also for the Raster Calculator in GUI (output name entered separately as well): | |||
float(lsat7_2002_40 - lsat7_2002_30) / float(lsat7_2002_40 + lsat7_2002_30) | |||
Again the same expression but written as a module call for the command line: | |||
r.mapcalc "ndvi = float(lsat7_2002_40 - lsat7_2002_30) / float(lsat7_2002_40 + lsat7_2002_30)" | |||
See list of all available operators in GRASS GIS in {{cmd|r.mapcalc}} manual. | |||
=== Functions === | === Functions === | ||
Line 89: | Line 101: | ||
| GRASS GIS has two floating point numeric types. First is single precision floating point number (float) with corresponding raster map type is FCELL. Second is double precision floating point number (double) with corresponding raster map type is DCELL. | | GRASS GIS has two floating point numeric types. First is single precision floating point number (float) with corresponding raster map type is FCELL. Second is double precision floating point number (double) with corresponding raster map type is DCELL. | ||
|} | |} | ||
An expression in ArcGIS to use ''landclass'' value when ''landclass'' is 1 or 2 and null (NoData) value otherwise: | |||
Con( ("landclass" == 1) | ("landclass" == 2), "landclass", null()) | |||
The same expression rewritten to GRASS GIS map algebra is: | |||
if(landclass == 1 || landclass == 2, landclass, null()) | |||
The expression we used assumes usage in GUI. In command line, used in {{cmd|r.mapcalc}} module call, we would start it with the name of the output and the whole expression would be in quotes (as command line requires). | |||
An expression in ArcGIS to use values from ''landclass'' raster when ''lakes'' contains null (NoData) values and use values from ''lakes'' raster otherwise: | |||
Con(IsNull("lakes"), "landclass", "lakes") | |||
The expression now rewritten to GRASS GIS syntax as it would be used in command line: | |||
r.mapcalc "land = if(isnull(lakes), landclass, lakes)" | |||
In this case without the expression are very similar. The difference is lowercase <code>isnull</code>, name <code>Con</code> versus <code>if</code>. For the command line, we add also <code>r.mapcalc "land = </code> at the beginning and a quote (<code>"</code>) at the end. | |||
See list of all available functions in GRASS GIS in {{cmd|r.mapcalc}} manual. | |||
=== Further notes === | === Further notes === |
Revision as of 16:00, 21 August 2015
Projections
ArcGIS supports on-the-fly projection of spatial data while GRASS GIS considers this as a bad practice and requires user to have consistent projection for all the data entering the analysis.
Data, databases and file formats
In ArcGIS, users often have data in different directories on disk. GRASS GIS sets a specific system to organize the data. First, data must be in one directory called GRASS GIS database directory. You can have one or more of these directories on your disk. This directory contains GRASS Locations. All data in one Location have the same projection (coordinate system, datum). Location is a directory which contains GRASS Mapsets. Mapset contains raster and vector maps (layers) and other geospatial data.
Cartography
The standard display in GRASS GIS
3D visualization
In GRASS GIS, the 3D view is integrated into the main graphical user interface (GUI) while in ArcGIS suite, there is a separate tool ArcScene. The GRASS GIS library which is behind the 3D view is called NVIZ. The integration of NVIZ into GUI which is called wxGUI is called wxNVIZ. The 3D visualization is also available as a module called m.nviz.image (usable from command line or Python).
In GRASS GIS, when you are in 2D and you switch to 3D, all raster map layers are automatically added to the 3D view as surfaces. This means that if you have in 2D a digital elevation model, you will see it as a 3D visualization of terrain in 3D. The colors set will be the same colors as in 2D. This is different from ArcScene where the raster layer is initially flat and you have to specify in properties which raster should be used to create the surface.
Raster algebra
Current ArcGIS raster calculator is implemented in Python. Some parts of the syntax resembles Python while some others differ from it. In GRASS GIS the map algebra is available through r.mapcalc module (implemented in C) or its convenient GUI wrapper Raster Map Calculator. The r.mapcalc syntax is specifically designed for raster map algebra and is based on C syntax (Python is C-like language as well). Both syntaxes are case sensitive as it is common for C-like languages.
Quotes
In ArcGIS map algebra layer names must be quoted. In GRASS GIS, the quotes are optional and usually not used. There is few cases where it is necessary to use quotes and that is when raster map name contains dashes (which would be interpreted as minus operator). However, best practice is not to use dashes in map names at all (since map name should be ideally also usable without quoting in SQL). When writing Python script and you want it to be really robust. Then you may want to use quoting.
Whitespace
In ArcGIS map algebra operators must be surrounded by spaces. In GRASS GIS, the spaces around operators are optional, however it is a best practice to use them (same as in Python or C).
Operators
ArcGIS | GRASS GIS | Notes | ||||
---|---|---|---|---|---|---|
& | && | Boolean (logical) AND operator is one ampersand (&) in ArcGIS. In GRASS GIS, boolean AND operator is two ampersands (&&) which is the same as in C. Note that & means bitwise AND operator in GRASS GIS (as well as in Python or C). There is also &&& in GRASS GIS which doesn't propagate null values (which is the standard behavior) but instead, treats them as false. | ||||
| | || | and boolean (logical) | and | . The | operator preserves nulls (as expected by default) and the | operator evaluates null values as false which is often advantageous. |
~ | ! | In GRASS GIS the boolean NOT operator is (one) exclamation mark (!) which is the same as in C. The ArcGIS equivalent is tilde (~) while in GRASS GIS tilde is a bitwise NOT operator (one's complement) which is the same meaning as in C or Python. | ||||
^ | xor() | A caret (^) in ArcGIS means boolean exclusive OR (XOR) operator while in GRASS GIS it means exponentiation (an arithmetic operation). Boolean exclusive OR is done using a function xor() in GRASS GIS. |
ArcGIS map algebra expression for the Raster Calculator in GUI for computing NDVI (output name is entered separately):
Float("lsat7_40" - "lsat7_30") / Float("lsat7_40" + "lsat7_30")
The same expression in GRASS GIS also for the Raster Calculator in GUI (output name entered separately as well):
float(lsat7_2002_40 - lsat7_2002_30) / float(lsat7_2002_40 + lsat7_2002_30)
Again the same expression but written as a module call for the command line:
r.mapcalc "ndvi = float(lsat7_2002_40 - lsat7_2002_30) / float(lsat7_2002_40 + lsat7_2002_30)"
See list of all available operators in GRASS GIS in r.mapcalc manual.
Functions
ArcGIS | GRASS GIS | Notes |
---|---|---|
Con(a, b, c), Con(a, b, c, d) | if(a, b, c) | The most used conditional statement (if-statement) in both ArcGIS and GRASS GIS has raster algebra is a function with three parameters first is the conditional expression (condition), second is value to be used when the condition is fulfilled ("if-part") and third one is the value to be used when the condition is not fulfilled ("else-part"). ArcGIS also supports a syntax with four parameters where the first one is just the raster and the fourth one is SQL conditional expression. GRASS GIS has also a version with four parameters but it is a convenience for the cases where we need to decide among three values based on the the first parameter (raster or expression) being lesser than zero, zero or greater than zero. |
Con(a, b) | if(a, b, null()) | In ArcGIS, the expression Con(a, b) will return NoData (NULL) if a is true (or non-zero). In GRASS GIS, the expression if(a, b) would return 0 (a number zero) in this case. So, we explicitly specify the value null() for the case when a is false (or zero) using third parameter. The general syntax is if(a, b, c) and it is the preferred one because it is explicit and thus one doesn't need to remember the special behavior of the other versions when reading the expression. |
SetNull(a, b), SetNull(a, b, c) | if(a, null(), b) | ArcGIS function SetNull returns NoData (NULL) when first parameter is true. The optional third parameter is SQL query which can be used instead of the expression (the first parameter). The GRASS GIS function for returning NULL when condition is not fulfilled is standard if function used with three parameters where second one is null(). |
IsNull() | isnull() | |
Int() | int() | |
Float() | float(), double() | GRASS GIS has two floating point numeric types. First is single precision floating point number (float) with corresponding raster map type is FCELL. Second is double precision floating point number (double) with corresponding raster map type is DCELL. |
An expression in ArcGIS to use landclass value when landclass is 1 or 2 and null (NoData) value otherwise:
Con( ("landclass" == 1) | ("landclass" == 2), "landclass", null())
The same expression rewritten to GRASS GIS map algebra is:
if(landclass == 1 || landclass == 2, landclass, null())
The expression we used assumes usage in GUI. In command line, used in r.mapcalc module call, we would start it with the name of the output and the whole expression would be in quotes (as command line requires).
An expression in ArcGIS to use values from landclass raster when lakes contains null (NoData) values and use values from lakes raster otherwise:
Con(IsNull("lakes"), "landclass", "lakes")
The expression now rewritten to GRASS GIS syntax as it would be used in command line:
r.mapcalc "land = if(isnull(lakes), landclass, lakes)"
In this case without the expression are very similar. The difference is lowercase isnull
, name Con
versus if
. For the command line, we add also r.mapcalc "land =
at the beginning and a quote ("
) at the end.
See list of all available functions in GRASS GIS in r.mapcalc manual.
Further notes
Note that there are different algebras in GRASS GIS, namely it is 3D raster algebra which the same as the standard 2D one with few differences to accommodate 3D rasters and then it is temporal algebra which contains a lot of additional syntax to work with spatio-temporal data.
Cost analysis
Cost surface is defined differently in GRASS GIS and ArcGIS. Cost in GRASS GIS is cost to cross a cell while in ArcGIS it is cost to cross one map unit. So for example we define cost as time and we have 30 m cells and speed is 5 m/s. Then the cost value of the cell is 6 s in GRASS GIS and 0.2 s in ArcGIS.