Hot answers tagged

15

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). After adding a value one need to change the "Percent Transparent" column to zero. After Applying this you can see the padded values as black.


15

In QGIS, you can use Raster Calculator with the following calculation: ("your_raster" != -32768) * "your_raster" With this calculation, if the cell value is -32768 you will get a 0 in that cell and if it is different from -32768 the cell will keep the value it had.


13

The simplest one-step and, IMO, most consistently reliable solution to reclassifying NoData to zero is to use the Reclassify Grid Values tool (SAGA) in the processing toolbox. After selecting the raster to be reclassified, simply scroll to the bottom of the dialog, ensure the box replace no data values box is checked. The default value is zero (but you can ...


12

What you want to do is Set Raster Properties in a script or change it manually in ArcCatalog. This will not create a new raster or even take very long. In python it's a bit tricky: import sys, os, arcpy InFolder = sys.argv[1] arcpy.env.workspace = InFolder for Ras in arcpy.ListRasters(): arcpy.AddMessage("Processing " + Ras) arcpy....


10

There is a bug that seems to correspond to what you're experiencing - it's registered as BUG-000084883 - The 'Ignore NoData in calculations' option in Zonal Statistics as Table tool {and Zonal Statistics tool} is not honored when checked off, producing incorrect results. It occurs with 10.3 and 10.2.2 but not 10.1. Did you try the tool with this version?


9

It is a bug. Something terribly wrong with cell count. Correct mean (9.0452380952381) times correct number of non-empty cells (420) divided by 297 (that is a cell count reported by tool) results in 12.7912457912458. That is a wrong average reported by tool. Results of my own toy size grids test:


8

Having the same problem, in the end I used Python directly -- you may have to adjust numpy.where for your specific purpose. In the case below, the pixel values are kept as they are if they are >= 0, all other pixels -- in this case this is only ones with the no-data value -- are set to "0" import gdal, gdalconst, numpy maskfile = gdal.Open('C:\Users\max\...


8

Shapefiles, which use the older dBase specs, do not support null values. If you must maintain null values and you have to keep the file format to shapefile, you'll need to use a representative or 'nodata' value for it. This can be any value you wouldn't normally encounter or expect to encounter in the data, or that even falls within valid data's range, such ...


8

You are incorrect in assuming that "the no data values are assigned -Inf". (I understand that you get that idea from "@ nodatavalue : num -Inf", but that is not how it works when the driver is "gdal".) The canonical way to change cells with NA to another value is y <- reclassify(x, cbind(NA, 10000)) While it is possible to do x[is.na(x)] <- 10000 ...


7

When using the Raster Calculator in ArcToolbox (version 10.3.1) the Con function is expressed as follows for a raster that is named "streams": Con(IsNull("streams"), 0, "streams") this returns zero if streams is null else it returns the value of streams. In this example all NoData pixels in the Streams are set to zero, otherwise they contain the pixel ...


7

That method ('noDataValue') is in QgsRasterBlock class (not in QgsRasterLayer). To get access to this method you can try out this code: layer = iface.activeLayer() extent = layer.extent() provider = layer.dataProvider() rows = layer.rasterUnitsPerPixelY() cols = layer.rasterUnitsPerPixelX() block = provider.block(1, extent, rows, cols) print block....


6

You can use the r.null.to function via GRASS to transform all NULL value cells into a user-defined value, which in your case is 800: Note: You will have to create a GRASS Mapset before you can use r.null.to as it is not available in the Processing Toolbox. Once you created a mapset, use the GRASS option to add a raster layer, select Open GRASS Tools and ...


6

There is a useful method using Con and IsNull statements in the raster calculator to convert NoData to a different value. HowTo: Convert NoData values to other values for raster data


6

Agree to the comment of @FelixIP, one possible solution is to first create a whole raster using RasterMosaicker transformer, then reproject and re-tile the Raster with RasterTiler transformer. This can be a ressource consuming approach, if you have many input tiles. Another approach is to apply nodata values with the RasterBandNodataSetter (Value = 0) or ...


6

The method 'setNoDataValue' is in QgsRasterDataProvider. You can use next code to try it out. It worked for me. layer = iface.activeLayer() provider = layer.dataProvider() provider.setNoDataValue(1, 0) #first one is referred to band number layer.triggerRepaint()


6

This can be done using the unmask function on your image, which allows you to set a value of your choice for the masked pixels. .unmask(-9999) An example script building on your question: https://code.earthengine.google.com/87f1a9d5193c562ff016fd4b13c45720


6

Python works pretty well for this: from osgeo import gdal from osgeo.gdalconst import GA_Update filename = 'somefile.tif' nodata = 0 # open the file for editing ras = gdal.Open(filename, GA_Update) # loop through the image bands for i in range(1, ras.RasterCount + 1): # set the nodata value of the band ras.GetRasterBand(i).SetNoDataValue(nodata) # ...


5

The Euclidean Allocation tool can accept your polygon as input, but you are right you need to set the values inside the polygon to NoData for this tool to work, otherwise it will pick up the values that are already there. First to feature to polygon, this will give values (any value, it doesn't matter, we're only interested in value or NoData) inside the ...


5

This is potentially a very difficult problem when the borders are ragged. A brute-force search of the optimum could require computational time that is proportional to the square of the number of cells in the image (a value that often will be in the billions, trillions, or greater). One promising approach is to relax the conditions a little bit and actually ...


5

As you have reclassified this raster I'll assume that you have access to the Spatial Analyst extension, so will continue with instructions that require this extension. The tool you want to use is Con, although you can do it with Extract by Attributes Con gives you more control over the 'false' case. Your SQL statement has the potential to be quite long ...


5

You can get a Numpy masked array that covers up nodata values from Rasterio by adding a keyword argument: src.read(1, masked=True). Operations on a masked array do not use the covered up elements. If your dataset has no defined nodata value, but you want to use for example 0, read out a non-masked array and mask it yourself: image_read = src.read(1) ...


5

An alternative approach (without altering your input data with gdal_edit) could be using GDAL VRT files as intermediate operands in gdal_calc and -a_nodata none in gdal_translate to skip the NoData values. For instance, if the original NoData value = 0: gdal_translate -of VRT raster1.tif raster1.vrt -a_nodata none gdal_translate -of VRT raster2.tif raster2....


5

If you want to filter no data and get raw values you need following code: import numpy as np from osgeo import gdal, gdal_array dataset = gdal.Open("path/to/file.tif") array = dataset.ReadAsArray() lst = [ element for v in array for element in v if element > 0 ] print lst I tried it out with a raster with no data values equal to -999 and it works ...


5

The two functions from the code snippet below, create_raster and numpy_array_to_raster should do the trick. In terms of maintaining the NoData value from the array in the output raster, that is set on the band(s) of a raster with the .SetNoDataValue() method which in this code snippet is used in the numpy_array_to_raster function. For more information about ...


5

Short; It will actually depend on what NO DATA values mean; are they representing missing values during acquisition? Or, as the production of these images requires many processing steps, erroneous values may occur during some of them? Keep also in mind that the 3 channels must be registered after acquisition, hence you can imagine them are initially almost ...


4

I have managed to find a workaround, although it relies on there being an "extent" shapefile that came with the original DEM. I'd still like to know what I'm doing wrong in my original method, if anything. gdalwarp -co "BIGTIFF=YES" -dstalpha -cutline dtm20m_ext_vg94.shp dtm20m-3785-hs.tif dtm20m-3785-hs-cut.tif This produces the right kind of TIF: ...so ...


4

This is the default NoData value for QGIS. It is the smallest possible value for a signed 32-bit float data type (I think you meant to type a minus in front of the value you quoted). You need not worry about a NoData value appearing especially if non of your data is NoData. QGIS won't suddenly allocate some data cells as NoData. It is just part of the ...


4

One solution may be this batch script: set nodatavalue=-99999 gdalwarp -srcnodata None rasterB_with_NoData.tif rasterB_without_NoData.tif python gdal_calc.py -A rasterB_without_NoData.tif --outfile=rasterB_updated_with_NoData.tif --calc="(A<>%nodatavalue%)*A" gdalwarp -srcnodata None rasterB_updated_with_NoData.tif rasterB_updated_without_NoData.tif ...


4

Sorry, by definition, rasters are rectangular in extent. The best you can do is convert the NoData cells to a value using a Raster Calculator with the map algebra expression: Con(IsNull("myraster"), 0, "myraster") ArcGIS Help 10.2: NoData in Raster Datasets


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