The Affine 4 params transformation - Practical Example

In this section we'll explain how to perform the Affine 4 parameters transformation with CorrMap (please refer to section Basic concepts | Affine for the concepts and the algorithm). To do so, we will follow a practical example. So let's start a new CorrMap project as explained in section Basic Operations[****]| Starting a new project and select the MAP1.PNG (*) file from the CorrMap samples folder (see section Getting started | Samples and demo version). The map will be opened in CorrMap, we then select the Affine transformation in the menu on top as shown in Fig. TR.A1 (1) and we are ready to start.

 

image275

Fig. TR.A1 – A new map ready for the Affine transformation.

 

icona_nota (*)

This map is a typical Cadastral Map provided with a grid of lines in both Easterly and Northerly directions, each of them presents its respective map coordinate. In this map the reference system is a local Cassini-Soldner projection, in other maps the system might change to Gauss-Boaga or Samson-Flamsteed, but whatever the reference system is, it does not matter.

 

 

The Affine transformation is usually performed on old Cadastral maps, provided with grid coordinates, in order to achieve three out of the four goals explained in section Basic concepts | What does it exactly mean to geo-reference a raster map: positioning the raster at the real map coordinates, correcting the orientation error and transforming map units from pixel into the real values (meters, etc.). As described in section Basic concepts | Affine, to apply the Affine algorithm we need at least two points on the raster map of which we also know the real map coordinates. This points are called "reference points" and for this kind of map we can of course rely on the grid points, i.e. the intersections of the grid lines present in the map. Also, if possible we can obviously use more than two points in order to achieve more accurate results.

CorrMap provides two different ways to use map grid points for the Affine transformation:

 

1.Directly clicking the grid points on the map, if the grid lines are present and sufficiently visible.

2.Tracing the grid lines, if they are not present or not sufficiently visible, but the map has some coordinate references along its borders.

 

In the remainder of this example we will explain the first method, the second one is illustrated in the Tracing grid lines section.

 

So, let's click on the Grid-point button on the top-left of the screen as shown in Fig. TR.A1 (2), the mouse cursor will now become a small cross. Then let's zoom to the first grid-point corresponding to the intersection between the lowest and the left hand side grid lines, i.e. the grid point at the most South-West position. As shown in Fig. TR.A2, we need to zoom to the point at a very high level of magnification, so that we can see the raster pixels, in order to click it with high precision. In fact, zooming at a large factor we can easily recognize the single rows and columns of pixels: the squares each of which has its own color.

 

image67

Fig. TR.2 – We need to zoom to the grid-point very precisely, until we can recognize the pixels, in order to click it at the maximum precision.

 

Why do we need to be so precise? Because, as we’ll see once calculated the transformation, the real dimension (in meters) of the pixels can be relevant, depending on the raster resolution. So, it might be that if we mistake of only one pixel, the error could be significant, and if this is the case, we might be led to the wrong conclusion: we think that the raster map is significantly deformed, whereas it is not, but the error only depends on our poor accuracy in performing this operation.

Once we have clicked the grid-point, the window shown in Fig. TR.A3 will appear asking us to insert its real map coordinates which we can easily read directly from the map itself (see first box in Fig. TR.A2).

 

image69

Fig. TR.A3Once we have clicked the grid-point, we simply need to provide its real map coordinates.

 

We then confirm these coordinates by clicking OK and we’ll see an X blue cross appearing exactly where we clicked the grid point. At the same time, in the Output window below, section Reference points, a row is created as shown in Fig. TR.4.

 

 

image73

Fig. TR.A4Here is the just inserted point,  an X blue cross appears on the map and a row of data is created.

 

Let’s see what information this row of data provides:

 

Point: an incremental number assigned to each inserted reference point.

East/North raster: the raster coordinates, i.e. the distances in pixels for both directions between the point and the raster origin, the low-left corner of the raster image.

East/North map: the real map coordinates that we assigned to the reference point. These original map coordinates are also called “nominal coordinates” to indicate that their values are what they should be if the map had not been subjected to any deformation.

 

