Encode GIS coordinates of locations

Basics of GIS locations

Any place on the surface of the earth can be located in terms of three coordinates: latitude, longitude and elevation (height above sea level). In most of our work, we are only concerned with the first two, latitude and longitude, because we don’t (currently) envisage any rendering or data processing that would make use of elevation.
Traditionally, latitude and longitude were expressed in degrees, like this:
51°30'49.25"N
 0° 5'58.42"W
These are the coordinates of St. Paul’s Cathedral. Notice that the longitude coordinate starts with zero; this is because it is very close to Greenwich, through which the zero line of longitude, the prime meridian, runs.
In modern GIS systems, latitude and longitude are expressed in decimal numbers, which look like this:
51.513557
-0.098369
You can see that these are the same basic numbers—latitude measured as distance north or south from the equator, longitude measured as distance east or west from the prime meridian—but they’re expressed in a form which enables computers to do math with them more easily.
Coordinates like this are usually comma-separated, like this:
51.513557,-0.098369
and if elevation is also included, it comes last, like this:
51.513557,-0.098369,0
However, there is a slight wrinkle here: if you use Google systems such as Google Maps or Google Earth, the coordinates are stored in Google’s XML file format called KML, and inside that file, the order of latitude and longitude is reversed:
<coordinates xmlns="http://www.opengis.net/kml/2.2">-0.098369,51.513557,0</coordinates>
No-one seems to know why Google (or the company they purchased who invented KML) chose to do things this way.

How to find the GIS location of a single point

In our work, we usually use Google Earth to find the geolocation of places. Here’s a screenshot of Google Earth showing St. Paul’s Cathedral:

The first thing we want to do is to make sure that Google Earth will use decimal coordinates instead of the traditional degrees; that will make our job easier. Click on Tools / Options, and make the selection shown here.

To find the coordinates of this place, the first thing we need to do is to create a Placemark for it. Click on the Placemark button (), or on Add / Placemark, and you’ll see a pushpin appear on the map.

Place the pushpin where you want it to go, and you’ll see that the lat/long coordinates appear in the dialog box, and also at the bottom of the map image. You can copy the latitude and longitude numbers (without their degree symbol) out of the dialog box, and put them in the TEI file for the location.
Where do you put them in your TEI file? If you open up the file for St. Paul’s Cathedral, STPA2.xml, you’ll see that it has a <div> in the body that looks like this:
<div type="placeInfo">
  
<head>St. Paul’s Cathedral</head>
  
<listPlace>
    
<place>
      
<placeName>St. Paul’s Cathedral</placeName>
      
<location>
        
<geo><!-- Geographical coordinates will go here when available. --> </geo>
      
</location>
    
</place>
  
</listPlace>
</div>
The comment of course tells you where the coordinates should go, like this:
<geo>51.513557,-0.098369</geo>
It is vital that you DO NOT put a space after the comma. You’ll see why this is important below.

How to find the outline of a larger place

For small locations such as individual houses, it is often sufficient to use a single point to identify the location on the map. However, for larger buildings, streets and other types of location, we want to provide more detail. Essentially, we want to draw an outline around the object. We’ll do that now, for St. Paul’s.
An outline is basically just a list of point coordinates, separated by spaces. So a triangle around the dome of St. Paul’s might be specified like this:
51.51391527182066,-0.09834042321448383
51.513532825929,-0.09863498228599121
51.51352062534084,-0.09800392197454352
51.51391527182066,-0.09834042321448383
You can see that there are four separate lat-long coordinates, separated by spaces (showing up as linebreaks). The first one is identical to the last one. This is how we know that this is a shape or outline of a place, rather than a path or line.
So how do we create shapes in Google Earth, and how do we get their coordinates out?
First, we have to create a polygon, in the same sort of way that we previously created a placemark. Click on the Add Polygon tool (), or on Add / Polygon. Now click on a point on the map; then on the next point; then the next; and finally click back on the first point to complete the polygon:

Now, Google Earth does not helpfully provide you with the output coordinates when you create a polygon. We have to go through rather a convoluted process to get them. First, give your new polygon a name in the dialog box, and press OK to save it. You should see it appear in your places list, either under My Places or Temporary Places—it doesn’t matter which:

Now we’re going to save this place as a KML file. Right-click on the place you created, and choose Save Place As.... In the dialog box that pops up, make sure you choose "Kml (*.kml)" as the file type, not kmz. Then give your file a name and save it. This file is an XML file in Keyhole Markup Language format. Open this file in Oxygen.
Now if you look at the file, you’ll see its <coordinates> element, with the reversed longitude-then-latitude coordinates, and with the elevation as a third item. We need to convert these coordinates into regular lat-long pairs, with each pair separated by a comma, and the pairs separated by spaces, to put into our <geo> element. We could do this manually by copying and pasting, but that’s a bit tedious and error-prone. Here’s a little trick to help us.
You may have seen, and may even have used, the XPath box at the top left of your Oxygen window. This is a box in which you can enter an XPath expression, then press Return, and have the XPath run on your document to get you some results. For instance, with a TEI file, if you put //name in the XPath box and press return, Oxygen will list all the <name> elements in your document.
However, this text box is not very big, and we’ll need to enter a long XPath expression to do our work, so we’re going to use the XPath Builder window to do that. In Oxygen, click on Window / Show View / XPath/XQuery Builder. This will open a new window in Oxygen, on the right:

