# Chapter 2 Coordinate systems

For spatial data, the location of observations are characterised by coordinates, and coordinates are defined in a coordinate system. Different coordinate systems can be used for this, and the most important difference is whether coordinates are defined over a 2-dimensional or 3-dimensional space referenced to orthogonal axes (Cartesian coordinates), or using distance and directions (polar coordinates, spherical coordinates). Figure 2.1: Two-dimensional polar (red) and Cartesian (blue) coordinates

## 2.1 Cartesian and geodetic coordinates

Figure 2.1 shows both polar and Cartesian coordinates for a standard two-dimensional situation. In Cartesian coordinates, the point shown is $$(x,y) = (3,4)$$, for polar coordinates it is $$(r,\phi) = (5, \mbox{arctan}(4/3))$$, where $$\mbox{arctan}(4/3)$$ is approximately $$0.93$$ radians, or $$53^{\circ}$$. Note that $$x$$, $$y$$ and $$r$$ all have length units, where $$\phi$$ is an angle (a unitless length/length ratio). Converting back and forth between Cartesian and polar coordinates is trivial, $x = r~\mbox{cos} \phi$ $y = r~\mbox{sin} \phi$ $\phi = \mbox{arctan}(y/x)$ $r = \sqrt{x^2 + y^2}$ but requires care with using the right quadrant for $$\mbox{arctan}$$; the atan2 function is helpful here.

## 2.2 Ellipsoidal coordinates

In three dimensions, where Cartesian coordinates are expressed as $$(x,y,z)$$, spherical coordinates are the three-dimensional equivalent of polar coordinates and can be expressed as $$(r,\lambda,\phi)$$, where

• $$r$$ is the radius of the sphere,
• $$\lambda$$ is the longitude, measured in the $$(x,y)$$ plane counter-clockwise from positive $$x$$, and
• $$\phi$$ is the latitude, the angle between the vector and the $$(x,y)$$ plane.

$$\lambda$$ typically varies between $$-180^{\circ}$$ and $$180^{\circ}$$ (or alternatively from $$0^{\circ}$$ to $$360^{\circ}$$), $$\phi$$ from $$-90^{\circ}$$ to $$90^{\circ}$$. When we are only interested in points on a sphere with given radius, we can drop $$r$$: $$(\lambda,\phi)$$ now suffice to identify any point.

It should be noted that this is just a definition, one could for instance also choose to measure polar angle, i.e. the angle between the vector and $$z$$, instead of latitude. There is also a long tradition of specifying points as $$(\phi,\lambda)$$ but throughout this book we will stick to longitude-latitude, $$(\lambda,\phi)$$.

For points on an ellipse, there are two ways in which angle can be expressed (figure 2.2): measured from the center of the ellipse ($$\psi$$), or measured perpendicular to the tangent on the ellipse at the target point ($$\phi$$). Figure 2.2: Angles on an ellipse: geodetic (blue) and geocentric (red) latitude

The most commonly used parametric model for the Earth is an ellipsoid of revolution, an ellipsoid with two equal semi-axes (Iliffe and Lott 2008). In effect, this is a flattened sphere (or spheroid): the distance between the poles is (slightly: about 0.33%) smaller than the distance between two opposite points on the equator. Under this model, longitude is always measured along a circle, but latitude along an ellipse. If we think of figure 2.2 as a cross section of the Earth passing through the poles, the latitude measure $$\phi$$ is the one used when no further specification is given; it is also called geodetic latitude. The latitude measure $$\psi$$ is called the geocentric latitude.

In addition to longitude and latitude we can add altitude to define points that are not on the spheroid, and obtain a three dimensional space again. When defining altitude, we need to choose

• where zero altitude is: on the ellipsoid, or relative to the surface approximating mean sea level (the geoid)?
• which direction is positive, and
• which direction is “straight up”: perpendicular to the spheroid surface, or in the direction perpendicular to the surface of the geoid?

All these choices may matter, depending on the application area.

## 2.3 Distances