At this stage we simply need to repeat the operation described above and insert a certain number of reference points in order to perform an accurate transformation (*). How many other reference points should we insert? And in which position? The answer to the first question depends on how good the raster map is. If we know in advance that it’s not significantly deformed, a few points are enough. Otherwise, the higher number of points we use, the better, because, as we’ll see, this abundance of points will allow us to exclude the points resulting in error conditions. The second question leads us to re-consider the algorithm explained in section Basic concepts | Affine. Since this transformation applies a rotation, the best positions for the reference points is possibly to get them along the external grid lines. Doing so, in fact, the calculated rotation result will be more accurate. So, following these considerations, we have completed our example by inserting the 9 reference points  shown in Fig. TR.A5 for which the coordinates are reported in the blue box of Fig. TR.A6.

 

icona_nota (*)

 

a.If you selected the Suggest coords option, explained in section Basic Operations | Common commands | Suggest coords, once you have inserted the first two reference points, the program automatically fills in the coordinates for the remaining points in the window shown in Fig. TR.A3 as soon as you click the point. This is of course very useful because it saves you time and avoids possible errors.

 

b.In case you make some mistake while inserting the reference points, you can easily correct them using the Select and Move point commands available in all CorrMap transformations. Please refer to paragraphs Clipboard and Move point in section Basic Operations | Common commands for the explanation of these commands.

 

c.CorrMap assigns a progressive number to the reference points as you go along inserting them. At the end of the insertion, you can also change these numbers if you don't like them, for example because you did not insert them following a particular order. This utility is explained in paragraph Renumbering reference points below in this section.

 

 

 

image75

Fig. TR.A5Our raster map with the 9 reference points.

 

Well, we can now calculate the transformation by simply clicking the Calculate button in CorrMap’s toolbar as shown in Fig. TR.A1 (3). The calculation produces for the 9 reference points the results shown in the red box of Fig. TR.A6.

 

image76

Fig. TR.A6The results of the transformation for the reference points.

 

These results are:

 

East/North georef: these two columns now contain the raster coordinates transformed into the map reference system by applying the algorithm explained in section Basic concepts | Affine. As we can see, these values are close to those we have manually inserted (columns East/North map) but they differ slightly. Why? Obviously because this raster map had been subjected to deformation due to the possible causes described in section Basic concepts | Why do raster maps need to be geo-referenced? - The map deformation.

 

Deviation: this is the residual value calculated by the least squares algorithm of this transformation and it’s due to the fact that we used 9 reference points, i.e. much more than the minimum 2 strictly required by the algorithm. This data is very important because it allows you to evaluate the reliability of each point: the higher the deviation is, the poorer the reference point reliability is. In other words, assuming that we inserted the points using the necessary care and precision, if a point deviation presents a high value, it means that the area of the map around that point has been subjected to a relevant deformation. In this case therefore, we can remove that point and recalculate so that the whole transformation will be no longer affected by it. To do this in CorrMap is quite simple, select the row of the point you want to exclude and right-click on it, the context menu shown in Fig. TR.A7 will then appear and you can choose either the Disable or the Remove option. The first option simply disables that point from the calculation (the X on the Consider column is removed), whereas the second one completely deletes the point from both the map and the table. Of course finally we might ask what is the acceptable tolerance for deviations. Well, it depends on many factors, first of which the quality of the raster map and second the required precision. In some Countries, for Cadastral tasks, the tolerance is directly stated in official standards. In Italy, for example, the Cadastral Authority indicates a value of 0.50 meters.

 

 

image79

Fig. TR.A7 – How to exclude a reference point presenting a high deviation.

 

Other than the results on reference points the calculation also determines the 4 parameters explained in section Basic concepts | Affine. You can see them in the Results box in CorrMap toolbar at the top, as in Fig. TR.A8.

 

 

image348

Fig. TR.A8The 4 parameters of the transformation.

 

East/North: these two values are the East/North translations applied to the origin of raster map to port it to the real map coordinates. Simply speaking, these numbers are then the map coordinates of the low-left vertex (pixel) of the raster itself.

 

