Wednesday 24 June 2015

Gdal/QGIS resampling asc file


I have a DEM (.asc) file with a resolution of 1000 meters per pixel. Therefore the file has a lot of columns and rows. I would like to chance the resolution per pixel from 1000 to 3000 meters per pixel. So i would like to resample it.


which gdal command do i use for this? i know it's gdalwarp but how is the exact command line with the extra options?


if you know how to do it in QGIS I'm also happy with it.



Answer



The task could feel trivial by reading the gdalwarp documentation http://www.gdal.org/gdalwarp.html and GDAL AAIGrid -- Arc/Info ASCII Grid driver documentation http://www.gdal.org/frmt_various.html. The target pixel size is three times bigger than the native resolution 0.008333333333 degrees/pixel (not 1000 m/pixel, see the comments).



gdalwarp -of AAIGrid -tr 0.024999 0.024999 input.asc output.asc

However, it is a bit more difficult than that.



  • gdalwarp does not support AAIGrid format as direct output format

  • The default resampling method of gdalwarp is nearest neighbor which does not suit well for DEM


Therefore the conversion must be done in two steps and with a better resampling method.


First step is to create an interim output as GDAL Virtual raster (.VRT) with "average" resampling


gdalwarp -of VRT -r average -tr 0.024999 0.024999 input.asc interim.vrt


Second step is to convert the interim DEM into new ASCII Grid file with gdal_translate


gdal_translate -of AAIGrid interim.vrt output.asc

Note:


The formats which are supported for output can be listed with gdalwarp --formats command. Formats which support direct output are marked with "+" character. However, all of them will not really work (NTv2 Datum Grid Shift file for example).


On Windows


gdalwarp --formats|find "+"
FITS -raster- (rw+): Flexible Image Transport System
HDF4Image -raster- (rw+): HDF4 Dataset

netCDF -raster- (rw+s): Network Common Data Format
VRT -raster- (rw+v): Virtual Raster
GTiff -raster- (rw+vs): GeoTIFF
NITF -raster- (rw+vs): National Imagery Transmission Format
HFA -raster- (rw+v): Erdas Imagine Images (.img)
ELAS -raster- (rw+v): ELAS
MEM -raster- (rw+): In Memory Raster
BMP -raster- (rw+v): MS Windows Device Independent Bitmap
PCIDSK -raster,vector- (rw+v): PCIDSK Database File
ILWIS -raster- (rw+v): ILWIS Raster Map

SGI -raster- (rw+): SGI Image File Format 1.0
Leveller -raster- (rw+): Leveller heightfield
Terragen -raster- (rw+): Terragen heightfield
ISIS2 -raster- (rw+v): USGS Astrogeology ISIS cube (Version 2)
ERS -raster- (rw+v): ERMapper .ers Labelled
RMF -raster- (rw+v): Raster Matrix Format
RST -raster- (rw+v): Idrisi Raster A.1
INGR -raster- (rw+v): Intergraph Raster
GSBG -raster- (rw+v): Golden Software Binary Grid (.grd)
GS7BG -raster- (rw+v): Golden Software 7 Binary Grid (.grd)

PNM -raster- (rw+v): Portable Pixmap Format (netpbm)
ENVI -raster- (rw+v): ENVI .hdr Labelled
EHdr -raster- (rw+v): ESRI .hdr Labelled
PAux -raster- (rw+): PCI .aux Labelled
MFF -raster- (rw+): Vexcel MFF Raster
MFF2 -raster- (rw+): Vexcel MFF2 (HKV) Raster
BT -raster- (rw+v): VTP .bt (Binary Terrain) 1.3 Format
LAN -raster- (rw+v): Erdas .LAN/.GIS
IDA -raster- (rw+v): Image Data and Analysis
GTX -raster- (rw+v): NOAA Vertical Datum .GTX

NTv2 -raster- (rw+vs): NTv2 Datum Grid Shift
CTable2 -raster- (rw+v): CTable2 Datum Grid Shift
KRO -raster- (rw+v): KOLOR Raw
ADRG -raster- (rw+vs): ARC Digitized Raster Graphics
SAGA -raster- (rw+v): SAGA GIS Binary Grid (.sdat)
PDF -raster,vector- (rw+vs): Geospatial PDF

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...