Programmatically Creating a GeoTiff Image

There are times when it is necessary to programmatically associate some geo-referencing information with a tiff file to create a geotiff. The example below demonstrates how this can be done using IDL.
The most difficult part of this program is to obtain the correct information to populate the necessary tags and geokeys. It is left to the user how and what information needs to be added but the values used in the following example represent a fairly typical scenario. 

; This is an example program that creates a geotiff file containing
; some of the tag and geokeys available to IDL users. The full list
; can be viewed via the IDL Help. The values used here come from
; an example found on the GeoTIFF Format Specification website:
; Projection: Lambert Conformal Conic
; Central Meridian: 120 degrees West
; Pixel size: 25m
; Datum: NAD27
; Standard Parallels; 41d 20m N and 48d 40m N
; Latitude of origin: 45d N and occurs at coordinates (80, 100)
; False Easting: 200000m
; False Northing; 1500000m
; Although the 'ProjAzimuthAngleGeoKey' is not in the IDL list
; of geokeys it has been added here to demonstrate that it is possible
; to write other accepted geokeys and have a valid geotiff file. This
; geokeys' information is displayed when a 'tiff dump' is done on the
; file.

pro example_write_geotiff

;Create some sample tag and geokey information
  g_tags = { $
    ModelPixelScaleTag: [25, 25, 0d], $
    ModelTiepointTag: [80, 100, 0, 200000, 1500000, 0], $
    GTModelTypeGeoKey: 1, $ ; (ModelTypeProjected)
    GTRasterTypeGeoKey: 1, $ ; (RasterPixelIsArea)
    GeographicTypeGeoKey: 4267, $ ; (GCS_NAD27)
    ProjectedCSTypeGeoKey: 32767, $ ; (user-defined)
    ProjectionGeoKey: 32767, $ ; (user-defined)
    ProjLinearUnitsGeoKey: 9001, $ ; (Linear_Meter)
    ProjCoordTransGeoKey: 8, $ ; (CT_LambertConfConic_2SP)
    ProjStdParallel1GeoKey: 41.333, $
    ProjStdParallel2GeoKey: 48.666, $
    ProjCenterLongGeoKey: 120.0, $
    ProjNatOriginLatGeoKey: 45.0, $
    ProjFalseEastingGeoKey: 200000.0, $
    ProjFalseNorthingGeoKey: 1500000.0, $
    ProjAzimuthAngleGeoKey: 3094 $ ; not in IDL list but is written

;Create an image for the tags and  geokeys and then
;write out the file
data = fix(dist(512))
WRITE_TIFF,'example_geotif.tif',data,/float, geotiff=g_tags

;Do a query on the file and print out the information found in the
;tags and geokeys
test=QUERY_TIFF( 'example_geotif.tif', geotiff=my_tag)
PRINT, my_tag
HELP, my_tag, /struct


Please login or register to post comments.