Distances between two points $$p_i$$ and $$p_j$$ in Cartesian coordinates are computed as Euclidian distances, in two dimensions by $d_{ij} = \sqrt{(x_i-x_j)^2+(y_i-y_j)^2}$ with $$p_i = (x_i,y_i)$$ and in three dimensions by $d_{ij} = \sqrt{(x_i-x_j)^2+(y_i-y_j)^2+(z_i-z_j)^2}$ with $$p_i = (x_i,y_i,z_i).$$ These distances represent the length of a straight line between two points $$i$$ and $$j$$.

For two points on a circle, the length of the arc of two points $$c_1 = (r,{\phi}_i)$$ and $$c_2 = (r, \phi_2)$$ is $s_{ij}=r~|\phi_1-\phi_2| = r ~\theta$ with $$\theta$$ the angle between $$\phi_1$$ and $$\phi_2$$ in radians. For very small values of $$\theta$$, we will have $$s_{ij} \approx d_{ij}$$.

For two points $$p_1 = (\lambda_1,\phi_1)$$ and $$p_2 = (\lambda_2,\phi_2)$$ on a sphere with radius $$r'$$, the great circle distance is the arc length between $$p_1$$ and $$p_2$$ on the circle that passes through $$p_1$$ and $$p_2$$ and has the center of the sphere as its center, and is given by $$s_{12} = r ~ \theta_{12}$$ with $\theta_{12} = \arccos(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \phi_2 \cdot \cos(|\lambda_1-\lambda_2|))$ the angle between $$p_1$$ and $$p_2$$, in radians.

Arc distances between two points on a spheroid are more complicated to compute. Details about the computation method used in package lwgeom (which, in turn, is used by package sf) are given in Karney (2013).

## 2.4 Bounded spaces

All the above assumes pure geometric computations in spaces where there are no unexpected obstructions. When we move through space on a daily basis, we typically find constraints e.g.

• when we walk through a building
• when we cycle to work
• or when we drive to a shop.

Distances, in such case, can be made up of a sequence of shortest (straight line or great circle) distances, but follow a more complex path than a straight line. Typical constraints come from road networks, or from the requirement for a certain habitat for movement (water for fish, forest for certain bird species).

## 2.5 Time

When we describe over which “space” a certain phenomenon is characterised, time forms an integral component: nothing exists forever. It is tempting to think that compared to geographical “space”, time is one-dimensional “linear”, and that is often the way we address time, e.g. in R where Date is represented by the number of days since 1970-01-01

(d = as.Date("1970-02-01"))
#>  "1970-02-01"
as.numeric(d)
#>  31

and POSIXt time by the number of seconds since the start of that date

(t = as.POSIXct("1970-01-02 00:00", tz = "UTC"))
#>  "1970-01-02 UTC"
as.numeric(t)
#>  86400

In practical cases however, we may be interested in how certain phenomena vary over the day, or over the year, in which case it may be more convenient to represent time as the tuple (year, day-of-year), or (day, time-of-day). When we study for instance traffic patterns, day of week plays a role, in which we may end up with (year, week-of-year, day-of-week, time-of-day) in order to quantify hourly, daily, weekly, and yearly signals. This decomposes time essentially in two or more components, with some of them having a cyclic character.

## 2.6 Exercises

• convert the $$(x,y)$$ points $$(10,2)$$, $$(-10,-2)$$, $$(10,-2)$$ and $$(0,10)$$ to polar coordinates
• convert the polar $$(r,\phi)$$ points $$(10,45^{\circ})$$, $$(0,100^{\circ})$$ and $$(5,359^{\circ})$$ to Cartesian coordinates
• assuming the Earth is a sphere with a radius of 6371 km, compute for $$(\lambda,\phi)$$ points the great circle distance between $$(10,10)$$ and $$(11,10)$$, between $$(10,80)$$ and $$(11,80)$$, between $$(10,10)$$ and $$(10,11)$$ and between $$(10,80)$$ and $$(10,81)$$ (units: degree). What are the distance units?

### References

Iliffe, Jonathan, and Roger Lott. 2008. Datums and Map Projections for Remote Sensing, Gis, and Surveying. Whittles Pub. CRC Press, Scotland, UK.

Karney, Charles FF. 2013. “Algorithms for Geodesics.” Journal of Geodesy 87 (1). Springer: 43–55. https://link.springer.com/content/pdf/10.1007/s00190-012-0578-z.pdf.