2017年8月11日 星期五

Multiple grd files to one raster (tif) file

Problem description

The *.grd files are obtained from different sources, and of time only contain a rectangle area which is smaller than the area of interest.
Moreover, the *.grd format is not commonly used under QGIS/ArcGIS environment.

To deal with

Steps
  1. Convert grd(s) to tif(s), set projection - use gdalwarp
  2. Merge tif(s) - use arcpy or arcgis toolbox "Mosaic To New Raster (Data Management)"
  3. Set nodata value on new tif - use gdalwarp
  for %%i in (*.grd) do ( 
  gdalwarp -overwrite -s_srs EPSG:3826 -t_srs EPSG:3826 
  -tr 1 -1 -ot float32 %%i ../bsn1010tif2/%%~ni.tif )  
  
  arcpy.MosaicToNewRaster_management(
  input_rasters= "94194055dem.tif; 94191009dem.tif; 94191025dem.tif",
  output_location="E:/E_DATAEXP/D20170308020100500_PP3/_TEST_merge/bsn1010tif2",
  raster_dataset_name_with_extension="merge.tif",
  coordinate_system_for_the_raster="#",
  pixel_type="32_BIT_FLOAT",
  cellsize="#",
  number_of_bands="1",
  mosaic_method="LAST",
  mosaic_colormap_mode="FIRST")
  
  gdalwarp -overwrite -s_srs EPSG:3826 -t_srs EPSG:3826 -tr 1 1 -ot float32
  -srcnodata XXX -dstnodata -9999 E:/E_DATAEXP/D20170308020100500_PP3/_TEST_merge/bsn1010tif/bsn1010arc.tif