Tuesday, 8 October 2019

gdal - How do I create blank geotiff with same spatial properties as existing geotiff?


How do I use gdal to create a blank geotiff with the same spatial properties (size, resolution, extent, projection) as an existing geotiff?


(The reason that I want to do this is that I'm using gdal_rasterize to rasterize a polygon shapefile to overlay with existing geotiffs, and I think it will be simpler to burn the values into a matching layer rather than specifying all the properties in the rasterize command.)



Answer



One line solution: modify the last gdal_calc.py example on http://www.gdal.org/gdal_calc.html:


gdal_calc -A input.tif --outfile=empty.tif --calc "A*0" --NoDataValue=0

Check the result:


gdalinfo empty.tif -hist
Driver: GTiff/GeoTIFF

Files: empty.tif
Size is 10, 10
Coordinate System is `'
Origin = (950.000000000000000,1050.000000000000000)
Pixel Size = (100.000000000000000,-100.000000000000000)
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( 950.000, 1050.000)
Lower Left ( 950.000, 50.000)

Upper Right ( 1950.000, 1050.000)
Lower Right ( 1950.000, 50.000)
Center ( 1450.000, 550.000)
Band 1 Block=10x10 Type=Byte, ColorInterp=Gray
0...10...20...30...40...50...60...70...80...90...100 - done.
256 buckets from -0.5 to 255.5:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
NoData Value=0

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...