english français

Ref.txt calibration file

The method of calibrating maps by writing a ref.txt calibration file is powerful and versatile. The idea is to specify some calibration points on the map (typically 4, but 2 may be sufficient). A calibration point is a point on a map for which one specifies its geographic coordinates (longitude and latitude, or coordinates in a given map projection). In the ref.txt file, one can also specify the cartographic projection used by the map. This information is generally required to obtain good accuracy in the calibration of large maps (covering areas of more than 100 km).

A ref.txt calibration file is a plain text document that can be written using eg TextEdit (on MacOS) or NotePad (on Windows). Note that Multiplans adopts the convention that the GPS coordinates are given in the order longitude, latitude (and not the reverse order latitude, longitude as in Google Maps).

Two cases may arise:

(A) Case of a map whose cartographic projection is unknown

If the used map projection is unknown, one can calibrate approximately the map by specifying four (or possibly only 2) calibration points on the map. The best results are obtained with four calibration points located near the four corners of the map.

Example: file ref.txt with four calibration points
Bilinear interpolation
0, 0 = 6.708785, 51.233717
0, 8000 = 6.851875, 51.236431
8000, 8000 = 6.856050, 51.146598
8000, 0 = 6.713237, 51.143892

The 1st line of file ref.txt contains the keyword "Bilinear interpolation", which tells Multiplans that it should interpolate or extrapolate the coordinates from the 4 (or 2) calibration points that are given in the next few lines in the file.
The calibration points are entered as lines of the form
x, y = longitude, latitude
where x and y are the coordinates (in pixels) of a point on the map, and "longitude, latitude" are the corresponding GPS geographical coordinates of this point (WGS84 datum). The coordinates x = 0, y = 0 corresponds to the upper-left corner of the image, while the point x = 0, y = 8000 pixels is located 8000 pixels below, on the left edge of the image. In this example, the four calibration points are located at the corners of a map of size 8000x8000 pixels, but it is not mandatory to put the calibration points exactly at the corners of the image. The four points must be put at the vertices of a rectangle or of a quadrilateral that is a "not too distorted" rectangle (technically speaking: the quadrilateral must be convex). If three calibration points are aligned along a straight line, the results will not be good!

To find the coordinates (in pixels) of a point on an image, one can use eg GraphicConverter (on MacOS), menu "Windows -> Contact." Alternatively, one can Multiplans to find these coordinates: Import the map without calibration file, and then create a point-of-interest on the map. The information screen on the point of interest displays the pixel coordinates of that point. (In a future version of Multiplan, it will be possible to indicate graphically the calibration points on the map, without having to write a ref.txt calibration file)

The method of bilinear interpolation with 4 points gives in general good results for maps that have a not too large geographical extent (less than 100 km). In the case where the lines of constant longitude (and those of constant latitude) are aligned along the vertical (respectively along the horizontal) direction, it is sufficient to specify only two calibration points. In that case, choose the two calibration points to lie approximately near two diagonally opposite corners of the map.

(B) Case of a map that uses a known projection

This is the ideal case, where we know the cartographic projection used by the map. We can then specify the projection on the first line of the ref.txt file and enter in the following lines of the file only two calibration points. 2 points are indeed sufficient to obtain an exact calibration when the map projection is known. (Warning: specify only 2 calibration points and not more!)

The map projection can be specified either by the keyword "EPSG:" followed by the EPSG projection number or by the keyword "PROJ", followed by a series of keywords describing this projection in the language PROJ library.

Example: The Swiss map above, like any swisstopo map, uses an oblique Mercator projection with EPSG number 21781. On page map.geo.admin.ch map (Avenches) , one can easily find the geographic coordinates of a point on the map. We determined in this way the geographical coordinates of two calibration points, shown in red in the picture above. With this information, the map can be calibrated by writing one of the following contents in file ref.txt:
Ref.txt file with EPSG map projection number, followed by two entries corresponding to two calibration points (geographic coordinates are expressed in Swiss coordinates)
EPSG: 21781
135,56 = 569000,193000
1136,656 = 574000,190000
Same, but with the coordinates of calibration points given in the WGS84 system (GPS)
EPSG: 21781
135.56 = 7.03193, 46.88734 (WGS84)
1136.656 = 7.09766, 46.8606 (WGS84)

