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 ...
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
...
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.
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 ...
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 ...
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....
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(...
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', ['...
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 ...
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 ...
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@...
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 ...
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 ...
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()]
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 ...
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)....
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 ...
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 ...
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 ...
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://...
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
...
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 ...
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
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(...
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 ...
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 ...
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 ...
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....
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
raster × 9830qgis × 2755
r × 1743
arcgis-desktop × 1655
gdal × 885
python × 813
coordinate-system × 489
arcmap × 438
postgis × 397
clip × 396
arcpy × 392
geotiff-tiff × 386
dem × 372
raster-calculator × 356
vector × 343
polygon × 311
grass-gis × 291
shapefile × 275
pyqgis × 239
arcgis-10.0 × 215
rasterio × 205
arcgis-pro × 204
spatial-analyst × 180
geoserver × 176
arcgis-10.1 × 176