[gdal-dev] python gdal gdal.ReprojectImage produces no data

Frank Warmerdam warmerdam at pobox.com
Wed Jul 29 10:29:28 EDT 2009


Jachym Cepicky wrote:
> Hi
> 
> I would like to write "custom" version of the gdalwarp tool in Python
> using gdal.ReprojectImage() function, but the only result I get, is just
> a empty "black" image.
> 
> The code would look like this:
> 
> # -------     python code start  -------
> from osgeo import gdal
> 
> # let's have georeferenced geotiff
> inds = gdal.Open("filename.tif")
> 
> # it *is* georeferenced
> inds.GetProjection()
> # 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.2572235629972,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]'
> 
> # create the driver
> driver = gdal.GetDriverByName("GTiff")
> 
> # create new output file
> outds = driver.Create("outfile.tif",inds.RasterXSize, inds.RasterYSize)
> 
> # do the transformation - actually no transformation at all
> gdal.ReprojectImage(inds, outds, inds.GetProjection(), inds.GetProjection())
....
> That was all :-( Projection and coordinates can be set using
> dsout.SetProjection and dsout.SetGeoTransform - that would not be a
> problem. The problem are the data, which were not copied.
> 
> I'm I missing something? Could this be a problem of my GDAL
> installation?


Jachym,

The problem is that your output file does not have a geotransform set,
so ReprojectImage() does not realize the output file overlaps the
area available from the input file.  You need to set the geotransform
before calling ReprojectImage().  Setting the coordinate system is not
critical since ReprojectImage() allows you to pass in an output coordinate
system.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list