New answers tagged

2 votes

Geocoordinates to pixel value in GDAL?

Such a program "gdallocationinfo" exists already and it is one of the standard GDAL utilities. The usage is documented in https://gdal.org/programs/gdallocationinfo.html and the source code ...
user avatar
  • 51.5k
2 votes
Accepted

Updating/Setting Field on GML file not working

The first line of the docs states: OGR has limited support for GML reading and writing. Update of existing files is not supported. And even if it was supported, you're opening the file in read mode ...
user avatar
  • 51.7k
1 vote
Accepted

Transforming using ntv2 nadgrids is behaving different between GDAL 2.3.1 and GDAL 3.4.2

I got this issue figured out with help from the GDAL folks after posting a bug to the GDAL list here. The issue was that my original coordinates (4547442.8444401 5290333.4162611) were not located ...
user avatar
  • 397
2 votes
Accepted

How can I activate GeoTIFF compression in QGIS 3.x gdal_translate?

Try 'OPTIONS':'COMPRESS=JPEG|JPEG_QUALITY=60' I executed the tool manually in QGIS, pressed Ctrl+Alt+H to see the command syntax:
user avatar
  • 51.2k
0 votes

Transforming using ntv2 nadgrids is behaving different between GDAL 2.3.1 and GDAL 3.4.2

You could try setting the PROJ_LIB variable to the location of the PROJ data files on your computer if you haven't already tried that. You also need to set the GDAL_DATA and GDAL_DRIVER_PATH ...
user avatar
  • 1
0 votes

'NoneType' object has no attribute

I'd say make sure all the files that are associated with that shapefile (.cpg, .dbf, .prj, .sbn, .sbx, .shp, .shx) are all found in the same file folder.
user avatar
  • 1
0 votes

Split TIFF and shapefile into smaller parts

This is my first project with geo data and for some reason I thought if I split the tif I must do the shape at the same time, so there should be a command to do just that. My solution: Created a grid ...
user avatar
0 votes
Accepted

How to create a 3D DXF from ARCGEN with gdal ogr2ogr?

If you want to convert the ID column into a DXF layer, then you can use this code: ogr2ogr -dialect sqlite -sql "SELECT ID as Layer, geometry from import_polz" ^ -f "DXF" ...
user avatar
  • 1,322
0 votes

Python ImportError with libgdal, undefined symbol: opj_codec_set_threads

To spell this out a bit more, opj_codec_set_threads was introduced in OpenJPEG version 2.3.0, and the above error is due to an older version of this library.
user avatar
  • 1
1 vote

How to loop for create a multi-page TIFF (Layer Stack)

I like os walk in combination with collections defaultdict list for problems like this. You can store each date as a key, and the two files as values: import os from collections import defaultdict ...
user avatar
  • 51.2k
0 votes

Zonal statistics with GDAL only (not Python)

This is not a command-line solution however given the nature of need in the question, I think it might help be helpful. If my understanding is correct, you want to get the summary statistics for the ...
user avatar
  • 1
0 votes

Importing gdal in QGIS and PyCharm not working

In using this guide https://spatialgalaxy.net/2018/02/13/quick-guide-to-getting-started-with-pyqgis3-on-windows/ I was able to create a bat file that when run loads all the proper paths for @echo off ...
user avatar
  • 1,159
0 votes

GDAL raster shifting with python error: 'NoneType' object has no attribute 'GetGeoTransform'

To solve that, just put an r before the path: rast_src = gdal.Open(r'C:\temp\raster1.tif', 1)
user avatar
0 votes

"GDALWarpOptions.Validate(): hSrcDS is not set" when reading a VRT pointing to a STACTA

GDAL's STACTA driver was added in GDAL version 3.3. Even if using the rasterio 1.2.10 wheel it would only include GDAL 3.2.1, according to the CHANGELOG. The release notes for rasterio 1.3b1 state: ...
user avatar
1 vote
Accepted

Raster to Numpy array for aspecified area, search maximum value using ArcPy and numpy

The following code works by masking the raster and returning the max value then storing it in a dictionary for subsequent use. The two key optimisations are to use glob to create a list of tifs and to ...
user avatar
  • 38.4k