Scale f.: this is the scale factor between the raster (pixel units) and the real map system (meter units). This value is actually the size of the pixels composing this raster map. In our example therefore, the value of 0.25373 indicates that each pixel of the map has a dimension (side of the square) of 0.25373 meters, i.e. about ¼ of a meter. This might now clarify why we said that during the insertion of reference points we should apply good care and precision (zooming until we can estimate each single row/column of pixels). In fact, for this map, one pixel mistake would mean an error of 25 cm. Also, as described in section Basic concepts | Why do raster maps need to be geo-referenced? | Fig. BC.6, this value now explains the difference between the real distance of the grid lines interval, 200 m, and the value in pixels that we measured in the CAD system, 787.965 pixels. In fact if we divide the two values we obtain:

 

200 / 787.965 = 0.253

 

i.e. just the scale factor calculated by the Affine transformation in this example.

 

Rotation: this is the transformation angle in gradians (g), the angular unit also defined as “gon” or “grad” corresponding to 1⁄400 of a turn and with decimal digits. The value -0.0189 means that the raster has been rotated counterclockwise by such an angle to fix it at the real map North direction. Note that here we don't follow the mathematical assumption but the classic topographical one which considers the angle direction as positive for clockwise.

Exporting the geo-referenced map

Well, we have finally calculated the transformation, what use can we make of it now? Simple, we can export the geo-referenced raster map into some common file formats so that we can use it in other applications, such as CAD software. To do so, click the corresponding option in the Export box in CorrMap toolbar (4 in Fig. TR.A1).

GeoTIFF and TWF

Clicking the GeoTIFF/TFW command, CorrMap creates the 2 typical file formats for geo-referenced raster maps. The first is the GeoTIFF format which you can create only if the original raster file was a .TIF file. This format in not actually a new format because the resulting file remains the same .TIF file that you opened in CorrMap at the beginning. The difference between the original (normal) .TIF file and the new GeoTIFF format saved by the export command is that the latter contains the transformation parameters and therefore it will be interpreted as geo-referenced by CorrMap or other software which supports this feature, such as CAD software like AutoCAD and ZWCAD (obviously, while saving the new GeoTIFF file you can choose a different name to the original file, so that you can still maintain the original non-transformed raster map). This means that if you start a new CorrMap project (see section Basic Operations[****]| Starting a new project) using a GeoTIFF file, the program gives you the following information about the geo-referencing in the right side of status bar (at the bottom of the screen) reproduced in Fig. TR.A9:

 

1.The indication that the raster map is geo-referenced.

 

2.The 4 transformation parameter.

 

3.The absolute coordinates of the point where the mouse cursor in positioned in the map.

 

image277

Fig. TR.A9CorrMap shows in the status bar all the geo-referencing information of a GeoTIFF file (or other format plus TFW).

 

The TFW (*) format instead is a simple 6 rows text file that contains the geo-referencing information as numerical data. This file is useful when the original raster file is not a .TIF file (then you can simply transform it into a GeoTIFF file), such as BMP, PNG, JPG, etc. The TFW file acts as an “accompanying” file so that when an application supporting geo-referenced raster files finds a .TFW file with the same name and in the same folder as the raster file you are opening, that program reads the geo-referencing information from the .TFW, thus positioning the image into the real coordinate system. For our example the TFW file exported contains the following 6 rows:

 

icona_nota (*)

The acronym TFW stands for Tiff World File, i.e. a file which contains the absolute (World) coordinates of the image.

 

 

0.25372531

0.00007524

0.00007524

-0.25372531

-34811.19736778

54938.86869373

 

Their values are:

 

1.Scale factor (pixel resolution) multiplied by the cosine of rotation angle: f  cos ε

2.Scale factor (pixel resolution) multiplied by the sine of rotation angle: f  sin ε.

3.The same as row 2.

4.The same as row 1 but with negative sign. This minus sign is used to indicate that the image Y-axis is positive down which is the opposite from real world coordinates.

5.The Easting of the upper left pixel (0,0 in image coordinates).

6.The Northing of the upper left pixel.

 

With reference to the rotational-translation matrix (2) in section Basic concepts | Affine the first four values are the central part of the matrix, i.e. the scale factor multiplied by the sine and cosine of the rotation angle:

image82

The final two values are the East/North map coordinates of the upper left pixel of the raster map. But please note that these values differ from the ones calculated by the transformation. This is due to the same reason mentioned for value 4, i.e. real map systems consider the map origin at the lower-left vertex and the North coordinate positive upward, whereas standard graphics software puts the image origin in the upper left pixel and vertical coordinate positive downward. So, you would expect that at least the Easting should be equal to that calculated, but this is not the case either because the raster has been rotated counterclockwise by -0.189 grads. In other words, the TFW file contains the transformation information, but in its own format.

When you click the GeoTIFF/TFW command from CorrMap Affine (or Barycentric) toolbar, the program proposes as the name of the .TFW file the same name of the original raster map. So, in the example above, the raster name MAP1.PNG will become MAP1.TFW. As mentioned above, once you have created the .TFW file placing it in the same folder as the original raster file, if you start a new CorrMap project (see section Basic Operations[****]| Starting a new project) using that raster again, the program will also find the .TFW file, so it will provide the geo-referencing information in the status bar as explained above for the GeoTIFF format (Fig. TR.A9).

DXF

The most useful and popular file format provided by CorrMap is the DXF file, because it is usable by CAD software. By clicking the DXF drawing option in the Export box in the CorrMap toolbar, shown in Fig. TR.A9, you can easily create this file. This command requests the name of the DXF file to create (MAP1_AFFINE.DXF in this example) and, as soon as the DXF file is successfully created, you get the message shown in Fig. TR.A10, and you can open it in your CAD software which is associated to DXF files in your Windows installation.

 

image359

Fig. TR.A10You can directly open the DXF drawing containing the geo-referenced map in the CAD software associated to DXF files in your Windows installation.

 

Fig. TR.11 shows the DXF drawing containing the geo-referenced map opened in the CAD software. At first sight this drawing seems the same of the one shown in section Basic concepts | Why do raster maps need to be geo-referenced? | Fig. BC.3. But it is not, this one is the geo-referenced map, as you can see the 9 red X’s positioned in the corresponding reference points used for the transformation.

 

image360

Fig. TR.A11The DXF containing the geo-referenced map opened in the CAD software.

Evaluating the geo-referencing

Now that we have the geo-referenced map in our CAD software, let’s see how the transformation has modified the map. We’ll do this by reproducing the same operations explained in section Basic concepts | Why do raster maps need to be geo-referenced? | A non-geo-referenced raster map has no reference system and real units. The first operation was showing the coordinates of the map lower-left vertex using the usual CAD Inquiring command to obtain the coordinates of a point (Fig. BC.4). That time the CAD system simply showed X=0 Y=0 Z=0 coordinates. As shown in Fig. TR.A12, repeating the same task in our new geo-referenced map we’ll get the real map coordinates of the raster origin calculated by the transformation as shown in Fig. TR.A8:

 

X= -34810.754

Y=  53445.188

 

image97

Fig. TR.A12The origin of the raster has now the real map coordinates.

 

Now let’s also ask for the coordinates of the first reference point used for the transformation, as we did in Fig. BC.5. In that case we got the values:

 

X = 831.012

Y = 610.106

 

which were simply the number of pixels in horizontal and vertical direction between the raster origin and that point. Now instead we get the real and exact coordinates written in the map, as shown in Fig. TR.A13.

 

E = -34600.000

N =  53600.000

 

image96

Fig. TR.A13Reference points have now their real map coordinates.

 

But is this really true? No, it is not. We get these exact map values only because we selected the point using the CAD object-snap, thus exactly selecting the red X, i.e. the CAD symbol of that point. But this symbol is actually placed by CorrMap at the absolute map coordinates, so it obviously has those values. To clarify this, let’s zoom in to the reference point very close as in Fig. TR.A14. Doing so, we can see that there is still a small difference between the position of the red X, the symbol at the absolute map coordinates, and the raster intersection of the two grid lines where we clicked the reference point when we performed the transformation. In fact, asking for the coordinates of this intersection (not using the object-snaps) we do not get the absolute coordinates but slightly different values:

 

