Opening the File
Before opening a GDAL supported raster datastore it is necessary to register drivers. There is a driver for each supported format. Normally this is accomplished with the GDALAllRegister() function which attempts to register all known drivers, including those auto-loaded from .so files using GDALDriverManager::AutoLoadDrivers(). If for some applications it is necessary to limit the set of drivers it may be helpful to review the code from gdalallregister.cpp. Python automatically calls GDALAllRegister() when the gdal module is imported.
Once the drivers are registered, the application should call the free standing GDALOpen() function to open a dataset, passing the name of the dataset and the access desired (GA_ReadOnly or GA_Update).
In C++:
int main()
{
if( poDataset == NULL )
{
...;
}
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:336
Various convenience functions for CPL.
@ GA_ReadOnly
Definition: gdal.h:114
GDALDatasetH GDALOpen(const char *pszFilename, GDALAccess eAccess) CPL_WARN_UNUSED_RESULT
Open a raster file as a GDALDataset.
Definition: gdaldataset.cpp:3032
void GDALAllRegister(void)
Register all known configured GDAL drivers.
Definition: gdalallregister.cpp:62
In C:
int main()
{
if( hDataset == NULL )
{
...;
}
Public (C callable) GDAL entry points.
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:255
In Python:
from osgeo import gdal
dataset = gdal.Open(filename, gdal.GA_ReadOnly)
if not dataset:
...
Note that if GDALOpen() returns NULL it means the open failed, and that an error messages will already have been emitted via CPLError(). If you want to control how errors are reported to the user review the CPLError() documentation. Generally speaking all of GDAL uses CPLError() for error reporting. Also, note that pszFilename need not actually be the name of a physical file (though it usually is). It's interpretation is driver dependent, and it might be an URL, a filename with additional parameters added at the end controlling the open or almost anything. Please try not to limit GDAL file selection dialogs to only selecting physical files.
Getting Dataset Information
As described in the GDAL Data Model, a GDALDataset contains a list of raster bands, all pertaining to the same area, and having the same resolution. It also has metadata, a coordinate system, a georeferencing transform, size of raster and various other information.
In the particular, but common, case of a "north up" image without any rotation or shearing, the georeferencing transform takes the following form :
adfGeoTransform[0]
adfGeoTransform[1]
adfGeoTransform[2]
adfGeoTransform[3]
adfGeoTransform[4]
adfGeoTransform[5]
In the general case, this is an affine transform.
If we wanted to print some general information about the dataset we might do the following:
In C++:
double adfGeoTransform[6];
printf( "Driver: %s/%s\n",
printf( "Size is %dx%dx%d\n",
{
printf( "Origin = (%.6f,%.6f)\n",
adfGeoTransform[0], adfGeoTransform[3] );
printf( "Pixel Size = (%.6f,%.6f)\n",
adfGeoTransform[1], adfGeoTransform[5] );
}
virtual CPLErr GetGeoTransform(double *padfTransform)
Fetch the affine transformation coefficients.
Definition: gdaldataset.cpp:1158
int GetRasterCount()
Fetch the number of raster bands on this dataset.
Definition: gdaldataset.cpp:804
virtual GDALDriver * GetDriver(void)
Fetch the driver to which this dataset relates.
Definition: gdaldataset.cpp:1296
int GetRasterXSize()
Fetch raster width in pixels.
Definition: gdaldataset.cpp:683
const char * GetProjectionRef(void) const
Fetch the projection definition string for this dataset.
Definition: gdaldataset.cpp:849
int GetRasterYSize()
Fetch raster height in pixels.
Definition: gdaldataset.cpp:717
virtual const char * GetMetadataItem(const char *pszName, const char *pszDomain="")
Fetch single metadata item.
Definition: gdalmajorobject.cpp:344
virtual const char * GetDescription() const
Fetch object description.
Definition: gdalmajorobject.cpp:79
#define GDAL_DMD_LONGNAME
Long name of the driver.
Definition: gdal.h:280
In C:
double adfGeoTransform[6];
printf( "Driver: %s/%s\n",
printf( "Size is %dx%dx%d\n",
{
printf( "Origin = (%.6f,%.6f)\n",
adfGeoTransform[0], adfGeoTransform[3] );
printf( "Pixel Size = (%.6f,%.6f)\n",
adfGeoTransform[1], adfGeoTransform[5] );
}
const char * GDALGetDriverShortName(GDALDriverH)
Return the short name of a driver.
Definition: gdaldriver.cpp:1435
GDALDriverH GDALGetDatasetDriver(GDALDatasetH)
Fetch the driver to which this dataset relates.
Definition: gdaldataset.cpp:1308
int GDALGetRasterCount(GDALDatasetH)
Fetch the number of raster bands on this dataset.
Definition: gdaldataset.cpp:816
const char * GDALGetDriverLongName(GDALDriverH)
Return the long name of a driver.
Definition: gdaldriver.cpp:1457
int GDALGetRasterXSize(GDALDatasetH)
Fetch raster width in pixels.
Definition: gdaldataset.cpp:695
const char * GDALGetProjectionRef(GDALDatasetH)
Fetch the projection definition string for this dataset.
Definition: gdaldataset.cpp:971
CPLErr GDALGetGeoTransform(GDALDatasetH, double *)
Fetch the affine transformation coefficients.
Definition: gdaldataset.cpp:1184
void * GDALDriverH
Opaque type used for the C bindings of the C++ GDALDriver class.
Definition: gdal.h:261
int GDALGetRasterYSize(GDALDatasetH)
Fetch raster height in pixels.
Definition: gdaldataset.cpp:729
In Python:
print("Driver: {}/{}".format(dataset.GetDriver().ShortName,
dataset.GetDriver().LongName))
print("Size is {} x {} x {}".format(dataset.RasterXSize,
dataset.RasterYSize,
dataset.RasterCount))
print("Projection is {}".format(dataset.GetProjection()))
geotransform = dataset.GetGeoTransform()
if geotransform:
print("Origin = ({}, {})".format(geotransform[0], geotransform[3]))
print("Pixel Size = ({}, {})".format(geotransform[1], geotransform[5]))
Fetching a Raster Band
At this time access to raster data via GDAL is done one band at a time. Also, there is metadata, block sizes, color tables, and various other information available on a band by band basis. The following codes fetches a GDALRasterBand object from the dataset (numbered 1 through GetRasterCount()) and displays a little information about it.
In C++:
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
printf( "Block=%dx%d Type=%s, ColorInterp=%s\n",
nBlockXSize, nBlockYSize,
if( ! (bGotMin && bGotMax) )
printf( "Min=%.3fd, Max=%.3f\n", adfMinMax[0], adfMinMax[1] );
printf( "Band has a color table with %d entries.\n",
int GetColorEntryCount() const
Get number of color entries in table.
Definition: gdalcolortable.cpp:301
GDALRasterBand * GetRasterBand(int)
Fetch a band object for a dataset.
Definition: gdaldataset.cpp:756
A single raster band (or channel).
Definition: gdal_priv.h:1069
virtual int GetOverviewCount()
Return the number of overview layers available.
Definition: gdalrasterband.cpp:2184
virtual GDALColorTable * GetColorTable()
Fetch the color table associated with band.
Definition: gdalrasterband.cpp:2050
virtual double GetMaximum(int *pbSuccess=nullptr)
Fetch the maximum value for this band.
Definition: gdalrasterband.cpp:1778
virtual double GetMinimum(int *pbSuccess=nullptr)
Fetch the minimum value for this band.
Definition: gdalrasterband.cpp:1871
virtual GDALColorInterp GetColorInterpretation()
How should this band be interpreted as color?
Definition: gdalrasterband.cpp:1958
GDALDataType GetRasterDataType(void)
Fetch the pixel data type for this band.
Definition: gdalrasterband.cpp:822
void GetBlockSize(int *, int *)
Fetch the "natural" block size of this band.
Definition: gdalrasterband.cpp:873
void GDALComputeRasterMinMax(GDALRasterBandH hBand, int bApproxOK, double adfMinMax[2])
Compute the min/max values for a band.
Definition: gdalrasterband.cpp:5700
const char * GDALGetColorInterpretationName(GDALColorInterp)
Get name of color interpretation.
Definition: gdal_misc.cpp:904
const char * GDALGetDataTypeName(GDALDataType)
Get name of data type.
Definition: gdal_misc.cpp:565
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:258
In C:
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
printf( "Block=%dx%d Type=%s, ColorInterp=%s\n",
nBlockXSize, nBlockYSize,
if( ! (bGotMin && bGotMax) )
printf( "Min=%.3fd, Max=%.3f\n", adfMinMax[0], adfMinMax[1] );
printf( "Band has a color table with %d entries.\n",
int GDALGetOverviewCount(GDALRasterBandH)
Return the number of overview layers available.
Definition: gdalrasterband.cpp:2203
void GDALGetBlockSize(GDALRasterBandH, int *pnXSize, int *pnYSize)
Fetch the "natural" block size of this band.
Definition: gdalrasterband.cpp:905
int GDALGetColorEntryCount(GDALColorTableH)
Get number of color entries in table.
Definition: gdalcolortable.cpp:317
GDALRasterBandH GDALGetRasterBand(GDALDatasetH, int)
Fetch a band object for a dataset.
Definition: gdaldataset.cpp:783
GDALDataType GDALGetRasterDataType(GDALRasterBandH)
Fetch the pixel data type for this band.
Definition: gdalrasterband.cpp:838
double GDALGetRasterMinimum(GDALRasterBandH, int *pbSuccess)
Fetch the minimum value for this band.
Definition: gdalrasterband.cpp:1933
double GDALGetRasterMaximum(GDALRasterBandH, int *pbSuccess)
Fetch the maximum value for this band.
Definition: gdalrasterband.cpp:1844
GDALColorTableH GDALGetRasterColorTable(GDALRasterBandH)
Fetch the color table associated with band.
Definition: gdalrasterband.cpp:2066
GDALColorInterp GDALGetRasterColorInterpretation(GDALRasterBandH)
How should this band be interpreted as color?
Definition: gdalrasterband.cpp:1975
In Python (note several bindings are missing):
band = dataset.GetRasterBand(1)
print("Band Type={}".format(gdal.GetDataTypeName(band.DataType)))
min = band.GetMinimum()
max = band.GetMaximum()
if not min or not max:
(min,max) = band.ComputeRasterMinMax(True)
print("Min={:.3f}, Max={:.3f}".format(min,max))
if band.GetOverviewCount() > 0:
print("Band has {} overviews".format(band.GetOverviewCount()))
if band.GetRasterColorTable():
print("Band has a color table with {} entries".format(band.GetRasterColorTable().GetCount()))
Reading Raster Data
There are a few ways to read raster data, but the most common is via the GDALRasterBand::RasterIO() method. This method will automatically take care of data type conversion, up/down sampling and windowing. The following code will read the first scanline of data into a similarly sized buffer, converting it to floating point as part of the operation.
In C++:
float *pafScanline;
pafScanline = (
float *)
CPLMalloc(
sizeof(
float)*nXSize);
0, 0 );
CPLErr RasterIO(GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, GSpacing, GSpacing, GDALRasterIOExtraArg *psExtraArg) CPL_WARN_UNUSED_RESULT
Read/write a region of image data for this band.
Definition: gdalrasterband.cpp:256
int GetXSize()
Fetch XSize of raster.
Definition: gdalrasterband.cpp:2717
void * CPLMalloc(size_t) CPL_WARN_UNUSED_RESULT
Safe version of malloc().
Definition: cpl_conv.cpp:168
@ GDT_Float32
Definition: gdal.h:69
@ GF_Read
Definition: gdal.h:120
The pafScanline buffer should be freed with CPLFree() when it is no longer used.
In C:
float *pafScanline;
pafScanline = (
float *)
CPLMalloc(
sizeof(
float)*nXSize);
0, 0 );
int GDALGetRasterBandXSize(GDALRasterBandH)
Fetch XSize of raster.
Definition: gdalrasterband.cpp:2733
CPLErr GDALRasterIO(GDALRasterBandH hRBand, GDALRWFlag eRWFlag, int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize, void *pBuffer, int nBXSize, int nBYSize, GDALDataType eBDataType, int nPixelSpace, int nLineSpace) CPL_WARN_UNUSED_RESULT
Read/write a region of image data for this band.
Definition: gdalrasterband.cpp:394
The pafScanline buffer should be freed with CPLFree() when it is no longer used.
In Python:
scanline = band.ReadRaster(xoff=0, yoff=0,
xsize=band.XSize, ysize=1,
buf_xsize=band.XSize, buf_ysize=1,
buf_type=gdal.GDT_Float32)
Note that the returned scanline is of type string, and contains xsize*4 bytes of raw binary floating point data. This can be converted to Python values using the struct module from the standard library:
import struct
tuple_of_floats = struct.unpack('f' * b2.XSize, scanline)
The RasterIO call takes the following arguments.
int nXOff, int nYOff, int nXSize, int nYSize,
void * pData, int nBufXSize, int nBufYSize,
int nPixelSpace,
int nLineSpace )
CPLErr
Error category.
Definition: cpl_error.h:53
GDALDataType
Definition: gdal.h:60
GDALRWFlag
Definition: gdal.h:119
Note that the same RasterIO() call is used to read, or write based on the setting of eRWFlag (either GF_Read or GF_Write). The nXOff, nYOff, nXSize, nYSize argument describe the window of raster data on disk to read (or write). It doesn't have to fall on tile boundaries though access may be more efficient if it does.
The pData is the memory buffer the data is read into, or written from. It's real type must be whatever is passed as eBufType, such as GDT_Float32, or GDT_Byte. The RasterIO() call will take care of converting between the buffer's data type and the data type of the band. Note that when converting floating point data to integer RasterIO() rounds down, and when converting source values outside the legal range of the output the nearest legal value is used. This implies, for instance, that 16bit data read into a GDT_Byte buffer will map all values greater than 255 to 255, the data is not scaled!
The nBufXSize and nBufYSize values describe the size of the buffer. When loading data at full resolution this would be the same as the window size. However, to load a reduced resolution overview this could be set to smaller than the window on disk. In this case the RasterIO() will utilize overviews to do the IO more efficiently if the overviews are suitable.
The nPixelSpace, and nLineSpace are normally zero indicating that default values should be used. However, they can be used to control access to the memory data buffer, allowing reading into a buffer containing other pixel interleaved data for instance.
Closing the Dataset
Please keep in mind that GDALRasterBand objects are owned by their dataset, and they should never be destroyed with the C++ delete operator. GDALDataset's can be closed by calling GDALClose() (it is NOT recommended to use the delete operator on a GDALDataset for Windows users because of known issues when allocating and freeing memory across module boundaries. See the relevant topic on the FAQ). Calling GDALClose will result in proper cleanup, and flushing of any pending writes. Forgetting to call GDALClose on a dataset opened in update mode in a popular format like GTiff will likely result in being unable to open it afterwards.
Techniques for Creating Files
New files in GDAL supported formats may be created if the format driver supports creation. There are two general techniques for creating files, using CreateCopy() and Create(). The CreateCopy method involves calling the CreateCopy() method on the format driver, and passing in a source dataset that should be copied. The Create method involves calling the Create() method on the driver, and then explicitly writing all the metadata, and raster data with separate calls. All drivers that support creating new files support the CreateCopy() method, but only a few support the Create() method.
To determine if a particular format supports Create or CreateCopy it is possible to check the DCAP_CREATE and DCAP_CREATECOPY metadata on the format driver object. Ensure that GDALAllRegister() has been called before calling GetDriverByName(). In this example we fetch a driver, and determine whether it supports Create() and/or CreateCopy().
In C++:
...
const char *pszFormat = "GTiff";
char **papszMetadata;
if( poDriver == NULL )
exit( 1 );
printf( "Driver %s supports Create() method.\n", pszFormat );
printf( "Driver %s supports CreateCopy() method.\n", pszFormat );
GDALDriver * GetDriverByName(const char *)
Fetch a driver based on the short name.
Definition: gdaldrivermanager.cpp:590
Format specific driver.
Definition: gdal_priv.h:1424
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition: gdalmajorobject.cpp:249
Various convenience functions for working with strings and string lists.
int CSLFetchBoolean(CSLConstList papszStrList, const char *pszKey, int bDefault)
DEPRECATED.
Definition: cpl_string.cpp:1635
#define GDAL_DCAP_CREATECOPY
Capability set by a driver that implements the CreateCopy() API.
Definition: gdal.h:347
#define GDAL_DCAP_CREATE
Capability set by a driver that implements the Create() API.
Definition: gdal.h:337
GDALDriverManager * GetGDALDriverManager(void)
Fetch the global GDAL driver manager.
Definition: gdaldrivermanager.cpp:97
In C:
...
const char *pszFormat = "GTiff";
char **papszMetadata;
if( hDriver == NULL )
exit( 1 );
printf( "Driver %s supports Create() method.\n", pszFormat );
printf( "Driver %s supports CreateCopy() method.\n", pszFormat );
char ** GDALGetMetadata(GDALMajorObjectH, const char *)
Fetch metadata.
Definition: gdalmajorobject.cpp:266
GDALDriverH GDALGetDriverByName(const char *)
Fetch a driver based on the short name.
Definition: gdaldrivermanager.cpp:612
In Python:
fileformat = "GTiff"
driver = gdal.GetDriverByName(fileformat)
metadata = driver.GetMetadata()
if metadata.get(gdal.DCAP_CREATE) == "YES":
print("Driver {} supports Create() method.".format(fileformat))
if metadata.get(gdal.DCAP_CREATE) == "YES":
print("Driver {} supports CreateCopy() method.".format(fileformat))
Note that a number of drivers are read-only and won't support Create() or CreateCopy().
Using CreateCopy()
The GDALDriver::CreateCopy() method can be used fairly simply as most information is collected from the source dataset. However, it includes options for passing format specific creation options, and for reporting progress to the user as a long dataset copy takes place. A simple copy from the a file named pszSrcFilename, to a new file named pszDstFilename using default options on a format whose driver was previously fetched might look like this:
In C++:
poDstDS = poDriver->
CreateCopy( pszDstFilename, poSrcDS, FALSE,
NULL, NULL, NULL );
if( poDstDS != NULL )
GDALDataset * CreateCopy(const char *, GDALDataset *, int, char **, GDALProgressFunc pfnProgress, void *pProgressData) CPL_WARN_UNUSED_RESULT
Create a copy of a dataset.
Definition: gdaldriver.cpp:806
void GDALClose(GDALDatasetH)
Close GDAL dataset.
Definition: gdaldataset.cpp:3588
In C:
NULL, NULL, NULL );
if( hDstDS != NULL )
GDALDatasetH GDALCreateCopy(GDALDriverH, const char *, GDALDatasetH, int, CSLConstList, GDALProgressFunc, void *) CPL_WARN_UNUSED_RESULT
Create a copy of a dataset.
Definition: gdaldriver.cpp:972
In Python:
src_ds = gdal.Open(src_filename)
dst_ds = driver.CreateCopy(dst_filename, src_ds, strict=0)
# Once we're done, close properly the dataset
dst_ds = None
src_ds = None
Note that the CreateCopy() method returns a writable dataset, and that it must be closed properly to complete writing and flushing the dataset to disk. In the Python case this occurs automatically when "dst_ds" goes out of scope. The FALSE (or 0) value used for the bStrict option just after the destination filename in the CreateCopy() call indicates that the CreateCopy() call should proceed without a fatal error even if the destination dataset cannot be created to exactly match the input dataset. This might be because the output format does not support the pixel datatype of the input dataset, or because the destination cannot support writing georeferencing for instance.
A more complex case might involve passing creation options, and using a predefined progress monitor like this:
In C++:
...
char **papszOptions = NULL;
poDstDS = poDriver->
CreateCopy( pszDstFilename, poSrcDS, FALSE,
papszOptions, GDALTermProgress, NULL );
if( poDstDS != NULL )
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Assign value to name in StringList.
Definition: cpl_string.cpp:1877
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:200
In C:
...
char **papszOptions = NULL;
papszOptions, GDALTermProgres, NULL );
if( hDstDS != NULL )
In Python:
src_ds = gdal.Open(src_filename)
dst_ds = driver.CreateCopy(dst_filename, src_ds, strict=0,
options=["TILED=YES", "COMPRESS=PACKBITS"])
# Once we're done, close properly the dataset
dst_ds = None
src_ds = None
Using Create()
For situations in which you are not just exporting an existing file to a new file, it is generally necessary to use the GDALDriver::Create() method (though some interesting options are possible through use of virtual files or in-memory files). The Create() method takes an options list much like CreateCopy(), but the image size, number of bands and band type must be provided explicitly.
In C++:
char **papszOptions = NULL;
papszOptions );
GDALDataset * Create(const char *pszName, int nXSize, int nYSize, int nBands, GDALDataType eType, char **papszOptions) CPL_WARN_UNUSED_RESULT
Create a new dataset with this driver.
Definition: gdaldriver.cpp:162
@ GDT_Byte
Definition: gdal.h:62
In C:
char **papszOptions = NULL;
papszOptions );
GDALDatasetH GDALCreate(GDALDriverH hDriver, const char *, int, int, int, GDALDataType, CSLConstList) CPL_WARN_UNUSED_RESULT
Create a new dataset with this driver.
Definition: gdaldriver.cpp:306
In Python:
dst_ds = driver.Create(dst_filename, xsize=512, ysize=512,
bands=1, eType=gdal.GDT_Byte)
Once the dataset is successfully created, all appropriate metadata and raster data must be written to the file. What this is will vary according to usage, but a simple case with a projection, geotransform and raster data is covered here.
In C++:
double adfGeoTransform[6] = { 444720, 30, 0, 3751320, 0, -30 };
char *pszSRS_WKT = NULL;
GByte abyRaster[512*512];
CPLErr SetProjection(const char *pszProjection)
Set the projection reference string for this dataset.
Definition: gdaldataset.cpp:1001
virtual CPLErr SetGeoTransform(double *padfTransform)
Set the affine transformation coefficients.
Definition: gdaldataset.cpp:1213
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:157
OGRErr SetWellKnownGeogCS(const char *)
Set a GeogCS based on well known name.
Definition: ogrspatialreference.cpp:2953
OGRErr SetUTM(int nZone, int bNorth=TRUE)
Universal Transverse Mercator.
Definition: ogrspatialreference.cpp:6973
OGRErr exportToWkt(char **) const
Convert this SRS into WKT 1 format.
Definition: ogrspatialreference.cpp:1330
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:81
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
@ GF_Write
Definition: gdal.h:121
In C:
double adfGeoTransform[6] = { 444720, 30, 0, 3751320, 0, -30 };
char *pszSRS_WKT = NULL;
GByte abyRaster[512*512];
CPLErr GDALSetProjection(GDALDatasetH, const char *)
Set the projection reference string for this dataset.
Definition: gdaldataset.cpp:1118
CPLErr GDALSetGeoTransform(GDALDatasetH, double *)
Set the affine transformation coefficients.
Definition: gdaldataset.cpp:1234
void * OGRSpatialReferenceH
Opaque type for a spatial reference system.
Definition: ogr_api.h:74
OGRErr OSRSetWellKnownGeogCS(OGRSpatialReferenceH hSRS, const char *pszName)
Set a GeogCS based on well known name.
Definition: ogrspatialreference.cpp:3056
OGRSpatialReferenceH OSRNewSpatialReference(const char *)
Constructor.
Definition: ogrspatialreference.cpp:689
void OSRDestroySpatialReference(OGRSpatialReferenceH)
OGRSpatialReference destructor.
Definition: ogrspatialreference.cpp:773
OGRErr OSRExportToWkt(OGRSpatialReferenceH, char **)
Convert this SRS into WKT 1 format.
Definition: ogrspatialreference.cpp:1541
OGRErr OSRSetUTM(OGRSpatialReferenceH hSRS, int nZone, int bNorth)
Set UTM projection definition.
Definition: ogrspatialreference.cpp:6995
In Python:
from osgeo import osr
import numpy
dst_ds.SetGeoTransform([444720, 30, 0, 3751320, 0, -30])
srs = osr.SpatialReference()
srs.SetUTM(11, 1)
srs.SetWellKnownGeogCS("NAD27")
dst_ds.SetProjection(srs.ExportToWkt())
raster = numpy.zeros((512, 512), dtype=numpy.uint8)
dst_ds.GetRasterBand(1).WriteArray(raster)
# Once we're done, close properly the dataset
dst_ds = None
$Id: gdal_tutorial.dox 2c8e7182770d6dd6a2970e554a0f3b614b6df3db 2017-08-16 11:02:15Z Even Rouault $