0 votes

Raster to Numpy array for aspecified area, search maximum value using ArcPy and numpy

Not tested, but if your extr1 is populated by 1, this (untested) should work: from arcpy.sa import * ONE = Raster(extr1) for raster in inras: R = arcpy.Raster(raster)*ONE arcpy.AddMessage(R....
user avatar
  • 21.4k
1 vote
Accepted

Specifying transformation method used by gdaltransform

Your transformation https://epsg.org/transformation_15851/NAD27-to-WGS-84-79.html is between NAD27 and WGS 84 and the input must be in NAD27 degrees like in this example: gdaltransform -ct urn:ogc:...
user avatar
  • 51.5k
1 vote
Accepted

gdal_translate TIFF to PNG with added alpha

By the driver documentation https://gdal.org/drivers/raster/png.html grayscale with alpha is not supported even the PNG format does support it http://libpng.org/pub/png/spec/1.2/PNG-DataRep.html I ...
user avatar
  • 51.5k
0 votes

Polygonizing global raster using Python/GDAL?

You can indeed split a raster into smaller tiles, but you will need to know the extents of each tile. gdal_translate and -projwin will give you the result you want. Another solution, one I have used ...
user avatar
0 votes

Installing QGIS with ECW support on ubuntu 20.04

Answer from comments and Can't install support for ECW in QGIS 3.6 / 3.4 on Ubuntu 18.04: You have to compile the same GDAL version used by QGIS with ECW support manually to use ECW inside QGIS.
user avatar
  • 74.9k
2 votes

gdal_calc - How to calculate where raster A is not equal to raster B?

From GDAL version >= 3.3, you can use --hideNoDatata option to ignore the NaNs in the calculation (it takes the NoData value as if it was a real value).
user avatar
1 vote
Accepted

Read geo-spatial data in R via Leaflet

Here's a sample sp-class points data frame in a projected coordinate system like your data is: > ps class : SpatialPointsDataFrame features : 4 extent : 1, 4, 1, 4 (xmin, xmax, ...
user avatar
  • 51.1k
0 votes

GDAL loop through gpkg layers

It is not straight forward to do that with a Windows batch file. The first step would be to read the layer list with ogrinfo, for example ogrinfo algeria.gpkg INFO: Open of `algeria.gpkg' using ...
user avatar
  • 51.5k
0 votes

ogr2ogr batch process tries to open zip files instead of .gdb

Ogr2ogr supports only one source datasource and one target datasource. The synopsis is documented in https://gdal.org/programs/ogr2ogr.html ogr2ogr [--help-general] [-skipfailures] [-append] [-update]...
user avatar
  • 51.5k
0 votes

Couldn't load plugin 'produce_training_data_for_deep_learning' due to an error when calling its classFactory() method

That type of error happens in QGIS2 (and i suppose that it does in QGIS3 as well) when you change something to the plugin UI (on QtDesigner) but forget to compile your .UI file into a .py file again. ...
user avatar
1 vote
Accepted

gdalwarp without reading the whole file, just coordinates

You can write to a VRT (GDAL Virtual format) gdalwarp args etc. infile outfile.vrt
user avatar
  • 51.7k
1 vote
Accepted

Trying to use GDAL in Windows Apache WSGI with Python 3.9.5 from OSGeo4W

After many hours of trial and error, before giving up, I made one last attempt that finally solved the problem. I removed the OSGeo4W GDAL installation from C:\OSGeo4W64\apps\Python39\Lib\site-...
user avatar
  • 3,623
0 votes

Inconsistent results between gdalWarp (with cutline) and rasterio.mask

You ask rasterio to use option "all touched" so maybe you should try the same with gdalwarp. Documentation must be searched in two steps, the main document https://gdal.org/programs/gdalwarp....
user avatar
  • 51.5k
1 vote

How to not generate .png.aux.xml files when using gdal2tiles?

Since this commit (2022-05-02) gdal2tiles does not write the .png.aux.xml files any more. Because the change is in the Python script there is no need to wait for the next GDAL release but users can ...
user avatar
  • 51.5k
3 votes

gdalinfo authenticate for remote file

For those who stumble upon this query, here is the workaround. GDAL throws this error because the response from the URL is not a TIFF but an html document asking the user to login. We need to send a ...
user avatar
0 votes

Creating a raster from overlapping shape files

You can use geocube to achieve what you want. I used this answer to create the below code which is a little bit more reduced than in the linked answer. import geopandas as gpd from geocube.api.core ...
user avatar
0 votes

Doubling of filesize with GDAL after transformation despite similar compression

Thanks to all your feedbacks. The culprit was simply precision and number of digits. gdal_translate doesn't seem to change decimals (i.e.: 2 digits stay as 2 digits) gdalwarp does bring more digits ...
user avatar
  • 641
3 votes
Accepted

How to not generate .png.aux.xml files when using gdal2tiles?

GDAL uses the .aux.xml files to store metadata, including statistics. You can disable completely by setting the environment variable GDAL_PAM_ENABLED=NO though I don't advise doing this permanently. ...
user avatar
  • 51.7k
1 vote

gdal2tiles.py generates wrong tiles / MapTiler the right ones

This question is a bit old, but there's now an "official" solution to this problem. Since GDAL version 3.1, gdal2tiles.py now includes a --xyz option. (For a full list of options see this ...
user avatar
1 vote
Accepted

Remove empty image - gdal_retile.py

I found that the .tif was actually being created on the lines if MemDriver is None: and not where t_band.WriteRaster() is located. So checking for an empty .tif should go right above that. See the new ...
user avatar
  • 896
2 votes

sf: Session aborts when reading large geopackage into R

Here's how to get a subset of a large geopackage layer if you can do a simple filter by attribute: This layer has 149 features: > p = st_read("flu.gpkg","localauth",quiet=TRUE) &...
user avatar
  • 51.1k
1 vote

How to create boundary (outline) polygon from raster grid (GeoTIFF floating point grid)

I would do it by this way: Use the raster calculator with this expression "raster@band" != nodata_value (replace: 'raster' with the name of your raster layer, 'band' with the band number ...
user avatar
  • 66
1 vote

ogrinfo - specify what information you want returned

The ogr2ogr utility is a general purpose tool and all that it can do is documented in https://gdal.org/programs/ogrinfo.html. There are some options for limiting the amount of output (-nocount -...
user avatar
  • 51.5k
0 votes

Using gdalbuildvrt in R gives Warning Message ... had status 1?

In my case, the following worked: gdalbuildvrt <- system2( command="gdalbuildvrt", args=c( "/path/to/mosaic.vrt", "/path/to/*.tif&...
user avatar
1 vote
Accepted

Rasterio to convert a GeoTIFF into a GeoJSON in Python

As Ian Turton points out, GeoJSON files can represent vector data, not raster data. In principle, you could first vectorize the raster data to polygons, and then save these as GeoJSON. But that is ...
user avatar
2 votes
Accepted

Python function to determine x and y extent of a raster

You can use Rasterio to read the xyz file and the bounds method to get the bounding box of the dataset. For example (sample data): import rasterio xyz = '/temp/small.xyz' dataset = rasterio.open(xyz)...
user avatar
  • 50.2k
1 vote

Doubling of filesize with GDAL after transformation despite similar compression

Your original might have used different compression options such as a predictor. Try this (if your values are floats, otherwise use PREDICTOR=2): gdal_translate output1.tif output2.tif -co COMPRESS=...
user avatar
  • 8,073
2 votes
Accepted

Is there any way of making gdal_rasterize or gdal_translate create transparent pixels on the output image created?

Burn a 4th band with 255, set it as the alpha channel. gdal_rasterize -burn 0 -burn 0 -burn 255 -burn 255 -ot Byte -tr 0.0000169959 0.0000169959 input.geojson image.tif gdal_translate -of PNG -ot Byte ...
user avatar
  • 51.7k
2 votes
Accepted

How can I use the <src_datasource> parameter from gdal_rasterize?

In your original command options -l input input.shp the input.shp is the datasource and input is the layer of the datasource that will be used. If the datastore can contain many layers, or if the ...
user avatar
  • 51.5k

Top 50 recent answers are included