Make sure you select "XPath 2.0" in the top left drop-down, and make sure your KML file is the active document on the left. Now you’ll need to copy/paste the following XPath expression into the window, as you see it in the screenshot above:
string-join(for $c in //coordinates[1]/tokenize(normalize-space(.), '\s') return concat(tokenize($c, ',')[2], ',', tokenize($c, ',')[1]), ' ')
Now press the red triangle button immediately above the expression to run the XPath against the document. You should see a result appear at the bottom of the Oxygen window:

Now right-click on the result, and choose Show message. In the popup box, you can select and copy the reorganized geo coordinates, and then paste them into the <geo> element in the TEI file.

Easy, right? Here’s a more realistic example, representing the real outline of St. Paul’s:

<geo>51.513412487853,-0.09956518738909835 51.51342490411496,-0.09907352353264927 51.51337515331529,-0.09854794927132422 51.51332657086279,-0.09826662956696325 51.5134050406195,-0.09797451920697323 51.51361478678208,-0.09734579556372211 51.51382896340971,-0.09725399622560914 51.51403178212471,-0.09744927183520874 51.51410842163026,-0.09813277781772305 51.51419510959087,-0.09839870581199643 51.51408838446699,-0.09868742601890415 51.51398706060057,-0.09911584437698109 51.51393048079962,-0.09963724273184871 51.513412487853,-0.09956518738909835</geo>

How to define paths

If you’re dealing with a location which is very long and thin, such as a street, you could define it as a very long, thin polygon, but that’s a lot of unnecessary detail. It’s probably better to define it as a path. You can do that in exactly the same way you create a polygon, but using Add / Path or the Path button (). Paths differ from polygons only in that their final coordinate is not the same as their initial coordinate.

Cite this page

MLA citation

The University of Victoria Humanities Computing and Media Centre HCMC. Encode GIS coordinates of locations. The Map of Early Modern London, edited by Janelle Jenstad, U of Victoria, 20 Jun. 2018, mapoflondon.uvic.ca/geo_deprecated.htm.

Chicago citation

The University of Victoria Humanities Computing and Media Centre HCMC. Encode GIS coordinates of locations. The Map of Early Modern London. Ed. Janelle Jenstad. Victoria: University of Victoria. Accessed June 20, 2018. http://mapoflondon.uvic.ca/geo_deprecated.htm.

APA citation

The University of Victoria Humanities Computing and Media Centre HCMC. 2018. Encode GIS coordinates of locations. In J. Jenstad (Ed), The Map of Early Modern London. Victoria: University of Victoria. Retrieved from http://mapoflondon.uvic.ca/geo_deprecated.htm.

RIS file (for RefMan, EndNote etc.)

Provider: University of Victoria
Database: The Map of Early Modern London
Content: text/plain; charset="utf-8"

TY  - ELEC
A1  - The University of Victoria Humanities Computing and Media Centre HCMC
ED  - Jenstad, Janelle
T1  - Encode GIS coordinates of locations
T2  - The Map of Early Modern London
PY  - 2018
DA  - 2018/06/20
CY  - Victoria
PB  - University of Victoria
LA  - English
UR  - http://mapoflondon.uvic.ca/geo_deprecated.htm
UR  - http://mapoflondon.uvic.ca/xml/standalone/geo_deprecated.xml
ER  - 

RefWorks

RT Web Page
SR Electronic(1)
A1 The University of Victoria Humanities Computing and Media Centre HCMC
A6 Jenstad, Janelle
T1 Encode GIS coordinates of locations
T2 The Map of Early Modern London
WP 2018
FD 2018/06/20
RD 2018/06/20
PP Victoria
PB University of Victoria
LA English
OL English
LK http://mapoflondon.uvic.ca/geo_deprecated.htm

TEI citation

<bibl type="mla"><author><name ref="#HCMC1" type="org">The University of Victoria Humanities Computing and Media Centre <reg>HCMC</reg></name></author>. <title level="a">Encode GIS coordinates of locations</title>. <title level="m">The Map of Early Modern London</title>, edited by <editor><name ref="#JENS1"><forename>Janelle</forename> <surname>Jenstad</surname></name></editor>, <publisher>U of Victoria</publisher>, <date when="2018-06-20">20 Jun. 2018</date>, <ref target="http://mapoflondon.uvic.ca/geo_deprecated.htm">mapoflondon.uvic.ca/geo_deprecated.htm</ref>.</bibl>

Personography

Organizations