Ticket #1469 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

AutoCreateWarpedVRT creates incorrect VRT Dataset

Reported by: szekerest Assigned to: warmerdam
Priority: normal Milestone: 1.4.1
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: vrt
Cc: mloskot

Description (Last modified by mloskot)

Currently, for the SWIG bindings, the only option to use the the GDAL warp functionality is to utilize AutoCreateWarpedVRT. To use this feature the following (simplified) C# code sample was created:

gdal.AllRegister();
Dataset ds = gdal.Open( "usapm.jpg", gdalconst.GA_ReadOnly );

SpatialReference t_srs = new SpatialReference("");
t_srs.SetFromUserInput("+proj=longlat +ellps=clrk80 +no_defs");
string t_srs_wkt;
t_srs.ExportToWkt(out t_srs_wkt);
SpatialReference s_srs = new SpatialReference("");
s_srs.SetFromUserInput("+proj=utm +zone=16 +datum=NAD83 +no_defs");
string s_srs_wkt;
s_srs.ExportToWkt(out s_srs_wkt);
Dataset dswarp = gdal.AutoCreateWarpedVRT( ds, s_srs_wkt, t_srs_wkt, gdalconst.GRA_NearestNeighbour, 0.125 );

Driver drv_out = gdal.GetDriverByName("GTiff");

// saving the VRT dataset (optional)
Dataset dsw1 = dswarp.GetDriver().CreateCopy("usapm_bad.vrt", dswarp, 1, null);
// saving the warped image
Dataset dsw = drv_out.CreateCopy("usapm_bad.tif", dswarp, 0, new string[] { "INTERLEAVE=PIXEL", null });

Currently this code does not work as expected and the resulting image is not warped.

So as to inspect this problem the following equivalent commands were executed using the same dataset:

gdalwarp -s_srs "+proj=utm +zone=16 +datum=NAD83 +no_defs" \
   -t_srs "+proj=longlat +ellps=clrk80 +no_defs" -of VRT \
   usapm.jpg usapm_good.vrt
gdalwarp -co "INTERLEAVE=PIXEL" usapm_good.vrt usapm_good.tif

A suggested patch was also created for fixing this problem.

The following files will be attached to this bug:

usapm_good.vrt
usapm_bad.vrt
usapm.zip (contains usapm.jpg, usapm.jgw)
vrtwarped.cpp.patch

Attachments

usapm_good.vrt (3.1 kB) - added by szekerest on 02/01/07 06:02:54.
usapm_good.vrt
usapm_bad.vrt (1.9 kB) - added by szekerest on 02/01/07 06:05:03.
usapm_bad.vrt
vrtwarped.cpp.patch (2.9 kB) - added by szekerest on 02/01/07 06:07:52.
vrtwarped.cpp.patch

Change History

02/01/07 06:02:54 changed by szekerest

  • attachment usapm_good.vrt added.

usapm_good.vrt

02/01/07 06:05:03 changed by szekerest

  • attachment usapm_bad.vrt added.

usapm_bad.vrt

02/01/07 06:07:52 changed by szekerest

  • attachment vrtwarped.cpp.patch added.

vrtwarped.cpp.patch

02/01/07 06:14:16 changed by szekerest

The data file couldn't be attached due to it's size, and can be downloaded from here:

http://members.chello.hu/szekeres.tamas1/usapm.zip

04/08/07 10:07:58 changed by mloskot

  • description changed.

04/08/07 10:10:18 changed by mloskot

  • keywords set to vrt.
  • cc set to mloskot.

04/08/07 10:21:06 changed by warmerdam

  • priority changed from highest to normal.
  • severity changed from critical to normal.
  • milestone set to 1.4.1.

I will review this before the 1.4.1 release to see if it belongs there, though I am hesitant at this late date.

04/08/07 23:35:00 changed by warmerdam

  • status changed from new to closed.
  • resolution set to fixed.

I don't really understand the bulk of the patch. I found the following change (passing pszDstWKT into GDALCreateGenImgProjTransformer()) was sufficient to fix the problem.

warmerda@amd64[120]% svn diff --diff-cmd diff -x -c
Index: vrtwarped.cpp
===================================================================
*** vrtwarped.cpp       (revision 11196)
--- vrtwarped.cpp       (working copy)
***************
*** 120,126 ****
  /* -------------------------------------------------------------------- */
      psWO->pfnTransformer = GDALGenImgProjTransform;
      psWO->pTransformerArg = 
!         GDALCreateGenImgProjTransformer( psWO->hSrcDS, pszSrcWKT, NULL, NULL,
                                           TRUE, 1.0, 0 );
  
  /* -------------------------------------------------------------------- */
--- 120,127 ----
  /* -------------------------------------------------------------------- */
      psWO->pfnTransformer = GDALGenImgProjTransform;
      psWO->pTransformerArg = 
!         GDALCreateGenImgProjTransformer( psWO->hSrcDS, pszSrcWKT, 
!                                          NULL, pszDstWKT,
                                           TRUE, 1.0, 0 );
  
  /* ------------------------------------------------------------------

This change has been applied in trunk, and 1.4 branch in time for the 1.4.1 release.