Hot answers tagged

60

If I open QGIS with the shortcut "QGIS Desktop 3.6.0 with GRASS 7.6.0" everything works fine. If I open QGIS with the shortcut "QGIS Desktop 3.6.0" I get the same error as you. UPDATE for QGIS 3.20: Please use qgis.bat located in C:\OSGeo4W\bin as qgis-bin-g7.exe is missing in the latest version.


43

It can be done in one step in QGIS in the raster calculator. In QGIS3, for a raster layer named "x", use the following expression: (("x">0)*"x") / (("x">0)*1 + ("x"<=0)*0) This trick maps raster values x>0 into the ratio x/1 = x, and raster values x<=0 into the ratio 0/0 = NaN. This NaN is rendered as FLOAT_MIN (aka -3.402832...e+38) if the ...


37

I didn't find a one-tool solution, but you can first use raster calculator to turn all values below a certain threshold to zero and then use gdal_translate with -a_nodata 0 to turn the 0 into nodata.


31

Interesting question! It's something I've wanted to try myself, so gave it a go. You can do this in PostGRES/POSTGIS with a function which generates a set of polygons. In my case, I have a table with one feature (a MULTILINESTRING) which represents a railway line. It needs to use a CRS in meters, I'm using osgb (27700). I've done 4km x 2km 'pages'. Here, ...


20

According to Diego Alonso's comments from the mappingGIS blog1, this error is related to QGIS version 2.14. With the upgrade, the standalone installer eliminated the msys folder from GRASS 7 algorithms. To bypass this error, go to Processing -> Options -> Provider and deactivate all GRASS folders from previous versions. Set these paths as blanks. Then, ...


18

Here's the GRASS mapcalc expressions to set a range to NULL: r.mapcalc "dem_corrected = if(dem<=0, null(), dem)"


18

In QGIS Raster Calculator, the comparison return 0 (if false) or 1 (if true). So you can write a conditional using a sum of products. ((raster1@1 >0.3) * raster1@1 * raster2@1 ) + ((raster1@1 <=0.3) * raster1@1 * raster3@1 )


17

