Hello,
I am trying to create a raster file with the GeoTiff driver, origin
[0,0] and pixel size [1,-1]. To do so I used the GDALDriver::Create(...)
method with {0,1,0,0,0,-1} as geotransform. But the created output file
has no "Pixel Size" or "Origin" metadata fields, and when I run gdalinfo
the corner coordinates are flipped along the y axis:
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 512.0)
Upper Right ( 512.0, 0.0)
Lower Right ( 512.0, 512.0)
Center ( 256.0, 256.0)
instead of the expected:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, -512.0)
Upper Right ( 512.0, 0.0)
Lower Right ( 512.0, -512.0)
Center ( 256.0, -256.0)
If I use another origin, another pixel size or another driver (I tested
with the ENVI driver), the output has the "Pixel Size" and "Origin"
fields, and the coordinates are not flipped.
Also, if I create the geoTiff file with GDALDriver::CreateCopy(...) on
the dataset on which I used Create(...), the output has the correct fields.
Is it a bug ? or am I doing something wrong here ?
Attached is a c++ main that reproduce the problem:
# It takes as input two filenames, the driver name, the origin and the
spacing.
# It creates a raster using the input driver, the first filename and the
method |GDALDriver::Create(...)|.
# It creates another raster using the second filename. This raster created
by copying the first dataset using |GDALDriver::CreateDataset(...)|.
config: Ubuntu 16.04, GDAL 2.2.1
sincerely,
Cédric Traizet
#include <iostream>
/* GDAL Libraries */
#include "gdal.h"
#include "gdaljp2metadata.h"
#include "gdal_priv.h"
#include "gdal_alg.h"
#include "cpl_conv.h" // for CPLMalloc()
#include <ogr_spatialref.h>
int main(int argc, char * argv[])
{
if (argc != 8)
{
std::cerr << "Usage: " << argv[0] << " <output_filename (using Create())> <output_filename2 (using CreateCopy())> <driver name> <origin X> <origin Y> <size X> < size Y>"
<< std::endl;
return 0;
}
const char * outputFilename = argv[1];
const char * outputFilename2 = argv[2];
const char * pszFormat = argv[3];
double adfGeoTransform[6] = { std::stod(argv[4]), std::stod(argv[6]), 0, std::stod(argv[5]), 0, std::stod(argv[7]) };
GDALAllRegister();
GDALDriver *poDriver;
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
char **papszOptions = NULL;
GDALDataset *poDstDS;
poDstDS = poDriver->Create( outputFilename, 512, 512, 1, GDT_Byte,
papszOptions );
GDALRasterBand *poBand;
GByte abyRaster[512*512];
poDstDS->SetGeoTransform( adfGeoTransform );
OGRSpatialReference oSRS;
char *pszSRS_WKT = NULL;
oSRS.SetUTM( 11, TRUE );
oSRS.SetWellKnownGeogCS( "NAD27" );
oSRS.exportToWkt( &pszSRS_WKT );
poDstDS->SetProjection( pszSRS_WKT );
CPLFree( pszSRS_WKT );
poBand = poDstDS->GetRasterBand(1);
poBand->RasterIO( GF_Write, 0, 0, 512, 512,
abyRaster, 512, 512, GDT_Byte, 0, 0 );
/*Copied dataset*/
GDALDataset *poDstDS2;
poDstDS = poDriver->CreateCopy( outputFilename2, poDstDS, FALSE,
NULL, NULL, NULL );
/* Once we're done, close properly the dataset */
GDALClose( (GDALDatasetH) poDstDS );
GDALClose( (GDALDatasetH) poDstDS2 );
}
_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev