# Entertaining Surveying

Hello!

Today I will tell you,% USERNAME%, about~~shoes and sealing wax, cabbage, kings~~ coordinates, projections, geodetic systems, and quite a bit about web mapping. Make yourself comfortable.

As Arthur Clark said, any sufficiently developed technology is indistinguishable from magic. So it is in web-mapping - I think everyone has long been accustomed to using geographical maps, but not everyone imagines how it all works.

Here, it would seem, a simple thing - geographical coordinates. Latitude and longitude, which could be simpler. But imagine that you found yourself on a desert island. The smartphone has drowned, and you have no other means of communication. It remains only to write a letter asking for help and, as usual, throw it into the sea in a sealed bottle.

That's just bad luck - you absolutely do not know where your uninhabited island is, and without indicating the coordinates no one will find you, even if you catch your letter. What to do? How to determine the coordinates without GPS?

So, a little theory to start with. To compare the coordinates on the surface of the sphere, it is necessary to set the origin - the fundamental plane for counting latitudes and the zero meridian for counting longitudes. For the Earth, the equatorial plane and the Greenwich meridian are usually used, respectively.

Latitude (usually denoted by φ) is the angle between the direction to a point from the center of the sphere and the fundamental plane. Longitude (usually denoted by θ or λ) is the angle between the plane of the meridian passing through the point and the plane of the zero meridian.

How to determine your latitude, i.e. the angle between the plane of the earth's equator and the point where you are?

Let's look at the same drawing from a different angle, projecting it onto the plane of our meridian. We also add to the drawing the horizon plane (the tangent plane to our point):

We see that the desired angle between the direction to the point and the equator plane is equal to the angle between the horizon plane and the axis of rotation of the Earth.

So how do we find this angle? Recall beautiful pictures of the starry sky with a long shutter speed:

Here is this point in the center of all the circles described by the stars - the pole of the world. By measuring its height above the horizon, we get the latitude of the observation point.

The question remains how to find the pole of the world in the starry sky. If you are in the Northern Hemisphere, then everything is quite simple:

- Find the Big Dipper bucket;

- mentally draw a straight line through the two extreme stars of the bucket - Dubhe and Merak;

- this line will point you to the handle of the Ursa Minor bucket. The extreme star of this pen - the Polar - almost exactly coincides with the North Pole of the world.

The North Star is always in the north, and its height above the horizon is equal to the latitude of the observation point. If you decide to get to the North Pole, the North Star will be exactly above your head.

In the Southern Hemisphere, things are not so simple. There are no large stars near the south pole of the world, and you will have to find the constellation Southern Cross, mentally extend its larger crossbar and count 4.5 its lengths - somewhere in this area there will be the south pole of the world.

It is easy to find the constellation itself - you have seen it many times on the flags of different countries - Australia, New Zealand and Brazil, for example.

Decided on the latitude. Let's move on to longitude. How to determine longitude on a desert island?

In fact, this is a very difficult problem, because, in contrast to latitude, the reference point of longitude (zero meridian) is chosen arbitrarily and is not attached to any observed landmarks. The Spanish king Philip II in 1567 awarded a substantial reward to the one who proposed a method for determining longitude; in 1598 under Philip III it grew to 6 thousand ducats at a time and 2 thousand ducats of rent for life - a very decent amount at that time. The task of determining longitude for several decades was the idea of fixed mathematicians, like Fermat's theorem in the 20th century.

As a result, they began to determine longitude using this device:

In fact, this device remains the most reliable way to determine longitude (not counting GPS / Glonass) today. This instrument ... (drum roll) ... marine chronometer.

In fact, when the longitude changes, the time zone changes. The difference in local time and Greenwich is easy to determine your own longitude, and very accurately. Each minute of the time difference corresponds to 15 angular minutes of longitude.

Accordingly, if you have a clock that is configured according to Greenwich Mean Time (in fact, it doesn’t matter which one - it’s enough to know the time zone of the place by which your watch’s time is running) - do not rush to translate it. Wait until the local noon, and the time difference will tell you the longitude of your island. (It’s very easy to determine the time of noon — watch the shadows. In the morning, the shadows are shortened, in the second they are lengthened. The moment the shadows began to lengthen is an astronomical noon in the area.)

Both methods of determining coordinates, by the way, are well described in the novel by Jules Verne "Mysterious Island".

So, we were able to determine our latitude and longitude with an error of several degrees, i.e. a couple of hundred kilometers. Perhaps even enough for a note in a bottle is enough, but for geographic maps it is no longer there.

This error is partly due to the imperfection of the tools used, but there are other sources of errors. The Earth can be considered a ball only in the first approximation - in general, the Earth is not a ball at all, but a geoid - a body most similar to a very uneven ellipsoid of revolution. In order to accurately assign coordinates to each point on the earth's surface, rules are needed - how to project a specific point on a geoid onto a sphere.

Such a set of rules should be universal for all geographical maps in the world - otherwise the same coordinates in different systems will denote different points on the earth's surface. At the moment, almost all geographic services use a single point assignment system - WGS 84 (WGS = World Geodetic System, 84 - year of adoption of the standard).

WGS 84 defines the so-called reference ellipsoid is a surface to which coordinates are given for the convenience of calculations. The parameters of this ellipsoid are as follows:

- semi-major axis (equatorial radius): a = 6378137 meters;

- compression: f = 1 / 298.257223563.

From the equatorial radius and compression it is possible to obtain the polar radius, it is also the minor axis (b = a * (1 - f) ≈ 6356752 meters).

Thus, three coordinates are assigned to any point on the earth's surface: longitude and latitude (on a reference ellipsoid) and height above its surface. In 2004, WGS 84 was supplemented by the Earth Gravitational Model (EGM96) standard, which specifies the sea level from which heights are measured.

Interestingly, the zero meridian in WGS 84 is not at all Greenwich (passing through the axis of the Passing Instrument of the Greenwich Observatory), but the so-called IERS Reference Meridian, which runs 5.31 arc seconds east of Greenwich.

Suppose we learned how to determine our coordinates. Now you need to learn how to display the accumulated geographical knowledge on the monitor screen. But this is bad luck - there are not very many spherical monitors in the world (not to mention monitors in the form of a geoid). We need to somehow map the map onto a plane - project it.

One of the easiest ways is to project a sphere onto a cylinder, and then deploy this cylinder onto a plane. Such projections are called cylindrical, their characteristic property is that all meridians are displayed on the map as vertical lines.

There are many projections of a sphere onto a cylinder. The most famous of the cylindrical projections is the Mercator projection (by the name of the Flemish cartographer and geographer Gerard Kremer, better known under the Latinized name Mercator).

Mathematically, it is expressed as follows (for a sphere):

x = R · λ;

