8

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 available: r.clip


5

How about this: import grass.script as grass grass.run_command('g.region', n=10, s=9, e=35, w=33, ewres=0.1, nsres=0.2, verbose=True, flags='p') projection: 3 (Latitude-Longitude) zone: 0 datum: wgs84 ellipsoid: wgs84 north: 10N south: 9N west: 33E east: 35E nsres: 0:12 ewres: ...


4

After some hard work, I got my GRASS working with Python using a .pth file in the sitepackages folder. To try this, do to the following steps: Go to the folder C:\OSGeo4W\apps\python27\lib\site-packages Create a file called grass.pth and open it with an editor Enter the following two lines (assuming your GRASS was installed with OSGeo4W; check the paths to ...


4

Well, you can do that using ogr2ogr, after exporting vectors from GRASS to shp: ogr2ogr -sql "SELECT * FROM file_in WHERE 'category' == 2 AND OGR_GEOM_AREA > 10000" file_out.shp file_in.shp file_in.shp is your data exported from GRASS file_out.shp is your filtered results. Then you can run: ogr2ogr -sql "SELECT count(OGR_GEOM_AREA) FROM file_out" ...


4

If you want to do that with PyQGIS, the def Val_raster(x,y,layer,bands,gt) of Python Script for getting elevation difference between two points becomes: def Val_raster(point,raster): return raster.dataProvider().identify(point,QgsRaster.IdentifyFormatValue).results().values() for point in points.getFeatures(): geompt = point.geometry().asPoint() ...


4

The raster If your raster is not in a the current region, all the values are nan Therefore by security from grass.pygrass.gis.region import Region current = Region() current.align('aspect') Then elev=raster.RasterRow('aspect') # one of my raster layers elev.open() elev.is_open() True elev.get_row(1) Buffer([ nan, nan, nan, ..., nan, nan, nan], ...


4

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="/path_to/.grass7/rc" Then with Python import grass.script.setup as gsetup gisbase = os.environ['GISBASE'] gisdb="path_to_your_GISDBASE" location="Geol" mapset="test" ...


4

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\etc\python' in Python just sets a variable (global one in your case) which is just a Python variable, nothing more, nothing less. The aforementioned wiki just ...


3

You are confusing two different issues: the Grass plugin (Joseph answer and the new GRASS Plugin ready) and Grass in the Processing Toolbox: 1) with the GRASS plugin, you work in GRASS GIS and you must use v.in.ogr to import your shapefile in the original GRASS GISDBASE (locations, mapset) -> The Joseph answer 2) a GRASS script in the processing toolbox ...


3

From QGIS 2.10 onwards, GRASS is no longer enabled by default. From the Start menu, you can select to start QGIS with GRASS: When it's loaded, you can open a mapset from the Plugins menu: To show the GRASS toolbox, right-click on the toolbar to get the menu to enable/disable panels and toolbars and select GRASS Tools: You should, hopefully, see the GRASS ...


3

You have two options, one in pure Python and the second, more classical, parsing the commands of GRASS GIS. 1) in pure Python If I look at GRASS Programmer's Manual: Python (with the version 6.4.3) I still haven't found a way to write data (attributes) to GRASS vectors from Python. But it's possible and easier with the version 7: GRASS 7 Programmer's Manual ...


3

For all I figured out, it is not possible to automate the heatmap - but GRASS has triweight KDE estimates, and CAN be scripted. Here is the general setup, to be put into a BASH file: http://geoinformatics.fsv.cvut.cz/gwiki/On_scripting_GRASS_GIS:_Building_location-independent_command_line_tools Heatmap generation from constituency.shp to constituency.tif ...


3

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 updated using the method sys.path.append() and that is all. A workaround is to re-execute the script after setting up the environment. This way the interpreter ...


2

It seems you don't have libfreetype-6.dll installed on your system. Just launch the OSGeo4W Network Installer (64 bit) > Advenced Install, type freetype in the search box and perform the freetype packages installing. Then, libfreetype-6.dll must be installed on your computer:


2

I've found a solution for LINUX. The bash scripting here is very comfortable. So you have to transfer the ideas explained here to windows. For this purpose you can use cygwin. Import your vector layer with the point features: v.in.ogr -o dsn=/your_shapefile_directory layer=your_vector_layer output=points The same for your raster map. I've imported an ...


2

From d.rast d.rast displays raster map layer(s) name in the active display frame on the graphics monitor. You need to first start and select a graphics monitor with d.mon but from d.mon doesn't work (WinGrass commandline) X monitors do not exist in native MS windows. You must use the GUI On Mac OS X or Linux with a X monitor: GRASS 6.4.3 (geol):~ ...


2

Only a small modification is needed: You need to generate the group prior to exporting (i.e., use i.group), then export to a multilayer file by assigning the group name as input in the r.out.gdal call.


2

The answer above, in accordance with the title of your question, refers to scripting in a bash shell. (Not python). If you would like more information on bash scripting, have a look at this tutorial (referred from the GRASS bash scripting wiki page If you want to work in python, then the language is quite different. For example, to loop thru a directory of *...


2

The proper syntax is: for file in $(ls *.tif); do r.in.gdal input=$file output=${file%.tif}; done; Where you gather the individual values provided by ls and iterate through them, so you have to put a variable sign($) before the ls command and put it between brackets. When you call for the file variable later, you can either call for $file as in the input ...


2

You can take the g.region -a (for 'align') option. This will align the region to the resolution.


2

That's because $MAPS doesn't exist from windows command line. You need to call variables with %MAPS% (surrounded by % sign). But also consider that grass when installed either from the grass site using the stand alone installer or osgeo4w they both come with MSYS - a unix like shell. You can use that instead which lets you stay with bash like syntax.


2

This bat file starts spyder for me and imports grass.script fine: @echo off rem set OSGEO4W_ROOT=c:\OSGEO4W64 rem set PATH=%OSGEO4W_ROOT%\bin;%PATH% call c:\osgeo4w64\bin\o4w_env.bat call %OSGEO4W_ROOT%\apps\grass\grass-6.4.3\etc\env.bat set GDAL_DRIVER_PATH=%OSGEO4W_ROOT%\bin\gdalplugins\1.9 set PATH=%PATH%;%OSGEO4W_ROOT%\apps\qgis\bin set PATH=%PATH%;%...


2

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 set by r.mask above) r.mapcalc ex=clipped_raster=big_raster # export r.out.gdal input=big_raster output=clipped_raster.tif


2

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 to spatialite.dll still remains an issue.


2

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


1

You mentioned that your point text file was created with v.out.ascii. That module adds a third column with the cat value. So you'll have to add to your "while read" loop like so (even though you don't need the cat value): while read X Y cat; do....


1

GRASS GIS has made it very easy to calculate both spatial as well as temporal descriptive statistical summaries. To get the statistical summaries such as mean, median, standard deviation etc. for each raster layer saved within GRASS t.ras one can use t.rast.univar This function creates statistical summaries for each of the layer. By checking the advance ...


1

GRASS GIS addin r.sun.hourly can be used to calculate instantaneous solar radiation flux(w/m2) at an specified interval. By default it is set to run at an hourly instance however by changing the 'time_step' parameter can change the time instant for the run. For eg if you want the total irradiance every two minutes, this is how the parameters would look like. ...


1

I think I understand now. Let me know if this is not what you're looking for. >>> import subprocess >>> p = subprocess.Popen(['v.in.ascii', 'input=/home/username/Desktop/temp.txt', 'output=raster_pnts','x=1','y=2','fs=\',\'','--o'],stdout=subprocess.PIPE, stderr=subprocess.PIPE) >>> stdoutdata, stderrdata = p.communicate() >>...


1

I would point out, in addition, that the GRASS model, v.what.rast takes a point layer and raster layer as input and uploads the raster values to a given attrib column for all points. To run this in the python console (within a GRASS session) you would do something like: import os import grass.script as grass input_points = "<your point list>" ...


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