Skip to main content
11 votes
Accepted

How to clip raster in GRASS GIS?

For cropping a raster map according to a vector map, you can use r.mask which also supports vector maps. Update 2018: Meanwhile there are v.clip and a new Addon r.clip available.
markusN's user avatar
  • 13k
5 votes

How to clip raster in GRASS GIS?

I know it's late, but for others who have the same question. Please try this: # limit your computational region to polygon_vector r.mask vect=polygon_vector # clip big_raster to polygon_vector (MASK ...
Huidae Cho's user avatar
4 votes

GRASS 7 environment setup for Python

I use this export GISBASE="path_to_your GISBASE" export PYTHONPATH="${PYTHONPATH}:$GISBASE/etc/python/" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GISBASE/lib" export GIS_LOCK=$$ export GISRC="/...
gene's user avatar
  • 55.1k
4 votes
Accepted

Connecting Python script external to Grass GIS 7 program in Windows 10?

The linked says you need to set environmental variables. This is done in Python using e.g.: import os os.environ['GISBASE'] = "/some/path" The syntax PYTHONPATH = 'C:\OSGeo4W\apps\grass\grass-7.0.4\...
wenzeslaus's user avatar
3 votes
Accepted

PyGRASS error: Could not load grass_gis.8.2

Hint: Let me recommend to use GRASS GIS 8 (and no longer 7.8). So, in a running GRASS GIS 8 session, run in python: import os import subprocess import sys # define GRASS data settings (adapt to your ...
markusN's user avatar
  • 13k
3 votes
Accepted

GRASS 7 environment setup for Python

Once a python script is running, changes to environment variables are no longer effective. They are set up right before runtime and the interpretor will not update them afterwards. PYTHONPATH can be ...
Luís de Sousa's user avatar
2 votes

grass GIS + spyder python script error

You can find the description of the error caused by sqlite3.dll here: WinGRASS errors. Having tried renaming all sqlite3.dll files, at least this error is temporarily fixed. However, the error due ...
Anshul Khandelwal's user avatar
2 votes

Adding GRASS module to QGIS 2.18.21

resolved this creating a .bat file with the line @"%GRASS_PYTHON%" "%GISBASE%/scripts/r.out.haralickFeatures.py" %* in the directory: C:\OSGeo4W64\apps\grass\grass-7.4.0\bin
user127368's user avatar
2 votes

How to use Python packages (GeoPandas, rioxarray) inside GRASS Python scripts?

I found a workaround for this: Instead of running Python scripts from within GRASS one can call GRASS from Python in any environment (that contains the desired packages such as geopandas etc) ...
pittyplaetsch's user avatar
1 vote
Accepted

Looping GRASS "v.extract" in python

If you prepare your where clause first, it should work (I use f-strings below): Edited Sorry for the mistake. If you enclose the where clause in double quotes, it should work. (tested here, this time)....
Micha's user avatar
  • 15.7k
1 vote
Accepted

How to process multiple GRASS GIS jobs with different regions in parallel?

From the described behavior, I think you are running everything in one process with shared set of environment variables (hard to sure without code, but likely). Things like WIND_OVERRIDE are ...
wenzeslaus's user avatar
1 vote
Accepted

Loading ADF file from National Elevation Dataset into GRASS with Python?

I think your problem is the output string. When you import a raster layer into GRASS you are creating a GRASS raster in the GRASS database, and with the internal format used by GRASS, not a file in ...
Micha's user avatar
  • 15.7k
1 vote

Watershed Delineation Loop - r.water.outlet resulting in NAN area while snapped

The coordinate system (projection or spatial reference) of outlets should be the same as that of the current mapset. If the current mapset is projected (not in lat/long), you need to reproject lat/...
Huidae Cho's user avatar
1 vote

How to execute a GRASS module developed in Python?