y = R · ln (tg (π / 4 + φ / 2), where R is the radius of the sphere, λ is the longitude in radians, φ is the latitude in radians.

At the output, we get the usual Cartesian coordinates in meters. The

map in the Mercator projection looks like this So:

It is easy to notice that the Mercator projection very significantly distorts the shapes and areas of objects. For example, Greenland on the map takes up twice as much area as Australia - although in reality Australia is 3.5 times larger than Greenland.

Why is this projection so good that it has become so popular despite significant distortions? The fact is that the Mercator projection has an important characteristic property: it preserves angles when projecting.

Suppose we want to sail from the Canary Islands to the Bahamas. Draw a straight line on the map connecting the departure and arrival points.

Since all meridians in cylindrical projections are parallel, and the Mercator projection also preserves angles, our line will intersect all meridians at the same angle. And this means that swimming along this line will be very simple for us: it’s enough to maintain the same angle between the course of the vessel and the direction to the polar star (or direction to magnetic north, which is less accurate) throughout the journey, and the desired angle can be easily measure with a banal protractor.

Similar lines intersecting all meridians and parallels at the same angle are called loxodromes. All loxodromes in the Mercator projection are shown directly on the map, and it is this wonderful property that is extremely convenient for maritime navigation, and has brought the Mercator projection wide popularity among sailors.

It should be noted that what has been said is not entirely true: if we project a sphere and move along a geoid, then the direction angle will not be determined quite correctly and we will sail not quite there. (The discrepancy can be quite noticeable - after all, the Earth’s equatorial and polar radii differ by more than 20 kilometers.) An ellipsoid can also be projected with conservation of angles, although the formulas for the Mercator elliptical projection are much more complicated than for the spherical (the inverse transformation is not expressed at all in elementary functions). A complete and detailed description of the mathematics of the Mercator projection on an ellipsoid can be found here .

Traveling around the loxodrome is very simple, but you have to pay for this simplicity: the loxodrome will send you on a journey along an non-optimal route. In particular, the path along the parallel (if it is not the equator) is not the shortest!

In order to find the shortest path on a sphere, you need to draw a circle with a center in the center of the sphere passing through these two points (or, which is the same thing, intersect the sphere with a plane passing through two points and the center of the sphere).

It is impossible to project a sphere onto a plane so that the shortest paths go into straight segments; Mercator's projection, of course, is no exception, and the orthodromes in it look like strongly distorted arcs. Some paths (through the pole) in the Mercator projection cannot be correctly depicted:

This is how the shortest path from Anadyr to Cardiff is projected: first we fly off to infinity strictly to the north, and then we return from infinity directly to the south.

In the case of movement along a sphere, the shortest paths are constructed quite simply using the apparatus of spherical trigonometry, but in the case of an ellipsoid, the task is significantly complicated - the shortest paths are not expressed in elementary functions.

(I note that this problem, of course, cannot be solved by choosing the Mercator spherical projection - the construction of the shortest paths is carried out on the reference ellipsoid WGS 84 and does not depend on the projection parameters.)

During the development of the Yandex.Maps API version 2.0, we faced a difficult task - parameterize the construction of shortest paths so that:

- it was easy to use the built-in functions to calculate the shortest paths on the ellipsoid WGS 84;

- it was easy to set your own coordinate system with your own methods for calculating the shortest paths.

After all, the Maps API can be used not only to display maps of the Earth’s surface, but also, say, the surface of the Moon or some game world.

To construct the shortest paths (geodesic lines) in the general case, the following simple and unpretentious equation is used:

Here - the so-called. Christoffel symbols expressed through partial derivatives of the fundamental metric tensor.

To make the user in such a way to parameterize their mapping area seemed somewhat inhuman to us :).

Therefore, we decided to go another way, closer to the Earth and the needs of our users. In geodesy, the problems of constructing shortest paths make up the so-called first (direct) and second (inverse) surveying tasks.

Note that the direction of travel (track angle) is a continuous function that changes throughout the path.

Having at our disposal the functions of solving these problems, with their help we can solve the cases we need in the Maps API: calculating distances, displaying the shortest paths and building circles on the earth's surface.

We announced the following interface for user coordinate systems:

solveDirectProblem (startPoint, direction, distance) - Solves the so-called first (direct) geodetic problem: where will we be if we exit the specified point in the specified direction and pass the specified distance without folding.

solveInverseProblem (startPoint, endPoint, reverseDirection) - Solves the so-called second (inverse) geodetic problem: to build the shortest route between two points on the surface to be mapped and determine the distance and direction of movement.

getDistance (point1, point2) - returns the shortest (along the geodesic line) distance between two given points (in meters).

This interface seemed to us quite simple to implement in cases where the user is mapping some non-standard surface or using non-standard coordinates. For our part, we wrote two standard implementations - for the ordinary Cartesian plane and for the reference ellipsoid WGS 84. For the second implementation, we used Vincenti formulas . By the way, I directly implemented this runawayed logic , we say hello to him :).

All these geodetic capabilities are available in the Yandex.Maps API, starting with version 2.0.13. Welcome!

Today I will tell you,% USERNAME%, about

As Arthur Clark said, any sufficiently developed technology is indistinguishable from magic. So it is in web-mapping - I think everyone has long been accustomed to using geographical maps, but not everyone imagines how it all works.

Here, it would seem, a simple thing - geographical coordinates. Latitude and longitude, which could be simpler. But imagine that you found yourself on a desert island. The smartphone has drowned, and you have no other means of communication. It remains only to write a letter asking for help and, as usual, throw it into the sea in a sealed bottle.

