<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>[Qgis-user] Georeferencer 3.1.9 bug (?) and work-around</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Hi there,<BR>
<BR>
> Date: Wed, 8 Jun 2011 18:04:04 -0400<BR>
> From: O <mondifero@gmail.com><BR>
> Subject: [Qgis-user] Georeferencer 3.1.9 bug (?) and work-around<BR>
> To: qgis-user <qgis-user@lists.osgeo.org><BR>
> Message-ID: <BANLkTini-WMi3_g=KaxbgOQDX9naqHPUPg@mail.gmail.com><BR>
> Content-Type: text/plain; charset="iso-8859-1"<BR>
><BR>
> Dear QGIS users,<BR>
><BR>
> Summary: I'm running the Georeferencer plugin 3.1.9 with QGIS 1.6.0 and it<BR>
> doesn't work correctly -- the raster is distorted and plotted in the wrong<BR>
> location. However, I found a work-around that fools the plugin into giving<BR>
> correct results, and appears to point out a serious bug in the plugin. (Or,<BR>
> I'm<BR>
> doing something wrong -- please let me know.)<BR>
><BR>
> (And please tell me if I've posted this in the wrong place.)<BR>
><BR>
> Suppose I have an image called "input.tif" that has some geospatial metadata<BR>
> with a CRS and image bounds. For the following discussion, here are the<BR>
> relevant lines that result from running "gdalinfo input.tif":<BR>
><BR>
> Size is 1101, 1091<BR>
> ...<BR>
> Upper Left ( 4578.469, -13361.035) ( 5d26'57.36"W, 2d10'18.28"S)<BR>
> Lower Left ( 4578.469, -13652.219) ( 5d26'57.36"W, 2d10'35.98"S)<BR>
> Upper Right ( 4872.322, -13361.035) ( 5d26'39.49"W, 2d10'18.28"S)<BR>
> Lower Right ( 4872.322, -13652.219) ( 5d26'39.49"W, 2d10'35.98"S)<BR>
> Center ( 4725.395, -13506.627) ( 5d26'48.43"W, 2d10'27.13"S)<BR>
><BR>
> Now suppose I open the Georeferencer and open this image, and define a<BR>
> transformation (say, "polynomial 1") with three ground control points<BR>
> (GCPs).<BR>
> When I tell it to "start georeferencing" and to load the result into my QGIS<BR>
> project, the image is hugely distorted and located in the wrong place. I<BR>
> found<BR>
> a BIG CLUE about what's happening when I asked it to "generate GDAL script".<BR>
> The result was:<BR>
><BR>
> gdal_translate -of GTiff -gcp 4690.78 13510.5 4434.32 -13412.7 \<BR>
> -gcp 4721.32 13469.4 4462.09 -13371.6 \<BR>
> -gcp 4753.5 13539.4 4497.52 -13458.7 \<BR>
> -gcp 4692 13536.2 4430.49 -13445.3 \<BR>
> "/path/input.tif" "/tmp/input.tif"<BR>
><BR>
> gdalwarp -r cubic -order 1 -co COMPRESS=NONE "/tmp/input.tif" \<BR>
> "/path/output.tif"<BR>
><BR>
> But if we look at the man pages for gdal_translate, the format for input of<BR>
> GCPs<BR>
> is:<BR>
><BR>
> -gcp pixel line easting northing elevation<BR>
><BR>
> The first argument to "-gcp" should be the x coordinate in *image* space,<BR>
> not in<BR>
> *coordinate* space. It should be the column number of the pixel in question<BR>
> (I<BR>
> don't know if it can be a floating point; hopefully it can). The second<BR>
> argument to "-gcp" has to be the *row* number of the pixel in the image<BR>
> being<BR>
> georeferenced. The "easting" and "northing" are indeed the x and y<BR>
> coordinates<BR>
> in the target coordinate system. But notice that in the gdal_translate<BR>
> command<BR>
> that the Georeferencer generated, the first two arguments are positions in<BR>
> coordinate space, not image space!<BR>
><BR>
> So, here's the work-around. We saw above that the size of the image is 1101<BR>
> x<BR>
> 1091. All we have to do is change the bounds of the input image so that the<BR>
> image's geographic coordinates match the image space coordinates. We can do<BR>
> that easily with gdal_translate, being careful to account for QGIS using a<BR>
> positive-up y-axis. Here's the command for the current case:<BR>
><BR>
> gdal_translate -of GTiff -a_ullr 0 0 1100 -1090 input.tif input_fixed.tif<BR>
><BR>
> Now, when we open the new input image (input_fixed.tif) into the<BR>
> Georeferencer<BR>
> and select GCPs, etc, it actually works!<BR>
><BR>
> M<BR>
<BR>
>From my experience I think you're right that there is a "major bug" with the georeferencer.  I too was getting extremely distorted (beyond recognition) output rasters; in my case using a linear transformation.  I thought I only had this problem when using more than two control points - but it's possible I'm remembering that incorrectly, and I actually only got a sensible result by choosing to create world files instead of new rasters.<BR>
<BR>
Alister</FONT>
</P>

</BODY>
</HTML>