The first line of the script is actually an instruction to Jupyter. It must be left out: #!/usr/bin/env python #%module #% description: Compute and analyze viewsheds #% keyword: raster #% keyword: ...
Luís de Sousa's user avatar
1 vote
Accepted

How to set GRASS GIS environment variables in MacOS?

I finally found the solution: export GRASSBIN=/Applications/GRASS-8.2.app/Contents/Resources/bin/grass
Jonas Frei's user avatar
1 vote

GRASS GIS: Execute SQL query and save output

If you want to run an SQL query against a PostgreSql database (As I understand your need) You can use the basic Qgis tool : it's located in Database Manager menu in Qgis, you write the connection to ...
Maximilien jaffrès's user avatar
1 vote

Can't access rasters from PERMANENT mapset from Python

I cannot confirm this. I tested in a local mapset, and set the region to a raster map from PERMANENT, with no problem. Here's my code copied from the "simple editor": #!/usr/bin/env python3 ...
Micha's user avatar
  • 15.7k
1 vote
Accepted

Error while performing actions in GRASS GIS in Python

Several questions here. I'll try one by one... r.in.gdal -e input="D:...\ASTGTMV003_N19E073_dem" output=DEM File "", line 1 r.in.gdal -e input="D:\...\ASTGTMV003_N19E073_dem&...
Micha's user avatar
  • 15.7k
1 vote
Accepted

GRASS GIS 7.8 trigometric function of vector attribtue

The problem is that SQLite by default lacks log(), sqrt(), cos(), and other functions. To overcome this limitation you need an addition to SQLite for this: the "SQLite extended functions". ...
markusN's user avatar
  • 13k
1 vote

r.green error installation on GRASS

Please consider to update to GRASS GIS 7.8 (your installation 7.0.0 is very old), not only for relevant updates including the change to Python 3, but also to follow our infrastructure migration from ...
markusN's user avatar
  • 13k
1 vote

Creating reclass-rules-textfile within Simple Python Editor of GRASS GIS

You can take a look at existing Python code in the main GRASS GIS repository, for example here: https://github.com/OSGeo/grass/blob/master/scripts/r.reclass.area/r.reclass.area.py#L139 Here, the ...
markusN's user avatar
  • 13k
1 vote
Accepted

GRASS GIS: creating raster with a certain gradient and extent

From @mankoff Can you use r.plane? r.plane
MarcM's user avatar
  • 1,156
1 vote

How to calculate area of the output of r.water.outlet?

I routinely use this script: #!/bin/bash if [[ $# -lt 3 ]]; then echo "Parameters missing" exit 1 else BASIN=$1 X=$2 Y=$3 fi g.region --q rast=<flow_dir>...
Micha's user avatar
  • 15.7k
1 vote
Accepted

How to calculate area of the output of r.water.outlet?

You can use r.report on the outlet map right away after the r.water.outlet step. It calculates the area size in a user defined unit (m^2, ha, etc.)
markusN's user avatar
  • 13k
1 vote

Possible to convert v.net.spanningtree to QGIS custom script so don't need GRASS installed?

Grass standalone I would say it would be difficult to use v.net.spanningtree (or any other) without grass or at least a truncated version of it. Indeed, if you download the source code ( https://...
Victor's user avatar
  • 1,852
1 vote

GRASS 7 environment setup for Python

Now there is also a module under development that simplifies the process. See: https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly#Python:...
Stefan B.'s user avatar
  • 286
1 vote
Accepted

Problem with numeric variable in i.topo.corr

Found a solution: apparently the bash script read the variable $azim as a string and not as a number (I didn't know this could happen in bash). The workaround to avoid the problem is perform a ...
ciskoh's user avatar
  • 165
1 vote
Accepted

Making GRASS GIS 7 Ubuntu bash file work on Windows 7

So, I finally opened the ticket after a few years, and found the solution. The problem with renaming null and cell files is on Windows' side, nothing can be done about that. It is not possible to read ...
Hynek G's user avatar
  • 121

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