Hot answers tagged

38 votes
Accepted

Create polygons of the boundary of a Raster in R

Here is an example. library(raster) # example data x <- raster(system.file("external/test.grd", package="raster")) To get the rectangular extent e <- extent(x) # coerce to a ...
Robert Hijmans's user avatar
37 votes
Accepted

numpy array to GTiff using rasterio without source raster

This ended up being more straightforward than I thought, with all of the capabilities lying in the rasterio.open function. Here is an example using a proj4 string instead of wkt. import rasterio ...
Bryce Frank's user avatar
  • 1,272
33 votes

Finding Georeferencer in QGIS

Since version 3.26 it has moved to the Layer menu because it now supports both raster and vector data. This is now documented, though it wasn't when the question was asked.
user2856's user avatar
  • 64.8k
32 votes

Python - Extract raster values at point locations

I use rasterio and geopandas. My example uses UTM coordinates. Obviously these fields will depend on your particular shapefile. In my experience this produces indentical results to the QGIS Point ...
Charlie Parr's user avatar
  • 1,894
30 votes

Extracting raster values at points using Open Source GIS?

I was having problems with the QGIS and SAGA GUI tools mentioned in this thread (Raster values to points was failing for some reason and throwing unhelpful errors and the GRASS v.sample created a ...
Ian's user avatar
  • 465
26 votes
Accepted

Extracting EPSG from a raster using gdal bindings in Python

I found the following workaround. I am unsure if it is the most efficient, but it does work for me. from osgeo import gdal, osr path = r"C:\temp\test2.tif" d = gdal.Open(path) proj = osr....
Lennert De Feyter's user avatar
26 votes

Make shapefile from raster-bounds in Python

With shapely box and GeoPandas import rasterio as rio ra = rio.open("raster.tif") bounds = ra.bounds Convert bounds to shapely geometry from shapely.geometry import box geom = box(*bounds) print(...
gene's user avatar
  • 54.4k
25 votes

Python equivalent of gdalbuildvrt

The answer of @rcoup only worked for me, if modify it as follows: from osgeo import gdal vrt_options = gdal.BuildVRTOptions(resampleAlg='cubic', addAlpha=True) my_vrt = gdal.BuildVRT('my.vrt', ['...
JensL's user avatar
  • 351
25 votes
Accepted

How to efficiently access files with GDAL from an S3 bucket using VSIS3?

I've found when something isn't particularly well documented in GDAL, that looking through their tests can be useful. The /vsis3 test module has some simple examples, though it doesn't have any ...
user2856's user avatar
  • 64.8k
24 votes

Splitting raster into smaller chunks using GDAL?

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 ...
mikewatt's user avatar
  • 4,963
23 votes

Performing Raster Reclassification in QGIS

I was able to reclassify a raster using the raster calculator Here the "Habitat" raster is reclassed from continuous values (0-1) to discrete values of 1,2,3 ("Habitat@1" < 0.3)* 1 + (("Habitat@...
knussear's user avatar
  • 331
22 votes

Removing small areas from raster layer using QGIS?

I suppose your pixel size is 10m². You could use the gdal sieve function you can find in the Raster menu to remove lonely pixels. You can also launch it by searching in the command line : Processing ...
gisnside's user avatar
  • 7,798
21 votes
Accepted

Using continuous color band for raster legend in QGIS composer legend?

A bit of a hack round to get composer to do this in QGIS 3 Add your legend, then adjust the symbol size in your legend to something small (example is 1.5mm). You'll still see white lines dividing ...
mapping dom's user avatar
  • 1,492
21 votes
Accepted

"AttributeError: 'QgisInterface' object has no attribute 'legendInterface'" in PyQGIS 3

You could just replace layers = iface.legendInterface().layers() with layers = [layer for layer in QgsProject.instance().mapLayers().values()]
Joseph's user avatar
  • 75.3k
21 votes
Accepted

Finding pixel location in raster using coordinates?

A rasterio way of doing this is pretty simple. Note this requires your raster be in the same projection as your coordinates. You can of course project your coordinates on the fly, but that's another ...
user2856's user avatar
  • 64.8k
20 votes
Accepted

How to display NoData of a raster in QGIS

You can display raster NoDataValue in LayerProperties / Transparency tab by unchecking the "No data value" checkbox and "adding values manually" to the "transparent pixel list" table (green plus sign)....
Qfwfq's user avatar
  • 316
20 votes

How to convert raster to point in QGIS

QGIS 3.4 There tool is a Raster pixels to points tool newly added in QGIS 3.4 (Oct./2018). Raster pixels to points This tool works with astonishing speed. When I converted 11-megabyte single band ...
Kazuhito's user avatar
  • 30.5k
20 votes
Accepted

Processing vector to raster faster with R

I tried to "parallelize" the function rasterize using the R package parallel in this way: split the SpatialPolygonsDataFrame object in n parts rasterize every part separately merge all the parts into ...
Guz's user avatar
  • 3,166
20 votes

R raster: masking a raster by polygon also remove cells partially covered?

The documentation is indeed a little confusing. It states that: [...] all cells that are not covered by the Spatial object are set to updatevalue But actually, here covered means only if the ...
Matifou's user avatar
  • 1,981
19 votes

Modifying single Pixel values in QGIS?

Since this is the #1 Google result for 'qgis raster editing' at this time, I thought I'd add that there is now the 'Serval' plugin that lets you modify pixels much like in Paint. How to use: https://...
Roel's user avatar
  • 456
19 votes
Accepted

Fill the gaps using nearest neighbors

You can fill in the NA values using the focal function with the na.rm argument set to FALSE and pad to TRUE. library(raster) r <- raster(matrix(1:16, nrow=8, ncol=8)) r[r==12] <- NA ...
Jeffrey Evans's user avatar
19 votes
Accepted

Rasterio: Use case for src.meta vs. src.profile when reading and writing rasters?

The meta property contains the basic raster metadata. The profile property is a super set of meta which includes dataset creation options (i.e inc. tiling, block size, compression etc...). You would ...
user2856's user avatar
  • 64.8k
18 votes

Deleting one band from raster file?

If you know how to access gdal from the OSGeo4W command line shell which comes with QGIS, you could try gdal_translate to export the first 3 bands: gdal_translate -b 1 -b 2 -b 3 input.tif output.tif
Joseph's user avatar
  • 75.3k
18 votes
Accepted

Crop a raster file in R

Create a box as a Spatial object and crop your raster by the box. e <- as(extent(-16, -7.25, 4, 12.75), 'SpatialPolygons') crs(e) <- "+proj=longlat +datum=WGS84 +no_defs" r <- crop(...
Kazuhito's user avatar
  • 30.5k
18 votes

Pros and Cons of using Bilinear Interpolation and Cubic Convolution when dealing with DEMs?

What you are dealing with is interpolation techniques. That is, you have two data points, and need to estimate the value of a point in-between. There are many such available, but the three main ones ...
Roberto Ribeiro's user avatar
17 votes

Plotting map resulted from kriging in R

In order to interpolate prices with kriging you first need to convert your geographic coordinates to projected coordinates. Assuming you have them, below there is a reproducible example, showing a way ...
Andre Silva's user avatar
  • 10.2k
17 votes

How to speed up raster to polygon conversion in R?

There is a "new" method from the stars package, which revolutionized the workflow for me (I was using the gdal_polygonizeR function previously). It has been faster than the John Baumgartner solution ...
Mikko's user avatar
  • 374
17 votes
Accepted

Clipping tiff raster image using bounding box with GDAL in python

Since GDAL 2.1 (more info here) GDAL and OGR utilities can be used as library functions, so this task is incredibly simple now: from osgeo import gdal ds = gdal.Open('original.tif') ds = gdal....
Antonio Falciano's user avatar
17 votes
Accepted

Remove NA from Raster Layer

A raster is an array and is always square (rectangular), regardless of where the data occurs. Unless you have a perfectly square extent of data you will have NA values, this is part of the point of ...
Jeffrey Evans's user avatar

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