Note that if one enter the geographical coordinates of calibration points in the WGS84 system, that is by their GPS coordinates, we have to add the keyword "(WGS84)" after the coordinates (warning: do not write "WGS 84" with a space, but "WGS84"). The syntax for a calibration point is then
x, y = longitude, latitude (WGS84)
In the absence of keyword "WGS84", the coordinates are interpreted as being expressed in the system of the map projection defined in the first line of file ref.txt.

To find the EPSG number of a cartographic projection, see table on next page .

Instead of specifying the EPSG projection number, the cartographic projection can be described by using the keywords of the library PROJ4. This is particularly useful when the projection has no assigned EPSG number. Another advantage of using the description by the PROJ library is that the various parameters that enter in the definition of the projection are explicitly mentioned. The first line of the file ref.txt begins then by keyword "PROJ" (instead of "EPSG"), as in the following example:
File ref.txt with projection defined using the proj library
PROJ:+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
135,56 = 569000,193000
1136,656 = 574000,190000
To find how to describe a map projection using the PROJ library, refer to the next page .

In any case, we can check if a ref.txt calibration file is correct by adding a point of interest on the map, and by checking if its shown longitude and latitude coordinates are correct.

Variation: 1-point calibration and resolution
Instead of giving two calibration points, it is possible to give only one point, and to enter in the next line of the file ref.txt, the resolution of the map. For the Swiss map above, we could also write the following calibration files:
Ref.txt file with a single calibration point, followed by the resolution of the map
EPSG: 21781
135,56 = 569000,193000
resolution: 5
Same, the calibration point being located at the center of the map
EPSG: 21781
center = 7.0636, 46.87376 (WGS84)
resolution: 5
The resolution of the map must be entered in "unit of cartographic coordinates" / pixel. For example, if the X and Y coordinates are measured in meters, the resolution must be given in meters per pixel.
If the geographic coordinates of the calibration point are given in the WGS84 system, the concomitant use of keyword "resolution" requires version 1.41 (or later) of Multiplans to work properly.

Note: The syntax of the ref.txt has evolved since the first version of Multiplans. The syntax used by the first versions of Multiplans ( see here ) is still accepted, but it is not recommended for use.

Note: In the current version, Multiplans assumes that the map has not been rotated relative to the cartographic projection defined in the first line of file ref.txt. This means that the lines with coordinate X = constant (or Y = constant) (where X and Y are the coordinates defined by the map projection, such as Swiss coordinates) must be horizontal (resp. vertical), as in the example of the Swiss map above. If the map shows a grid of X, Y coordinates which has been rotated, use a drawing program to compensate for the rotation before calibrating the map. The compensation of the rotation must be done for instance in the case of some scans of IGN map sheets: introduce a rotation so that the small black crosses corresponding to the Lambert grid are aligned horizontally and vertically (the problem of rotation applies only to scans of maps IGN paper, not to the maps coming from the IGN geoportal). See this document of Raymondo.

Fichier de calibrage ref.txt

La méthode de calibrage par écriture d'un fichier de calibrage ref.txt est puissante et versatile. L'idée est de préciser quelques points de calibrage sur la carte (typiquement 4, mais 2 peuvent suffire). Un point de calibrage est un point auquel on associe des coordonnées géographiques données (coordonnées de longitude et de latitude, ou coordonnées correspondant à une certaine projection cartographique). Lors du calibrage, on peut également préciser la projection cartographique employée par la carte. Cette information est en général nécessaire pour obtenir une bonne précision dans le calibrage de grandes cartes (couvrant des zones de plus de 100 km).

Noter que le fichier de calibrage ref.txt pour des cartes provenant de certains sites web cartographiques (en particulier les cartes Google maps, les cartes des géoportails français, suisse, anglais, etc.) peuvent être générés automatiquement! Voir explications à la page Visualiseurs de cartes.

Un fichier de calibrage ref.txt est un simple document de texte, que l'on peut écrire par exemple avec TextEdit (sur MacOS) ou NotePad (sur Windows). Noter que Multiplans adopte la convention que les coordonnées GPS sont toujours données dans l'ordre longitude, latitude (et non l'ordre inverse longitude, latitude comme dans Google Maps).

Deux cas peuvent se présenter:

(a) Cas d'une carte de projection cartographique inconnue

Si la projection cartographique utilisée est inconnue, on peut calibrer approximativement la carte en spécifiant 4 (ou éventuellement que 2) points de calibrage sur la carte. Les meilleures résultats seront obtenus avec 4 points de calibrage situés non loins des quatre coins de la carte.

Exemple: fichier ref.txt avec 4 points de calibrage
Bilinear interpolation
0, 0 = 6.708785, 51.233717
0, 8000 = 6.851875, 51.236431
8000, 8000 = 6.856050, 51.146598
8000, 0 = 6.713237, 51.143892

La 1re ligne du fichier ref.txt contient le mot-clé "Bilinear interpolation", qui indique à Multiplans qu'il doit interpoler, voire extrapoler, les coordonnées à partir des 4 (ou 2) points de calibrage indiqués dans les lignes suivantes du fichier.
Les points de calibrage sont donnés à l'aide de lignes de la forme
x, y = longitude, latitude
où x et y sont les coordonnées (en pixels) d'un point sur la carte, et "longitude, latitude" sont les coordonnées géographiques correspondantes de ce point (dans le datum WGS84, c'est-à-dire les coordonnées GPS du point). Le point de coordonnées x=0,y=0 correspond au coin en haut à gauche de l'image, tandis que le point x=0,y=8000 est situé 8000 pixels plus bas sur le bord gauche de l'image. Dans cet exemple, les 4 points de calibrage sont situés aux quatre coins d'une carte de dimensions 8000x8000 pixels, mais il n'est pas obligatoire de positionner les points exactement aux coins de l'image. Les 4 points doivent être placés aux sommets d'un rectangle, ou d'un quadrilatère correspondant à un rectangle "pas trop déformé" (techniquement parlant: le quadrilatère doit être convexe). Si 3 points de calibrage sont alignés selon une droite, les résultats ne seront pas bons!

Pour trouver les coordonnées (en pixels) d'un point sur une image, on peut utiliser par exemple GraphicConverter (sur MacOS), menu "Fenêtres-->Coordonnées". Alternativement, on peut utiliser Multiplans pour trouver ces coordonnées: importer la carte sans fichier de calibrage, puis créer un point d'intérêt sur la carte. L'écran d'information sur le point d'intérêt affiche les coordonnées pixels du point. (Dans une version future de Multiplans, il sera possible d'indiquer graphiquement les points de calibrage sur la carte, sans passer par l'écriture d'un fichier de calibrage ref.txt)

La méthode d'interpolation bilinéaire à 4 points donne en général de bons résultats pour des cartes d'une étendue géographique pas trop grande (moins de 100 km). Dans le cas où les lignes de longitude constante (et de latitude constante) sont alignées selon la verticale (respectivement selon l'horizontale), il est suffisant de ne spécifier que 2 points de calibrage. Choisir alors ces deux points de calibrage approximativement vers 2 coins diagonalement opposés de la carte.

(b) Cas d'une carte de projection cartographique connue

Il s'agit du cas idéal, où l'on connaît la projection cartographique employée par la carte. On peut alors indiquer cette projection sur la première ligne du fichier ref.txt et ne spécifier dans les lignes suivantes que 2 points de calibrage. 2 points sont en effet suffisants pour obtenir un calibrage exact lorsque la projection cartographique est connue. (Attention: ne mettre que 2 points de calibrage, et non pas 4!)

La projection cartographique peut être indiquée soit par le mot-clé "EPSG:" suivi du numéro EPSG de la projection, soit par le mot-clé "PROJ:", suivi d'une suite de mot-clés décrivant cette projection dans le langage de la librairie PROJ.

Exemple: La carte suisse ci-dessus emploie, comme toute carte de swisstopo, une projection de Mercator oblique portant le numéro EPSG:21781. À la page map.geo.admin.ch (carte d'Avenches), on peut lire aisément les coordonnées géographiques d'un point donné de la carte. On a déterminé ainsi les coordonnées géographiques de deux points de calibrage, indiqués en rouge dans l'image ci-dessus. Avec ces informations à disposition, cette carte peut être calibrée en écrivant, à choix, l'un des contenus suivants dans le fichier ref.txt:
Fichier ref.txt avec no de projection cartographique EPSG, suivi par la donnée de deux points de calibrage (les coordonnées géographiques sont exprimées en coordonnées suisses)
EPSG:21781
135,56 = 569000,193000
1136,656 = 574000,190000
Idem, mais avec les coordonnées des points de calibrage indiquées dans le système WGS84 (coordonnées GPS)
EPSG:21781
135,56 = 7.03193, 46.88734 (WGS84)
1136,656 = 7.09766, 46.8606 (WGS84)

Noter que si l'on indique les coordonnées géographiques des points de calibrage dans le système WGS84, autrement dit par leur coordonnées GPS, il faut ajouter le mot-clé "(WGS84)" après les coordonnées (attention: ne pas écrire "WGS 84" avec un espace, mais bien "WGS84"). La syntaxe pour un point de calibrage est alors
x, y = longitude, latitude (WGS84)
En l'absence de ce mot-clé "WGS84", les cordonnées sont interprétées comme étant données dans le système de projection cartographique défini dans la première ligne du fichier ref.txt.

Pour trouver le numéro EPSG d'une projection, se référer au tableau à la page suivante.

Au lieu d'indiquer la projection par son numéro EPSG, on peut la décrire au moyen des mot-clés de la librairie PROJ4. Cela est particulièrement utile dans le cas où la projection n'a pas encore de numéro EPSG attribué. Un autre avantage d'utiliser la description par la librairie PROJ est que les différents paramètres entrant dans la définition de la projection sont explicitement mentionnés. La première ligne du fichier ref.txt commence alors par le mot-clé "PROJ:" (au lieu de "EPSG:"), comme dans l'exemple suivant:
Fichier ref.txt avec projection décrite par la librairie proj4
PROJ:+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
135,56 = 569000,193000
1136,656 = 574000,190000
Pour trouver comment décrire une projection cartographique en utilisant la librairie PROJ, se référer à la page suivante.

Dans tous les cas, on peut vérifier si un fichier de calibrage ref.txt est correct en créant un point d'intérêt sur la carte, et en vérifiant si les coordonnées de longitude et latitude de ce point calculées par Multiplans sont correctes.

Variante: calibration à 1 point et résolution
Au lieu de donner deux points de calibrage, il est possible de ne donner qu'un seul point, et d'indiquer, dans le ligne suivante du fichier ref.txt, la résolution de la carte. Pour la carte suisse ci-dessus, on aurait pu par exemple également écrire les fichiers de calibrage suivants:
Fichier ref.txt avec un seul point de calibrage, suivi de l'indication de la résolution de la carte
EPSG:21781
135,56 = 569000,193000
resolution: 5
Idem, le point de calibrage étant situé au centre de la carte
EPSG:21781
center = 7.0636, 46.87376 (WGS84)
resolution: 5
Attention: le mot-clé à utiliser est bien "resolution" (sans accent car en anglais), et non "résolution". La résolution de la carte doit être indiquée en "unité de coordonnées cartographiques"/pixel. Par exemple, si les coordonnées X et Y sont mesurées en mètre, la résolution doit être donnée en mètres par pixel.
Si les coordonnées géographiques du point de calibration sont données dans le système WGS84, l'utilisation concomittante du mot-clé "resolution" ne fonctionne correctement qu'à partir de la version 1.41 de Multiplans.

Remarque: La syntaxe du fichier ref.txt a evolué depuis la première version de Multiplans. La syntaxe utilisée par les premières versions de Multiplans (voir ici) est toujours acceptée, mais il n'est pas recommandé de l'utiliser.

Remarque: Dans la version actuelle, Multiplans suppose que la carte n'a pas subi de rotation par rapport à la projection cartographique définie dans la première ligne du fichier ref.txt. Cela signifie que les lignes de coordonnées X=constante (ou Y=constante) (où X et Y sont les coordonnées cartographiques définies par la projection cartographique, par exemple les coordonnées suisses) doivent être horizontales (resp. verticales), comme dans l'exemple de la carte suisse ci-dessus. Si la carte montre une grille de coordonnées X,Y qui a subi une rotation, il faut utiliser un programme de dessin pour compenser cette rotation avant de calibrer la carte. Cette compensation de la rotation doit être effectuée dans le cas de scans de certaines cartes IGN papier: introduire une rotation de sorte que les petites croix noires de la grille Lambert soient alignées horizontalement et verticalement (ce problème de rotation ne concerne que les scans de cartes IGN papier, et non les cartes IGN du géoportail). Voir ce document de Raymondo.

Exemples de calibrage de cartes

Rappel: la page Visualiseurs de cartes permet de générer automatiquement le fichier de calibrage de cartes de certains sites web.