That's just bad luck - you absolutely do not know where your uninhabited island is, and without indicating the coordinates no one will find you, even if you catch your letter. What to do? How to determine the coordinates without GPS?

So, a little theory to start with. To compare the coordinates on the surface of the sphere, it is necessary to set the origin - the fundamental plane for counting latitudes and the zero meridian for counting longitudes. For the Earth, the equatorial plane and the Greenwich meridian are usually used, respectively.

Latitude (usually denoted by φ) is the angle between the direction to a point from the center of the sphere and the fundamental plane. Longitude (usually denoted by θ or λ) is the angle between the plane of the meridian passing through the point and the plane of the zero meridian.

How to determine your latitude, i.e. the angle between the plane of the earth's equator and the point where you are?

Let's look at the same drawing from a different angle, projecting it onto the plane of our meridian. We also add to the drawing the horizon plane (the tangent plane to our point):

We see that the desired angle between the direction to the point and the equator plane is equal to the angle between the horizon plane and the axis of rotation of the Earth.

So how do we find this angle? Recall beautiful pictures of the starry sky with a long shutter speed:

Here is this point in the center of all the circles described by the stars - the pole of the world. By measuring its height above the horizon, we get the latitude of the observation point.

The question remains how to find the pole of the world in the starry sky. If you are in the Northern Hemisphere, then everything is quite simple:

- Find the Big Dipper bucket;

- mentally draw a straight line through the two extreme stars of the bucket - Dubhe and Merak;

- this line will point you to the handle of the Ursa Minor bucket. The extreme star of this pen - the Polar - almost exactly coincides with the North Pole of the world.

The North Star is always in the north, and its height above the horizon is equal to the latitude of the observation point. If you decide to get to the North Pole, the North Star will be exactly above your head.

In the Southern Hemisphere, things are not so simple. There are no large stars near the south pole of the world, and you will have to find the constellation Southern Cross, mentally extend its larger crossbar and count 4.5 its lengths - somewhere in this area there will be the south pole of the world.

It is easy to find the constellation itself - you have seen it many times on the flags of different countries - Australia, New Zealand and Brazil, for example.

Decided on the latitude. Let's move on to longitude. How to determine longitude on a desert island?

In fact, this is a very difficult problem, because, in contrast to latitude, the reference point of longitude (zero meridian) is chosen arbitrarily and is not attached to any observed landmarks. The Spanish king Philip II in 1567 awarded a substantial reward to the one who proposed a method for determining longitude; in 1598 under Philip III it grew to 6 thousand ducats at a time and 2 thousand ducats of rent for life - a very decent amount at that time. The task of determining longitude for several decades was the idea of fixed mathematicians, like Fermat's theorem in the 20th century.

As a result, they began to determine longitude using this device:

In fact, this device remains the most reliable way to determine longitude (not counting GPS / Glonass) today. This instrument ... (drum roll) ... marine chronometer.

In fact, when the longitude changes, the time zone changes. The difference in local time and Greenwich is easy to determine your own longitude, and very accurately. Each minute of the time difference corresponds to 15 angular minutes of longitude.

Accordingly, if you have a clock that is configured according to Greenwich Mean Time (in fact, it doesn’t matter which one - it’s enough to know the time zone of the place by which your watch’s time is running) - do not rush to translate it. Wait until the local noon, and the time difference will tell you the longitude of your island. (It’s very easy to determine the time of noon — watch the shadows. In the morning, the shadows are shortened, in the second they are lengthened. The moment the shadows began to lengthen is an astronomical noon in the area.)

Both methods of determining coordinates, by the way, are well described in the novel by Jules Verne "Mysterious Island".

# Geoid coordinates

So, we were able to determine our latitude and longitude with an error of several degrees, i.e. a couple of hundred kilometers. Perhaps even enough for a note in a bottle is enough, but for geographic maps it is no longer there.

