10
votes
Accepted
Fast way to convert raster to polygon shapefile in R
Use the terra package instead of raster and use as.polygons to polygonize.
Sample data maker:
library(terra)
maker = function(x,y){rast(matrix(sample(1:18, x*y, TRUE), x, y))}
# same scale as yours:
...
10
votes
Accepted
Getting x, y, slope in raster, using QGIS
You can use the algorithm Raster Values to points (or Raster Pixels to points Documentation link). Once the point layer is created you could export it as a csv file :)
10
votes
Make the pixel values of the DEM correspond to the actual heights
I had a similar SE-GIS question several years ago. The answer: by default, QGIS displays an estimate of the min/max values, which results in the unexpected values. To see this, open up the Min/Max ...
9
votes
Accepted
What could be causing these crazy pixel values when I rasterize a polygon?
You set all values to zero and you specify nodata value as zero. So you get an empty raster, all pixels have nodata. Since there is no min and max value in the image to show in the legend, QGIS ...
8
votes
Set raster values to a specific number
Use Raster Calculator with an if-condition, available since QGIS 3.22, with this expression:
if ("raster@1" >= 5 , 5, "raster@1")
8
votes
Accepted
Contrast enhancement on UInt16 data type to set the maximum value greater than 255 with PyQGIS
Default DataType of QgsContrastEnhancement is Byte (Reference). Specify DataType during instantiation.
Without specifying DataType:
e = QgsContrastEnhancement() # Qgis.Byte by default
e....
8
votes
Accepted
QGIS does not load Luxembourg TIF/TFW file
The TIFF doesn't have a projection set. If you set the projection to EPSG:2169 (LUREF / Luxembourg TM) it will display correctly.
7
votes
Displaying row/column of point in raster using QGIS
You can use the "Value Tool" plugin for QGIS.
7
votes
Accepted
Fill in small 'islands' with surrounding raster pixel values
You can give the SAGA processing tool "Majority Filter" from the processing toolbox a try.
Example before:
Example after (default settings used):
7
votes
Fill in small 'islands' with surrounding raster pixel values
As answered by @MrXsquared, SAGA handles it efficiently in a much simpler way. Alternatively, another way to achieve this in QGIS version 3.x is:
Make sure GRASS 7 plugin is installed.
From ...
7
votes
Accepted
Browse efficiently through multiple rasters using QGIS
Place your rasters in the group.
Switch the group as Mutually Exclusive Group in the context menu.
Use Space to turn visibility on and off.
If your rasters are in the nested groups it may be usefull ...
7
votes
Accepted
QGIS zonal statistics only non zero values
Convert raster pixels with value 0 to nodata cells using Raster Calculator. Divide the raster's value by itself: a division by 0 will return nodata.
For all other pixels, to keep the value as it is, ...
7
votes
Accepted
GDAL NoDataFill returns as int and won't write to copied raster
There were a couple of problems.
First of all, it's always usefull to run gdal.UseExceptions() at the start of your script. Then you would have gotten a error message on the line where you run gdal....
7
votes
Accepted
How to get Amersfoort 28992 in QGIS?
You hit the already classical problem: do not change the layers's CRS, instead use Menu Raster > Projections > Warp (reproject) (in case of raster layers).
Alternatively, you could have the same ...
7
votes
Shifting existing points (shapefile) to the highest raster pixel value in 5m buffer
Here's an approach that will work, but whether it works for you is going to come down to the size of your raster dataset, which you haven't included in the question.
First convert your raster data to ...
6
votes
Accepted
Generating new raster by combining the values of two separate ones in Python
You can use this script.
import rasterio
import numpy as np
# CHANGE paths
file1 = r"c:\path\to\raster1.tif"
file2 = r"c:\path\to\raster2.tif"
output = r"c:\path\to\outout....
6
votes
Accepted
QGIS - DEM - adding height to raster
Two ways to update the target raster directly without creating a temporary raster layer:
Use gdal_rasterize https://gdal.org/programs/gdal_rasterize.html with -add option.
-add
Instead of burning a ...
6
votes
Accepted
Importing text file Arc/Info ASCII GRID into QGIS
I noticed from the sample data that the prj file was missing. I just took the prj file from their sample data and it solved the issue.
Just take the content below and create a text file copy and ...
5
votes
PostGIS: type "raster" does not exist
For me the answer was: run create extension postgis_raster from a SQL client.
I had never used this extension, only vanilla postgis, but I was trying to install a PostGIS "add-on" that ...
5
votes
Accepted
Raster R package, points outside the grid
Since you set a custom resolution (10), the output raster doesn't have the same boundary box as the points layer, because the raster approximates to the closest value for defining the number of rows/...
5
votes
Fill in small 'islands' with surrounding raster pixel values
The gdal_sieve utility https://gdal.org/programs/gdal_sieve.html is made for this purpose.
gdal_sieve.py script removes raster polygons smaller than a provided
threshold size (in pixels) and replaces ...
5
votes
Accepted
Add polygon areas by roof orientation condition
You can use sum() with a filter, like this:
sum(area($geometry),filter:="DN">135 and "DN"<225 and intersects($geometry,get_feature('buildingpolygon',"buildingid",'...
5
votes
Accepted
Dropping one band in multi-band raster using ArcGIS Pro
One way is to use the Extract Band function. In your example:
Use your 5 band raster as the input raster
Select the 4 bands you want to retain by name or ID
Specify the output raster for the ...
5
votes
Accepted
How to remove NA value of legend when using R tidyterra?
Use na.translate=FALSE in the scale function:
ggplot() +
geom_spatraster(data=f,aes(fill=fac)) +
theme_bw() +
scale_fill_cross_blended_d(na.translate=FALSE)
Why isn't this documented? Well, ...
5
votes
Accepted
NoData masks in QGIS
First, you need to know what value is assigned to the nodata tag. You can see it in the Information tab of the layer properties:
The pixels currently have that value (-1.25 in my case). I assume in ...
5
votes
Changing 10m to 20 m Resolution in QGIS
There are at least 3 ways to change the resolution of a raster image with QGIS.
Use Layer-Export-Save as.. and give the resolution
Use Raster projections-Warp from the processing toolbox with an ...
5
votes
Accepted
Set raster values to a specific number
One tool you can use in QGIS is Reclassify by Table.
Your table should look like this:
5
votes
Calculating slope using the 3*3 window approach for elevation data
Here is a shotgun answer, detailing four common methods in deriving terrain attributes. Since you do not indicate a language nor software this is provided in a matrix index context. In an application ...
5
votes
Accepted
Reducing resolution of raster layer in QGIS: "Save as..." or "Align Raster..."?
If you are looking to change the resolution of a raster layer, your best option is probably the Warp tool (gdalwarp). You can choose from a full range of resampling methods, and set the output file ...
5
votes
Looping area calculations for multiple rasters in R
You can do this by reading the rasters into a list object then iterating through the resulting list, defining a function that operates on each raster.
This creates the list object containing rasters.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
raster × 9838qgis × 2757
r × 1744
arcgis-desktop × 1656
gdal × 886
python × 814
coordinate-system × 489
arcmap × 438
postgis × 397
clip × 396
arcpy × 392
geotiff-tiff × 388
dem × 373
raster-calculator × 356
vector × 344
polygon × 311
grass-gis × 291
shapefile × 276
pyqgis × 239
arcgis-10.0 × 215
arcgis-pro × 205
rasterio × 205
spatial-analyst × 180
geoserver × 176
arcgis-10.1 × 176