E = -34600.218

N =  53599.755

 

 

image95

Fig. TR.A14Despite transformation, reference points have maintained their deformation compared to their absolute coordinates.

 

We will explain why shortly. First, let’s complete the third operation we performed when we imported the non-geo-referenced raster map in the CAD system in section Basic concepts | Why do raster maps need to be geo-referenced? | A non-geo-referenced raster map has no reference system and real units. This operation consisted of getting the distance between 2 two consecutive grid lines (Fig. BC.6). At that time we got the value:

 

788.132

 

instead of 200 meters. Performing the same measurement now we get the real dimension in meters, but we still do not get exactly 200 meters, but we get:

 

200.534

 

as shown in Fig. TR.A15. The reason of this discrepancy is just the same as the difference between the coordinates in Fig. TR.A14 and it’s quite a simple reason: this transformation does not remove the deformation of the map or, in other words, it does not rectify the map. The raster map was deformed before the transformation and it still is deformed after the transformation. This geo-referencing technique, in fact, simply applies a scale factor to the raster image in order to transform it from pixels to meters, but it does not alter the image itself. In other words, the original raster map has only been scaled but the image itself has remained the same, i.e. maintaining its deformation.

 

image98

Fig. TR.A15We still do not get exactly 200 meters as two grid lines interval.

 

This obviously leads to the conclusion that this method can only be suitable for certain purposes, such as verifying the quality of the scanning process, but it is not suitable at all for tasks in which a higher level of precision is required, as, for example, in the case of boundary disputes. For these kind of tasks we need some other techniques which really correct the map’s deformation, as we’ll see in the sections of this guide dedicated to the other transformations provided by CorrMap.

Tracing grid lines

Some maps does not present the grid lines but only their references (marks) along the border of the map itself. In this case, you cannot directly insert the grid points for the geo-referencing. CorrMap lets you overcome this problem by manually tracing the grid lines and automatically calculating the grid points. Let's explain this functionality by performing a practical example. So let's start a new CorrMap project as explained in section Basic Operations[****]| Starting a new project and select the MAP2.PNG (scale 1 : 1000) file from the CorrMap samples folder (see section Getting started | Samples and demo version). The map will be opened in CorrMap, we then select the Home section in the menu on top as shown in Fig. TR.A16 (1) and we are ready to start.

image259

Fig. TR.A16CorrMap lets you trace grid lines for maps that only present reference marks along the border.

 

Now using the zoom commands (see section Basic Operations | Common commands) we zoom in the first reference mark on the bottom-left border of the raster (2 in Fig. TR.A16) and then we click the Grid line button in CorrMap toolbar (3 in Fig. TR.A16). This command let us trace the grid line connecting two reference marks. So, we zoom the first mark at a very high level so that the raster pixels become visible and we click it at the maximum precision as shown in Fig. TR.A17.

 

image248

Fig. TR.A17CorrMap lets you zoom reference marks until pixels become visible so you can reach the maximum precision.

 

Once we have clicked the point, we need to move up to the corresponding mark in the upper edge of the map. We can do this in two ways:

 

1.Press the Page-Up key on the keyboard. Doing so you get the screen scrolling up while maintaining verticality.

 

2.Press the mouse wheel, the cursor changes to a hand and allows you to move the raster by clicking the left mouse button and dragging the raster holding it down (see the explanation of the Pan command in section Basic Operations | Common commands). You can also zoom dynamically by turning the mouse wheel, but be careful, after zooming, the cursor returns to be a cross, ready to click the second point, so if you want to return to Pan mode for further translating the map, you need to click the wheel again. So, using in combination the dynamic zoom and Pan, you can easily locate the area of the corresponding mark, as shown in Fig. TR.A18. Zoom in this area until you can see the pixels of this mark and click it (Fig. TR.A19).

 

image250

Fig. TR.A18You can easily locate the corresponding mark by using the dynamic zoom and Pan in combination.

 

image251

Fig. TR.A19Once you have traced the line you only need to insert its coordinate.

 

