Whether you’re a mapping aficionado or just getting started in the world of spatial data, you’ve likely heard the word “projection.” Dealing with projections is key component of spatial analysis and mapping, and at times, it can be confusing. However, there’s no need to fear! In this article, I’ll discuss what projections are and why it’s important to be familiar with the concept, and I’ll explore how SAS makes it easy to handle projecting spatial data.
Spatial data is a representation of the earth, which is a sphere. However, we typically display spatial data by creating a map, which is a two-dimensional flat surface. Projecting spatial data refers to the mathematical process of converting spherical latitude and longitude coordinates to Cartesian coordinates that can be mapped on a flat surface. Projections are at the heart of cartography and map-making, and it’s important to be familiar with them if you work with any form of spatial data.
Imagine peeling an orange and then flattening the peel. The result won’t be a tidy rectangle and it won’t naturally lie flat. The same is true of spatial data. Plotting unprojected spatial data will often result in a distorted map, where angles, shapes, and sizes don’t look the way that you expect.
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
Projecting data, or the process of mathematically transforming the coordinates, allows you to minimize the distortion, by preserving area, distance, direction, or shape. For instance, this map of the United States looks much more “right” than the unprojected example above.
While it is not possible to eliminate all forms of distortion, there are hundreds and hundreds of different projections available, each designed to minimize distortion in certain geographic areas or dimensions. For example, there are projections that preserve direction at the expense of shape or preserve area at the expense of distance. Each one is suited to a particular use case.
Projections are also useful you are dealing with two or more data sets. If you are creating a multi-layer map using multiple spatial data sets, or if you are performing some sort of location analysis using multiple data sets, it is critical that both use the same projection. Using different projections can distort or misrepresent spatial relationships.
In SAS, you can use the GPROJECT procedure to project and reproject spatial data. The GPROJECT procedure lets you choose a projection to project unprojected data into, reproject already projected data into a new projection, and control the criteria of those projections.
The GPROJECT procedure supports three different kinds of projections: Albers’ equal-area, Lambert’s conformal, and gnomonic.
Albers’ equal area: Works well for both large and small areas and areas that extend east to west. It does not work well for maps that cross the equator. It also preserves the relative size of unit areas.
Lambert’s conformal: Works well for small areas and areas that extend east to west. It does not work well for maps that cross the equator. It also preserves the original shape of unit areas.
Gnomonic: Works well for both areas that extend east to west and for maps that cross the equator.
The GPROJECT procedure looks like this:
PROC GPROJECT DATA=input-mapdata-set
<OUT=output-map-data-set>
<option(s)>;
ID <id-variable(s)>;
RUN;
The DATA= and OUT= specify the input and output data sets, respectively. The ID statement specifies the variable that identifies unique unit areas. For example, if you were projecting a map of countries, this would be the column that identifies each country.
By default, the GPROJECT procedure takes unprojected data and projects in one of three previously discussed projections. It also expects data to be in degrees, and it expects longitude values to increase to the west, so that positive values are west of the prime meridian. The vast majority of spatial data nowadays uses degrees and longitude values increase to the east. We can add two additional arguments to the procedure to account for this: DEGREES and EASTLONG.
PROC GPROJECT DATA=input-mapdata-set
<OUT=output-map-data-set>
DEGREES
EASTLONG
<option(s)>;
ID <id-variable(s)>;
RUN;
Let’s take a look at some examples, using an unprojected map data set of the continental United States.
The default projection is the Albers’ equal area.
proc gproject data=us48unproj out=us48proj
degrees
eastlong;
id state;
run;
To project to a different projection, you can use the PROJECT= option. For instance, here’s what the Lambert’s conformal looks like:
proc gproject data=us48unproj out=us48proj
degrees
eastlong
project=lambert;
id state;
run;
Notice that this map appears more distorted. For a map of the size of the continental US, Albers’ is a better choice than Lambert’s.
Finally, the gnomonic projection looks like this:
proc gproject data=us48unproj out=us48proj
degrees
eastlong
project=gnomon;
id state;
run;
If the Lambert, Albers’, or Gnomonic projections don’t work for you, you can also specify any other projection that you want. Remember, there are hundreds of possible projections, each designed for a slightly different region or purpose. To do so, you can use the PROJECT=PROJ.4 argument in the PROC GPROJECT statement.
Proj.4 codes are space-delimited name-value pairs that define projection parameters. By default, this option will convert unprojected coordinates to a Mercator projection, but you can then use the TO= option to specify any other projection. You can also use the FROM= option to specify a starting projection if the input data is not unprojected. When using the PROJ.4 option, you do not need to use the DEGREES or EASTLONG options as they are enabled automatically.
You can also use EPSG and ESRI codes, which are a shortcut for Proj.4 strings. You can look up Proj.4 code, ESRI codes, and EPSG codes at SpatialReference.org.
For example, the following code projects the unprojected map data set into EPSG:3728, a projection designed specifically to minimize distortion for the northern portion of Ohio. This is just one example of the many possible projections that are available.
proc gproject data=us48unproj
out=us48proj
project=proj4
to="EPSG:3728";
id Name;
run;
Understanding projections is critical when working with spatial data. Luckily, SAS makes it easy to project projected data, and to reproject data that already been projected. In additional to three out-of-the box options, SAS also allows you to fully customize your mapping and spatial analysis with complete control over projecting your data. Stay tuned for future articles about other ways to improve your mapping with SAS!
Find more articles from SAS Global Enablement and Learning here.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.