There's a bundled python script specifically for retiling rasters, gdal_retile: gdal_retile.py [-v] [-co NAME=VALUE]* [-of out_format] [-ps pixelWidth pixelHeight] [-overlap val_in_pixel] [-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/ CInt16/CInt32/CFloat32/CFloat64}]' [ -tileIndex ...


17

Here is a quick worked example of setting the GRASS environment, reading an on-disk raster, calculating a focal mean (using r.neighbors) and reading the results back into R. Hopefully this will get you started. if (!require(rgrass7)) stop("rgrass7 PACKAGE MISSING") setwd("D:/TMP") # Working directory # Set on-disk raster variable rname <- paste(getwd(...


15

My solution, based on the one from @wwnick reads the raster dimensions from the file itself, and covers the whole image by making the edge tiles smaller if needed: import os, sys from osgeo import gdal dset = gdal.Open(sys.argv[1]) width = dset.RasterXSize height = dset.RasterYSize print width, 'x', height tilesize = 5000 for i in range(0, width, ...


15

The Processing framework in QGIS can call these function directly from Python. From the QGIS Python console: >>>import processing >>>outputs_0=Processing.runalg("saga:ordinarykriging", vectorlayer_pointtable, z, True, 0, 0, True, 100, True, 0.0, 10.0, 100.0, 1.0, 0.1, 1, 0.5, 1000.0, 4, 20, 1.0, True, None, None, None) >>>...


15

You can also save the layer (right click, save as ...) and specify a nodata range. This will keep the original nodata and create new nodatas for the specified range of values.


14

The answer will depend on the requirements of your specific workflow and application but I can offer you advise on how a drainage network is generally extracted from a digital elevation model (DEM). The key to extracting a drainage network from a DEM is creating a flow accumulation raster, i.e. a raster for which each grid cell contains a value that is ...


14

@Steven Kays's answer in PyQGIS. Just select the lines in your layer before running the script. The script does not support the linemerging so it can not work on layer with multilinestring #!python # coding: utf-8 # https://gis.stackexchange.com/questions/173127/generating-equal-sized-polygons-along-line-with-pyqgis from qgis.core import (...


13

The idea is to merge all your shapefiles containing linestrings. You have to handle with unique identifiers that are characterizing your linestrings definitely, according to the distinct shapefiles. QGIS approach: Add the unique IDs to the attribute table of each shapefile if required: Open the attribute table, toggle editing and add a new column. Fill the ...


12

Tom Patterson, the lead cartographer at the U.S. National Parks Service has some excellent tutorials on working with DEM data to make beautiful shaded reliefs. Part of his workflow involves using Natural Scene Designer and Adobe Photoshop. For my own workflow I like to use GDAL to resample the size of the DEM before rendering a shaded relief. This often ...


12

There is differents solutions. And this can work with simple polyline and multiple selected entities block diagram: Parameters select orientation for generation and read index (left-to-right, north-to-south...) set object size shape = (4000,8000) # (<width>,<length>) define superposition coef (10% by default ?) init Ordering polyline (...


11

What is not mentioned, yet: QGIS and GRASS GIS - both can be run as a completely separate software However, GRASS GIS algorithms are included in QGIS processing toolbox (can be excluded or included during the installation of QGIS software). Thus, GRASS algorithms (similarly as GDAL, SAGA, R scripts, or other activated providers) can be used directly from ...


10

If you want to develop a module for GRASS GIS as a Python script or just a script which uses GRASS GIS (which is, in fact, almost the same), start with http://grasswiki.osgeo.org/wiki/GRASS_and_Python. You need to be in GRASS session and start a Python script from there, then you can import from grass.script import core as gcore which enables you to call ...


10

Many thanks to Dominik. My first answer is not correct for QGIS 2.8.3 (the expression "myraster@1" > 0 returns 0 or 1 for non-nodata input, for nodata input it returns nodata). The following QGIS Raster Calculator expression should be sufficient (raster layer named "myraster"), since the QGIS Raster Calculator sets all pixels that do not satisfy the ...


10

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


9

I finally got a workaround for the problem, based on Micha's suggestion (thank you!) to import the raster to GRASS and vectorize it there. 1 Import Raster: r.in.gdal input=raster.tif output=raster 2 Vectorize (option -s leads to slightly smoothed 45-degree edges): r.to.vect -s input=raster output=vector_blue feature=area 3 Generalize with Douglas to ...


9

I develop a free and open-source GIS called Whitebox Geospatial Analysis Tools (can be downloaded here) that has extensive analysis functionality for processing LiDAR data. Whitebox contains a tool specifically for calculating the point-density of LiDAR LAS files called Point Density LiDAR. The tool is highly specific to LiDAR, taking one or more LAS files ...


9

In spatial hydrology, DEM-based flow accumulation operations are typically static. That is, they represent a steady-state condition of the discharge of surface and near surface water passing through a point. Flow accumulation grids are actually accumulating contributing area downslope, i.e. areas not volumes. The accumulated cells that you described is ...


9

I get the same error with the Ubuntugis version of QGIS and GRASS version 7.2.0. It seems that 7.2 is not yet correctly adopted in processing. There is already a ticket for it: https://hub.qgis.org/issues/16019 and https://lists.osgeo.org/pipermail/qgis-developer/2017-January/046671.html As a workaround, you may edit (as sudo) /usr/share/qgis/python/...


9

You need to adjust the "threshold" parameter, which is Minimum flow accumulation for streams in the Processing GUI. With this parameter you determine what is the minimum drainage area for each stream reach. THe units are pixels. So in the above image, with Minimum flow accumulation=1 you will be creating a very dense stream network, where each and every ...


9

Ok, this is slightly embarrassing but I'll post the answer here anyway in case someone is as blind as I was. Apparently, there are two QGIS executable files: C:\OSGeo4W64\bin\qgis-bin.exe and C:\OSGeo4W64\bin\qgis-bin-g7.4.1.exe. In Windows, when firing up a program via the Windwos startup button, it runs qgis-bin.exe by default and GRASS does not work. When ...


8

I used GIMP plugin wavelet noise reduction tool and I get good results and fast: GIMP Plugin Wavelet noise reduction


8

For the record - You can now do this easily with QGIS alone (since later QGIS versions): first use 'explode lines' tool, yielding all line segments, then calculate azimuth with field calculator: degrees(azimuth( start_point($geometry), end_point($geometry)) ) finished..


8

The current version of QGIS (QGIS 3.0+) has the option to Force segments to be exactly of a given length, except for the last one using v.split. v.split is accessed from the Processing Toolbox under GRASS --> Vector


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