Once we have clicked the second mark, the window reproduced in Fig. TR.A19 is opened, asking us the coordinate of the line just traced. In this case, having traced a vertical grid line, the coordinate is the Easting. So, let's type this value by simply reading it from the map itself (2 in Fig. TR.A16) ad confirm by clicking OK, the grid line is traced on the map as shown in Fig. TR.A20.

 

image253

Fig. TR.A20The inserted grid line.

 

Let's proceed with the vertical grid line next to that just inserted. Once we have clicked the second mark, in the window for inserting the coordinate we can simply use the Increase/Decrease buttons to add or subtract the grid interval from the previous inserted line (Fig. TR.A21). Please note that this interval has the value that you inserted when you opened the map as explained in section Basic Basic Operations[****]| Starting a new project.

 

image254

Fig. TR.A21You can easily insert the coordinate using the Increase/Decrease buttons.

 

Let's then trace the third vertical grid line next to that already inserted, repeating the same operations. Now we need to insert the horizontal grid lines. To do so we simply act in the same way as for the vertical grid line, with the only difference that, once the mark on the left border of the map is clicked, to reach the corresponding mark on the right border we can press the End key on the keyboard or use with the dynamic zoom and Pan as explained above. Of course if we start our line from the right border, we can press the Home key on the keyboard to quickly reach the left border. Fig. TR.A22 and Fig. TR.A23 shows the tracing of a horizontal grid line.

 

image255

Fig. TR.A22Tracing horizontal grid lines is also easy.

 

image256

Fig. TR.A23The Northing coordinate of a horizontal grid line.

 

We then insert the horizontal grid line next to that just inserted. After that the map appears as the one reproduced in Fig. TR.A24, i.e. with all the grid lines we have traced.

While we are tracing grid lines, in case of mistakes, we can always delete the last inserted line or remove all inserted lines by clicking the buttons Remove last line and Remove all lines from the CorrMap toolbar.

Finally, we click the Calculate grid points button in CorrMap toolbar (4 in Fig. TR.A16), the grid points are automatically created on both the map and the Reference points table in the Output window at the bottom, as shown in Fig. TR.A25.

 

image257

Fig. TR.A24Here are all East/North traced grid lines.

 

image258

Fig. TR.A25And finally here are the grid points automatically created by CorrMap.

 

This final step has reproduced the same situation as if we had inserted the grid points based on grid lines already present in the map, as in the example developed at the beginning of this section. We can then proceed with the calculation of the Affine transformation as explained in that paragraph.

Renumbering reference points

Whilst you insert the reference points for the Affine transformation CorrMap assigns an incremental number to each point as you insert them. So, it might happens that at the end of the insertion, you don't like this numbering because you did not insert the points following a particular order, or the order has been altered due to some deletions or additions of points. In this case you can automatically change the point numbers as required. To do so, having finished inserting the reference points, move to the Home CorrMap section as shown in Fig. TR.A26 (1), then click the Renumber grid-points button (2 in Fig. TR.A26), the command window shown in Fig. TR.A27 opens asking you for the re-numbering order you want to choose.

 

image278

Fig. TR.A26CorrMap allows you to automatically change the point numbers as required.

 

 

image280

Fig. TR.A27You can easily choose the required re-numbering order.

 

For instance, as you can see from Fig. TR.A26, in the example explained in this section we have followed the order (*) indicated by the blue box in Fig. TR.A27 (bottom-up then left-right). So, let's now change to the numbering indicated by the red box (left-right then top-down). All we need to do is to chose this option (the radio-button below the schema) and confirm with OK. The grid point numbers are automatically changed to the new order, both on the map and in the Reference points table in the Output window, as shown in Fig. TR.A28.

 

image282

Fig. TR.A28The new grid point numbers of both the map and the in the Reference points table.

 

 

icona_nota (*)

Please note that this utility works in all CorrMap transformations, not only in those based on grid points (Affine and Grid). This means that the renumbering is also applied to the transformations Barycentric, Homography, Rubber-Sheeting and Trilateral in which the reference points are randomly located because they correspond to surveyed points