% vim: set textwidth=78 autoindent:

\subsection{Georeferencer Plugin}

% when the revision of a section has been finalized, 
% comment out the following line:
%\updatedisclaimer

The \toolbtntwo{georeferencer}{Georeferencer} allows to generate world files for rasters.
Therefore you select points on the raster, add their coordinates, and the plugin will compute the world file parameters.
The more coordinates you provide the better the result will be.

As an example we will generate a world file for a topo sheet of South Dakota from SDGS.
It can later be visualized together with in the data of the GRASS spearfish60 location.
You can download the topo sheet here: \url{http://grass.osgeo.org/sampledata/spearfish\_toposheet.tar.gz}

As a first step we download the file and untar it.

\begin{verbatim}
wget http://grass.osgeo.org/sampledata/spearfish_toposheet.tar.gz
tar xvzf spearfish_toposheet.tar.gz
cd spearfish_toposheet
\end{verbatim}

The next step is to start QGIS, load the georeferencer plugin and select the file \filename{spearfish\_topo24.tif}.

\begin{figure}[ht]
\begin{center}
\caption{Select an image to georeference \nixcaption}\label{fig:select_image}\smallskip
  \includegraphics[clip=true, width=12cm]{select_image}
\end{center}
\end{figure}

Now click on the button \button{Arrange plugin window} to open the image in
the georeferencer and to arrange it with the reference map in the qgis map
canvas on your desktop (see Figure \ref{fig:georefplugin}).

\begin{figure}[ht]
\begin{center}
  \caption{Arrange plugin window with the qgis map canvas \nixcaption}\label{fig:georefplugin}\smallskip
  \includegraphics[clip=true,width=\textwidth]{georefplugin}
\end{center}
\end{figure}

With the button \button{Add Point} you can start to add points on the raster image and enter their coordinates, and the plugin will compute the world file parameters (see Figure \ref{fig:choose_points}).
The more coordinates you provide the better the result will be.
For the procedure you have two options:

\begin{enumerate}
\item You click on a point in the raster map and enter the X and Y coordinates manually
\item You click on a point in the raster map and choose the button \button{from map canvas} to add the X and Y coordinates with the help of a georeferenced map already loaded in QGIS.
\end{enumerate}

\begin{figure}[ht]
\begin{center}
  \caption{Add points to the raster image \nixcaption}\label{fig:choose_points}\smallskip
  \includegraphics[clip=true,width=0.9\textwidth]{choose_points}
\end{center}
\end{figure}

For this example we use the second option and enter the coordinates for the selected points with the help of the \filename{roads} map provided with the  \filename{spearfish60} location from: \url{http://grass.osgeo.org/sampledata/spearfish\_grass60data-0.3.tar.gz}

If you don't know how to integrate the \filename{spearfish60} location with
the GRASS plugin, information are provided in Section \ref{sec:grass}. As you
can see in Figure \ref{fig:choose_points}, the georeferencer provides buttons to zoom, pan, add and delete points in the image.

After you added enough points to the image you need to select the transformation type for the georeferencing process and save the resulting world file together with the Tiff.
In our example we choose 
\selectstring{Transform type}{linear transformation} 
although a 
\selectstring{Transform type}{Helmert transformation}
might be sufficient as well.


\begin{Tip}\caption{\textsc{Choosing the transformation type}}
\qgistip{The linear (affine) transformation is a 1st order transformation and is used for scaling, translation and rotation of geometrically correct images.
With the Helmert transformation you simply add coordinate information to the image like geocooding.
If your image is contorted you will need to use software that provides 2nd or 3rd order polynomial transformation, e.g. GRASS GIS.}
\end{Tip} 

The points we added to the map will be stored in a \filename{spearfish\_topo24.tif.points} file together with the raster image.
This allows us to reopen the georeferencer plugin and to add new points or delete existing ones to optimize the result.
The \filename{spearfish\_topo24.tif.points} file of this example shows the points:

\begin{verbatim}
mapX    		mapY    		pixelX  pixelY
591630.196867999969982  4927104.309682800434530 591647  4.9271e+06
608453.589164100005291  4924878.995150799863040 608458  4.92487e+06
602554.903929700027220  4915579.220743400044739 602549  4.91556e+06
591511.138448899961077  4915952.302661700174212 591563  4.91593e+06
602649.526155399973504  4919088.353569299913943 602618  4.91907e+06
\end{verbatim} 

We used 5 coordinate points to georeference the raster image.
To get correct results it is important to disperse the points regulary in the image.
Finally we check the result and load the new georeferenced map \filename{spearfish\_topo24.tif} and overlay it with the map \filename{roads} of the \filename{spearfish60} location.

\begin{figure}[ht]
\begin{center}
  \caption{Georeferenced map with overlayed roads from spearfish60 location
  \nixcaption}\label{fig:result_map}\smallskip
  \includegraphics[clip=true,width=\textwidth]{result_map}
\end{center}
\end{figure}
