Spatial reference system: What is it?
Spatial reference system: What is it?
by Regina O. Obe and Leo S. Hsu, authors of PostGIS in Action, Second Edition
The topic of spatial reference systems (SRS) is one of the more abstruse in GIS to understand. This is mainly due to the loose way in which people use the term spatial reference system and secondly to its unglamorous nature compared to other areas of GIS. If GIS is Disneyland, think of SRS as the bookkeeping necessary to keep the Disneyland operation afloat. In this article, based on chapter 3 of PostGiS in Action, Second Edition, the authors explain the components of a spatial reference system.
Take any two paper maps from your collection having one point in common and overlay one atop of the other using as a reference the point they have in common. Both maps represent the whole or a part of Earth, but unless you're extremely lucky, the two maps have no relation to each other. Travel five centimeters right on one map and you can end up on another street. Five centimeters on the other map could put you in another continent. Your two maps don't overlay well because they don't have the same spatial reference system. The main reason for the GIS data consumer to become acquainted with the spatial reference system (SRS) is to bring in data from disparate sources in different SRSs and be able to overlay one atop another. Many standards exist to make this task easy without having to delve into the nuances of SRS. The most common one is the European Petroleum Survey Group (EPSG) numbering system. Take any two sources of data with the same EPSG number, and they'll overlay perfectly. EPSG is a fairly recent SRS numbering system. If you uncover data from a few decades ago, you'll not find an EPSG number. You'll have no choice but to delve into the constituent pieces that form a spatial reference system. So what is a spatial reference system?
From outer space, our good Earth appears spherical, often described as a blue marble. To anyone living on its surface, nothing can be further from the truth. The slick glossy surface seen from outer space actually comprises mountain ranges, deep canyons, and ocean trenches. The surface of the Earth with all its nooks and crannies resembles a slightly charred English muffin much more than a lustrous marble. Even the idea of the Earth being spherical isn't accurate, because the equator bulges out, making a trip around the equator about 42.72 km longer than a trip on one of the meridians.
In light of the fact that we have a deeply pitted and somewhat squashed orange under our feet, what are we going to do? With our new GPS toys, we could conceivably represent every square meter on Earth as a satellite map, assigning it a spherical 3D coordinate, and be done with it. This is the approach taken by many digital elevation models. Though this brute force computation method could certainly become the standard one day, we still need a simpler and more computationally cost-effective model for most use cases.
A model, by definition, is a simplified representation of reality. All models are inherently flawed in some way or other. In exchange for their shortcomings, they provide us with a more cost-effective way of doing things. A key factor in selecting a model is finding one that balances cost of computation (in speed and complexity) with observed failure. Some models may fail in ways you don't care about because you'll never exercise their points of failure. Until the time when we can afford to carry around portable holograms of the Earth, we need several cheap models.
A starting point for any 3D model is the choice of definition of the surface of the Earth. Do you use the mean sea level? An average of the peaks and valleys?
Quite a few options are available, but they all suffer from a common problem; you can't really go out and set up a standard of measurement that's applicable around the entire world. Take the notion of sea level, for instance. Someone in Cardiff, England, can say that their house is 50 meters above the sea during low tide and use this as a reference against their neighbor's house. Suppose a fellow in Pago Pago has a small house and measures his house also to be 50 meters above sea level. What can we say about the relative elevation of the two houses to each other? Not much.
Sea level varies from place to place relative to the center of the Earth. And even the notion of center of the Earth is ambiguous. Along comes Gauss, who, with the help of a crude pendulum, determined in the early nineteenth century that the surface of the Earth should be defined using gravitational measurements. Though he lacked a digital gravity meter, we can picture the idea of going around the surface of the globe with such a device and measuring out a surface where gravity was constant—an equipotential surface . This is the basic idea behind the geoid. We take gravity readings of various sea levels to come up with a consensus and then use this constant gravitational force to map out an equigravitational surface around the globe. Many consider the geoid to be the true figure of the Earth.
Surprisingly, the geoid is far from spherical; see figure 1. You must not forget that the core of the Earth isn't homogenous. Mass is distributed unevenly, giving rise to bulges and craters that rival those found on the lunar surface. The advent of the geoid didn't simplify matters. On the contrary, it created even more headaches. The true surface of the Earth is now even less marble like, even a slightly squashed orange is no longer a faithful representation.
Figure 1 A geoid seen from different angles
Although the geoid is rarely talked about in GIS, it's the foundation of both planar and geodetic models. In the next section, we'll discuss the more commonly used ellipsoids, which are simplifications of the geoid and are generally good enough for most geographic modeling needs.
Since ancient times, the point for modeling the Earth has always been an ellipsoid of some sort. An ellipsoid is merely a 3D ellipse.
|An ellipsoid is composed of three radii: a and b are equatorial radii (along the X and Y axes), and c is the polar radius (along the Z axis). In geodesy only two axes are considered: semi major and semi minor. Spheroids are a subclass of ellipsoids where a = b. A spheroid where c > a is called an oblate spheroid. By the way, if a = b = c, you have a perfect sphere.|
By varying the X/Y and polar axes on the ellipsoid, you can model the equatorial bulge. At some point in the history of cartography, people must have postulated one ellipsoid that could be used all around the world—a reference ellipsoid. Everyone can locate each other by finding their placement on the reference ellipsoid. The discovery of the geoid shattered the idea of using a single ellipsoid. One look at the geoid will show why. The geoid paints a picture where the local curvature varies from place to place. An ellipsoid that fits the curvature for one spot may be awfully inaccurate for another; see figure 2.
Figure 2 The geoid and the ellipsoid seen together
Now, instead of one ellipsoid to rule us all, people on different continents wanted their own to better reflect the regional curvature of the Earth. This gave rise to the multitude of ellipsoids we have today. This was all well and good when we didn't care about people far away from us. This disparate use of different systems became more of an issue with time because of the need for scientists and governments to collaborate and the rise of oil surveying and aviation. Fortunately, today the world is settling on the World Geodetic System (WGS 84) and GRS 80 ellipsoids, with WGS 84 becoming the standard of choice. WGS 84 is what all GPS systems are based on. To call WGS 84 simply an ellipsoid isn't quite accurate. The WGS 84 GPS systems we use have a geoid component as well. The present WGS 84 system uses the 1996 Earth Gravitational Model (EGM96) geoid and is the best-fitting ellipsoid to the geoid model for the selected survey points in the set.
Common ellipsoids used today are:
- GRS 80
- WGS 84 (more common nowadays and the standard for GPS data)
The 80 and 84 stand for 1980 and 1984, when the standards came out, and they're very similar.
Many ellipsoids have been used over the years, and some continue to be used because of their better fit for a particular region. All historical data is still referenced against other ellipsoids. Table 1 shows a sampling of some common ellipsoids and their various ellipsoidal parameters.
Table 1 Common ellipsoids
|Ellipsoid||Equatorial radius (m)||Polar radius (m)||Inverse flattening||Where used|
|Clarke 1866||6,378,206.4||6,356,583.8||294.9786982||North America|
|NAD 27||6,378,206.4||6,356,583.8||294.978698208||North America|
|GRS 80||6,378,137||6,356,752.3141||298.257222101||North America|
|WGS 84||6,378,137||6,356,752.3142||298.257223563||GPS (World)|
|IERS 1989||6,378,136||6,356,751.302||298.257||Time (World)|
One common old ellipsoid is the Clarke 1866 (this is so close to what is called the NAD 27 ellipsoid that they're synonymous for most purposes). So even though these old data points are measured in longitude and latitude, they aren't the same longitude and latitude we use today, and they also use different grounding points. They're shifted.
|Lon lat which ellipsoid?|
|This is why it's important to not just call things lon lat. You can have NAD 27 lon lat, NAD 80 lon lat, and WGS 84 lon lat, and each will be subtly different. As a rule, when people nowadays refer to lon lat, they mean WGS 84 datum and WGS 84 spheroid in lon lat units. NAD 27 is the most different because it was done a long time ago. (Note that datum is the shift of a spheroid.)|
In the next section, we'll discuss the concept of datums and how they fit into the overall picture of the spatial reference system.
The ellipsoid alone only models the overall shape of the Earth. After picking out an ellipsoid, you need to anchor it if you ever need to use it for real-world navigation. Every ellipsoid that's not a perfect sphere has two poles. This is where the axis arrives at the surface. These ellipsoid poles must permanently be tagged to actual points on Earth. This is where the datum comes into play. Even if two reference systems use the same ellipsoid, they could still have different anchors, or datum, on Earth.
The simplest example of a datum is to look at the tilt between the geographic pole and the magnetic pole. In both models, the Earth has the same spherical shape, but one is anchored at the North Pole and the other is somewhere in Canada.
To anchor an ellipsoid to a point on Earth, you need two types of datum: a horizontal datum to specify where on the plane of the Earth to pin down the ellipsoid and a vertical datum to specify the height. For example, the North American Datum of 1927 (NAD 27) is anchored at Meades Ranch in Kansas because it's close to the geographical centroid of the United States. NAD 27 is both a horizontal and a vertical datum. Here are some commonly used datums:
- NAD 83 (North American 1983, which is often accompanied with the GRS 80 spheroid)
- NAD 27 (North American 1927, which is generally accompanied by the Clarke 1866/NAD 27 ellipsoid)
- European Datum 1950
- Australian Geodetic System 1984
Coordinate reference system
Many people confuse coordinate reference systems (CRS) with spatial reference systems. A CRS is only a necessary ingredient that goes into the making of a SRS and not the SRS itself. To identify a point on our reference ellipsoid, you need a coordinate system. For use on a reference ellipsoid, the most popular CRS is the geographical coordinate system (also known as geodetic coordinate system or simply as lon lat). You're already intimately familiar with this coordinate system.
You find the two poles on an ellipsoid and draw longitude (meridian) lines from pole to pole. You then find the equator of your ellipsoid and start drawing latitude lines. Keep in mind that even though you've only seen geographical coordinate systems used on a globe, the concept applies to any reference ellipsoid. For that matter, it applies to anything resembling an ellipsoid. For instance, a watermelon has nice longitudinal bands on its surface.
Let's summarize what we discussed thus far about spatial reference systems:
- We start by modeling the Earth using some variant of a reference ellipsoid, which should be the ellipsoid that deviates least from the geoid for the regions on Earth we care about.
- We use a datum to pin the ellipsoid to an actual place on Earth, and we assign a coordinate reference system to the ellipsoid so we can identify every point on the surface. For example, the zero milestone in Washington, D.C. is W -77.03655 and N 38.8951 (in spatial x: -77.03655, y: 38.8951) on a WGS 84 ellipsoid using WGS 84 datum, but on a NAD 27 datum, Clarke 1866 ellipsoid, this would be W -77.03685, N 38.8950.
We can quit at this point, because we have all the elements necessary to tag every spot on Earth. We can even develop transformation algorithms to convert coordinates based on one ellipsoid in relation to another. Many sources of geographic data do stop at this point and don't go on to the next step, projections. We term this data unprojected data. All data served up in the form of latitudes and longitudes is unprojected. You can do quite a bit with unprojected data, such as by using the great circle distance formula; you can get distances between any two points. You can also use it to navigate to and from any points on Earth.
Projection has distortion built in. The concept of projection generally refers to taking an ellipsoidal Earth and squashing it on a flat surface. Because geodetic and 3D globes are ellipsoidal, they by definition don't refer to a flat surface and are referred to as unprojected. In the next section, we'll briefly go over the different kinds of projections and why we have them.
Different kinds of projections
So why do we have 2D projections of our ellipsoid or geoid? The obvious reason is eminently practical: you can't carry a huge globe everywhere you go. Less obvious but more relevant is the mathematical and visual simplicity that comes with planar (Euclidean) geometry.
As we have repeated many times, PostGIS works for the most part on a Cartesian plane, and most of the powerful functions assume a Cartesian model. Your brain and the quite different brain of PostGIS can perform area and distance calculations quickly on a Cartesian plane. On a plane, the area of a square is its side squared. Distance is nothing more than applying the Pythagorean theorem. A planar model fits nicely on a piece of paper. Calculating the area of a square directly on the surface of an ellipsoid becomes quite a challenge, not the least aspect of which is deciding what constitutes a square on an ellipsoid in the first place.
|PostGIS 1.5 supports geodetic data; 2.1 improves it|
|PostGIS 1.5 introduced support for geodetic data using the new datatype geography, similar in concept to SQL Server 2008 geography types. All spatial functions work for geometry data, with only a few functions and operators also for geography, such as distance functions. In PostGIS 2.1, various enhancements were made to improve speed yielding in many case 10 fold or higher speed in proximity checks from 1.5 geography support. PostGIS 2.1 also introduced new geodetic aware functions such as ST_Segmentize.|
How exactly you'd squash an ellipsoidal Earth on a flat surface is controlled by several classes of rules we'll loosely refer to as the classes of Cartesian coordinate systems. Each class of rules tries to optimize for a set of features; each specific instance of a coordinate system is bounded by a particular region on Earth, and each uses a particular unit (usually meters or feet). Needless to say, you try to balance four conflicting features. The importance you place on each will dictate the choice of coordinate system and eventually of the spatial reference system(s):
- Shape—How accurately it represents angles
- Direction—Is north really north?
- Range of area supported
The general tradeoff is that, if you want to span a large area, you have to give up measurement accuracy or deal with the pain of maintaining multiple spatial reference systems and some mechanism to shift among them. The larger your area, the less accurate and potentially grossly unusable your measurements will be. If you try to optimize for shape and to cover a large range, your measurements may be off, perhaps way off.
There are a few flavors of projections (squashing) you can do to optimize for different things. These are listed here:
- Cylindrical projections—Imagine a piece of paper rolled around the globe and imprinting the globe on its surface. Then you unroll it to make it flat. The most common of these is the Mercator projection, which has the bottom of the rolled cylinder parallel to the equator. This results in great distortion at the polar regions, whereas measurement accuracy is best the closer you are to the equator, because there the approximation of flat is most accurate.
- Conic projections—These are sort of like the cylindrical projection except you wrap a cone around the globe, take the imprint of the globe on the cone, and then roll it out.
- Azimuthal projections—You project a spherical surface onto a plane tangent to the spheroid.
Within these three kinds of projections you must also consider the orientation of the paper you roll around the globe. These are the possibilities:
- Oblique—Neither parallel nor perpendicular to the equator; some other angle
- Equatorial—Perpendicular to the plane of the equator
- Transverse—Parallel along the equator
Combinations of these categories form the main classes of planar coordinate systems:
- Lambert Azimuthal Equal Area (LAEA)—These are reasonably good for measurement and can cover some large areas but are not great for shape. The one we like most when dealing with United States data and when we're concerned with somewhat decent measurement is US National Atlas (EPSG:2163). This is a meter-based spatial reference system. These are in general not good at maintaining direction or angle.
- Universal Trans Mercator (UTM)—These are generally good for maintaining measurement and shape and direction but only span six-degree longitudinal strips. If you need to cover the whole globe and you use one of these, you'll have to maintain about 60 spatial ref IDs. You cannot use them for the Polar Regions.
- Mercator—These are good for maintaining shape and direction and span the globe, but they're not good for measurement, and they make the regions near the poles look huge. The measurements you get from them are nothing less than cartoonish, depending on where you are. The most common Mercator projections in use are variants of World Mercator (SRID:3395) or Spherical Mercator (aka Google Mercator (SRID:900913), which is now an EPSG standard with EPSG:3857 (but for a time was EPSG:3785). This last one is fairly new, so you may not find it in your spatial_ref_sys table if your PostGIS version is older. They're common favorites for web map display because you only have to maintain one SRID, and they look good to most people.
- National Grid Systems—These are generally a variant of UTM or LAEA but are used to define a restricted region such as a country. As mentioned, US National Atlas (SRID:2163, US National Atlas Equal Area) is common for the United States. These are generally decent for measurement (but not super accurate), don't always maintain good shape, but cover a fair amount of area, which is in many cases the national area you care about.
- State Plane—These are U.S. spatial reference systems. They're usually designed for a specific state, and most are derived from UTM. Generally there are two for a state—one measured in meters and one measured in feet—although some larger states have four or more. Optimal for measurement, these are commonly used by state/city land surveyors but, as we said, they can deal with only a single state.
- Geodetic—PostGIS can store WGS 84 lon lat (4326) as a geometry data type, but more often than not you'll want to transform it to another spatial reference system or store it in the geography data type for it to be usable. You can sometimes get away with using it as a geometry data type for small distances along the same longitude and when two things intersect, but keep in mind that when you use it, PostGIS is really projecting it. It squashes it on a flat surface, treating longitude as X and latitude as Y, so even though it looks unprojected, in reality it's projected and in a mostly unusable way. The colloquial name for this kind of projection is Plate Carrée.
In this article, we explained what a spatial reference system is and what are the elements it consists of. You saw how they evolved and how different categories of projections form the basis for various planar coordinate systems. To learn more about PostGIS, an open source spatial database extender for PostgreSQL, please check out PostGIS in Action.
Here are some other Manning titles you might be interested in:
SQL Server MVP Deep DivesPaul Nielsen, Kalen Delaney, Greg Low, Adam Machanic, Paul S. Randal, and Kimberly L. Tripp
SQL Server DMVs in ActionIan Stirk
SQL Server 2008 Administration in ActionRod Colledge