This error is partly due to the imperfection of the tools used, but there are other sources of errors. The Earth can be considered a ball only in the first approximation - in general, the Earth is not a ball at all, but a geoid - a body most similar to a very uneven ellipsoid of revolution. In order to accurately assign coordinates to each point on the earth's surface, rules are needed - how to project a specific point on a geoid onto a sphere.

Such a set of rules should be universal for all geographical maps in the world - otherwise the same coordinates in different systems will denote different points on the earth's surface. At the moment, almost all geographic services use a single point assignment system - WGS 84 (WGS = World Geodetic System, 84 - year of adoption of the standard).

WGS 84 defines the so-called reference ellipsoid is a surface to which coordinates are given for the convenience of calculations. The parameters of this ellipsoid are as follows:

- semi-major axis (equatorial radius): a = 6378137 meters;

- compression: f = 1 / 298.257223563.

From the equatorial radius and compression it is possible to obtain the polar radius, it is also the minor axis (b = a * (1 - f) ≈ 6356752 meters).

Thus, three coordinates are assigned to any point on the earth's surface: longitude and latitude (on a reference ellipsoid) and height above its surface. In 2004, WGS 84 was supplemented by the Earth Gravitational Model (EGM96) standard, which specifies the sea level from which heights are measured.

Interestingly, the zero meridian in WGS 84 is not at all Greenwich (passing through the axis of the Passing Instrument of the Greenwich Observatory), but the so-called IERS Reference Meridian, which runs 5.31 arc seconds east of Greenwich.

# Flat cards

Suppose we learned how to determine our coordinates. Now you need to learn how to display the accumulated geographical knowledge on the monitor screen. But this is bad luck - there are not very many spherical monitors in the world (not to mention monitors in the form of a geoid). We need to somehow map the map onto a plane - project it.

One of the easiest ways is to project a sphere onto a cylinder, and then deploy this cylinder onto a plane. Such projections are called cylindrical, their characteristic property is that all meridians are displayed on the map as vertical lines.

There are many projections of a sphere onto a cylinder. The most famous of the cylindrical projections is the Mercator projection (by the name of the Flemish cartographer and geographer Gerard Kremer, better known under the Latinized name Mercator).

Mathematically, it is expressed as follows (for a sphere):

x = R · λ;

