Skip to content

Convert coordinates between spatial reference systems (SRS)

November 22, 2013

When calibrating the prediction model (species distribution model) in Maxent, both types of input spatial data, the samples/localities (the dependent, response variable) and the environment layers (independent, explanatory, predictor variables), have to be described using the very same spatial reference system (SRS). For spatial data with national coverage in Norway, it is common to use the Universal Transverse Mercator (UTM) of zone 33N and WGS84 datum (epsg:32633). The environmental layers provided for the BIO4115/BIO9115 master/PhD course at the Natural History Museum of the University of Oslo are provided in the UTM33N format.

Artskart provides species occurrence locality coordinates in both WGS84 UTM 33N (epsg:32633) and the standard WGS84 decimal degrees (epsg:4326) (often called “WGS84 latlong”).

ScientificName Longitude Latitude UTMsone UTMost UTMnord
Archillea milefolium 9.589478 62.597128 33 222412 6952352
Archillea milefolium 6.691447 62.545205 33 73481 6962430

 

The GBIF portal provides species occurrence locality coordinates as standard WGS84 decimal degrees (epsg:4326). The GBIF portal is a global portal and does not provide respective national coordinate systems. Few other countries than Norway use the UTM33N SRS. If you want to use species occurrence data downloaded from the GBIF portal together with environmental raster layers in UTM33N (or other SRSs) you will need to convert either the occurrence coordinates or the raster layers to a common SRS.

GDAL/OGR library software

The Geospatial Data Abstraction Library (GDAL/OGR, http://www.gdal.org/) is a translator library for geospatial raster and vector data formats. The GDAL/OGR library is available for Windows, MacOsX, Linux and other UNIX-like operating systems. On a MacOsX system you may install the frameworks from KyngChaos (http://www.kyngchaos.com/software/frameworks#gdal_complete). On a Windows system you may want to install the FWTools that includes GDAL/OGR (http://fwtools.maptools.org/).

Convert GBIF species occurrence data to UTM33N using GDAL

The GDAL/OGR library can be used from the command line or from a GIS. I will describe using GDAL from the command line. On a Windows system with the FWTools open the “FWTools shell” in a DOS window (figure 1). On UNIX-like systems (such as MacOsX or Linux) open a standard terminal window (figure 2) (Applications >> Utilities >> Terminal).

Copy your coordinate tuple to a plain text file with each coordinate tuple on a new line and coordinates separated by a space. GDAL expects the coordinate tuple to be ordered as longitude, latitude (x, y) (easting, northing). So remember to put the x-coordinate (longitude or easting) in the first column, and the y-coordinate (latitude, northing) in the second column. Then use gdaltransform to convert your coordinate tuples.

Figure 1: Using GDAL with FWTools on a Windows system.

Figure 1: Using GDAL with FWTools on a Windows system.

Figure 2: Using GDAL in a terminal window on a MacOsX system.

Figure 2: Using GDAL in a terminal window on a MacOsX system.

Convert the coordinate tuple from decimal degrees to UTM33N

WGS84_DD.txt (longitude latitude coordinates in a text file):
9.327703 58.872074
10.55039 59.95672

$ gdaltransform -s_srs EPSG:4326 -t_srs EPSG:32633 < “WGS84_DD.txt”
173154.636743861 6539674.3145872 0
251611.627711431 6654946.66561605 0

This GDAL output can be understood/interpreted as:
UTM 33 173154mE 6539674mN
UTM 33 251611mE 6654946mN

 

To save the gdaltransform output results directly into a new text-file, you may redirect the standard output using a “>” in the command:

$ gdaltransform -s_srs EPSG:4326 -t_srs EPSG:32633 < “WGS84_DD.txt” > “UTM33N.txt”

Retrieve the UTM coordinates from text file named UTM33N.txt (easting northing).

 

New line as CR and/or LF

Notice that gdaltransform originates from unix-like systems and expects to find unix-type new line given as LF (“line feed”, “\n”, “0x0A”). MacOsX systems CR (“carriage return”, “\r”, “0x0D”) to separate new lines; while Windows systems use both CR + LR (“\r\n”, “0x0D0A”). If you have your coordinates in a MacOsX formatted text-file, you will need to replace the line endings from CR to LF. Here is an example of how to do this using perl (from the command line).

perl -pi -e ‘s/\r/\n/g’ WGS84_dd.txt # Convert CR (Mac) to LF (unix)

The “-p” flag makes perl operate on each line of the input text-file; “-i” flag makes perl operate directly on the file itself (instead of the need of creating a new file); -e allow a complete one-liner perl command to be run on the command line (not in a script); ‘s/\r/\n/g’ is a regular expression where “s” is for substitute or replace and “g” is for global replace of all matches. Inside the slashes /from-pattern-to-be-substituted/to-pattern-to-be-inserted/.

perl -pi -e ‘s/\r|\r?\n/\n/g’ WGS84_dd.txt # Convert both CR (Mac) and/or CR+LF (Win) to LF (unix)

 

Online coordinate conversion tools

Coordinates can also be converted using an online conversion tool. Most of these provide only the conversion of one single coordinate tuple at a time.

The online coordinate conversion tool from MyGeodata (http://cs2cs.mygeodata.eu/) is the most useful online converter I could find. Keep the default input coordinate system (WGS84 (SRID=4326)) and give the output coordinate system as “EPSG:32633”. The tool accepts a list of input coordinate tuples in a wide variety of formats (including reverse latitude-longitude (y-x) ordering by ticking the bottom box: “Switch XY”).

The World Coordinate Converter (http://twcc.free.fr/) provides a nice interface for converting one coordinate tuple at a time. You may click in the map or type in the coordinate tuple to be converted. Source SRS: “GPS (WGS84) (deg)”. UTM33N is not included in the list of target SRS by default and need to added: Click on the green plus sign button at the bottom right, and type “EPSG:32633” into box number 2.

The conversion tool from EarthPoint (single point, batch conversion, http://www.earthpoint.us) provides an option for batch conversion of multiple coordinate tuples in a spreadsheet – HOWEVER – you will need to register for a user account for this tool to take more than 5 coordinate tuples at a time…

 

These guidelines were prepared for the BIO4115/BIO9115 master/PhD course at the Natural History Museum of the University of Oslo written by Dag Endresen (GBIF-Norway) on 22nd November 2013.

No comments yet

Leave a comment