y = R · ln (tg (π / 4 + φ / 2), where R is the radius of the sphere, λ is the longitude in radians, φ is the latitude in radians.

At the output, we get the usual Cartesian coordinates in meters. The

map in the Mercator projection looks like this So:

It is easy to notice that the Mercator projection very significantly distorts the shapes and areas of objects. For example, Greenland on the map takes up twice as much area as Australia - although in reality Australia is 3.5 times larger than Greenland.

Why is this projection so good that it has become so popular despite significant distortions? The fact is that the Mercator projection has an important characteristic property: it preserves angles when projecting.

Suppose we want to sail from the Canary Islands to the Bahamas. Draw a straight line on the map connecting the departure and arrival points.

Since all meridians in cylindrical projections are parallel, and the Mercator projection also preserves angles, our line will intersect all meridians at the same angle. And this means that swimming along this line will be very simple for us: it’s enough to maintain the same angle between the course of the vessel and the direction to the polar star (or direction to magnetic north, which is less accurate) throughout the journey, and the desired angle can be easily measure with a banal protractor.

Similar lines intersecting all meridians and parallels at the same angle are called loxodromes. All loxodromes in the Mercator projection are shown directly on the map, and it is this wonderful property that is extremely convenient for maritime navigation, and has brought the Mercator projection wide popularity among sailors.

It should be noted that what has been said is not entirely true: if we project a sphere and move along a geoid, then the direction angle will not be determined quite correctly and we will sail not quite there. (The discrepancy can be quite noticeable - after all, the Earth’s equatorial and polar radii differ by more than 20 kilometers.) An ellipsoid can also be projected with conservation of angles, although the formulas for the Mercator elliptical projection are much more complicated than for the spherical (the inverse transformation is not expressed at all in elementary functions). A complete and detailed description of the mathematics of the Mercator projection on an ellipsoid can be found here .

*When we started making our cards at Yandex, it seemed logical to us to use an elliptical Mercator projection. Unfortunately, many other cartographic web services didn’t think so, and they use spherical projection. Therefore, for a long time it was impossible to show tiles, say OSM, on top of the Yandex map - they diverged along the y axis, the closer to the pole - the more noticeable. In API 2.0, we decided not to swim against the tide, and made it possible to both work with the map in an arbitrary projection, and to show several layers in different projections on the map at the same time - as convenient.*# Surveying tasks

Traveling around the loxodrome is very simple, but you have to pay for this simplicity: the loxodrome will send you on a journey along an non-optimal route. In particular, the path along the parallel (if it is not the equator) is not the shortest!

In order to find the shortest path on a sphere, you need to draw a circle with a center in the center of the sphere passing through these two points (or, which is the same thing, intersect the sphere with a plane passing through two points and the center of the sphere).

It is impossible to project a sphere onto a plane so that the shortest paths go into straight segments; Mercator's projection, of course, is no exception, and the orthodromes in it look like strongly distorted arcs. Some paths (through the pole) in the Mercator projection cannot be correctly depicted:

This is how the shortest path from Anadyr to Cardiff is projected: first we fly off to infinity strictly to the north, and then we return from infinity directly to the south.

In the case of movement along a sphere, the shortest paths are constructed quite simply using the apparatus of spherical trigonometry, but in the case of an ellipsoid, the task is significantly complicated - the shortest paths are not expressed in elementary functions.

(I note that this problem, of course, cannot be solved by choosing the Mercator spherical projection - the construction of the shortest paths is carried out on the reference ellipsoid WGS 84 and does not depend on the projection parameters.)

During the development of the Yandex.Maps API version 2.0, we faced a difficult task - parameterize the construction of shortest paths so that:

- it was easy to use the built-in functions to calculate the shortest paths on the ellipsoid WGS 84;

- it was easy to set your own coordinate system with your own methods for calculating the shortest paths.

After all, the Maps API can be used not only to display maps of the Earth’s surface, but also, say, the surface of the Moon or some game world.

To construct the shortest paths (geodesic lines) in the general case, the following simple and unpretentious equation is used:

Here - the so-called. Christoffel symbols expressed through partial derivatives of the fundamental metric tensor.

To make the user in such a way to parameterize their mapping area seemed somewhat inhuman to us :).

Therefore, we decided to go another way, closer to the Earth and the needs of our users. In geodesy, the problems of constructing shortest paths make up the so-called first (direct) and second (inverse) surveying tasks.

**Direct geodesic task:**given the starting point, the direction of movement (usually the direction angle, i.e. the angle between the north direction and the direction of movement) and the distance traveled. It is required to find the end point and the final direction of movement.**Inverse geodesic problem:**two points are given. It is required to find the distance between them and the direction of movement.Note that the direction of travel (track angle) is a continuous function that changes throughout the path.

Having at our disposal the functions of solving these problems, with their help we can solve the cases we need in the Maps API: calculating distances, displaying the shortest paths and building circles on the earth's surface.

We announced the following interface for user coordinate systems:

solveDirectProblem (startPoint, direction, distance) - Solves the so-called first (direct) geodetic problem: where will we be if we exit the specified point in the specified direction and pass the specified distance without folding.

solveInverseProblem (startPoint, endPoint, reverseDirection) - Solves the so-called second (inverse) geodetic problem: to build the shortest route between two points on the surface to be mapped and determine the distance and direction of movement.

getDistance (point1, point2) - returns the shortest (along the geodesic line) distance between two given points (in meters).

*(The getDistance function is highlighted separately for those cases where the calculation of distances can be performed much faster than solving the inverse problem.)*This interface seemed to us quite simple to implement in cases where the user is mapping some non-standard surface or using non-standard coordinates. For our part, we wrote two standard implementations - for the ordinary Cartesian plane and for the reference ellipsoid WGS 84. For the second implementation, we used Vincenti formulas . By the way, I directly implemented this runawayed logic , we say hello to him :).

All these geodetic capabilities are available in the Yandex.Maps API, starting with version 2.0.13. Welcome!