Geographic Information Systems

Swonk uses the GDAL toolkit from gdal.org for most geographic data preparation and processing, and QGIS from qgis.org for preparing and printing maps.

Some common data formats used with geographic information systems.

GPX

GPX (the GPS Exchange Format) is a light-weight XML data format for the interchange of GPS data (waypoints, routes, and tracks) between applications and Web services on the Internet. Swonk uses it because it is clearly defined, easy to use, easy to extend, and supported by many applications.

This example shows the use of <extensions> to store extra data with each waypoint.

<?xml version="1.0" encoding="UTF-8"?>
<gpx
 version="1.1"
 creator="aerodrome.perl"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://www.topografix.com/GPX/1/1"
 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
 <metadata>
    <author>
        <name>Swonk Dog</name>
        <email id="swonk" domain="swonkdog.com"/>
        <link href="http://swonkdog.com/"/>
    </author>
    <link href="http://swonkdog.com/"/>
</metadata>
<wpt lat="-45.2116666666667" lon="169.373333333333">
<ele></ele>
<name>Alexandra</name>
<desc>NZLX Non-certificated</desc>
<src>CAA Aerodrome co-ordinates Updated 29 Jul 11</src>
<link>http://www.caa.govt.nz/aerodromes/aerodromes.htm</link>
<type>AD</type>
<extensions>
<aerodrome>
<aip>NZLX</aip>
<elev>752</elev>
<operator>Russell Anderson, Central Otago Flying Club, PO Box 159, Alexandra Tel/Fax (03) 448 7462 or (027) 237 9668</operator>
<date>2012-07-26</date>
<link>http://www.aip.net.nz/pdf/NZLX.pdf</link>
<frequencies>
<frequency desc="Flight information and Alexandra QNH - Christchurch Information" frequency="122.2"/>
<frequency desc="Unattended" frequency="119.1"/>
</frequencies>
<runways>
<runway designation="01/19" length="652" width="60" surface="Grass"/>
<runway designation="14/32" length="1200" width="60" surface="Grass"/>
<runway designation="14/32" length="1200" width="30" surface="Seal"/>
</runways>
</aerodrome>
</extensions>
</wpt>
<wpt lat="-37.0297222222222" lon="174.973333333333">
<ele></ele>
<name>Ardmore</name>
<desc>NZAR Non-certificated</desc>
<src>CAA Aerodrome co-ordinates Updated 29 Jul 11</src>
<link>http://www.caa.govt.nz/aerodromes/aerodromes.htm</link>
<type>AD</type>
<extensions>
<aerodrome>
<aip>NZAR</aip>
</aerodrome>
</extensions>
</wpt>
<wpt lat="-43.9033333333333" lon="171.796666666667">
<ele></ele>
<name>Ashburton</name>
<desc>NZAS Non-certificated</desc>
<src>CAA Aerodrome co-ordinates Updated 29 Jul 11</src>
<link>http://www.caa.govt.nz/aerodromes/aerodromes.htm</link>
<type>AD</type>
<extensions>
<aerodrome>
<aip>NZAS</aip>
<elev>298</elev>
<operator>
Ashburton Airport Authority, PO Box 94, Ashburton.
Tel (03) 308 5139 Fax (03) 308 1836
</operator>
<date>2003-09-04</date>
<link>http://www.aip.net.nz/pdf/NZAS.pdf</link>
<frequencies>
<frequency desc="Unattended" frequency="119.1"/>
<frequency desc="Christchurch Control" frequency="120.9"/>
</frequencies>
<runways>
<runway designation="09/24" length="1388" width="90" surface="Grass"/>
<runway designation="11/29" length="1024" width="90" surface="Grass"/>
<runway designation="02/20" length="897" width="60" surface="Grass"/>
<runway designation="16/34" length="1080" width="45" surface="Grass"/>
</runways>
</aerodrome>
</extensions>
</wpt>
</gpx>

GeoJSON

GeoJSON is a format for encoding a variety of geographic data structures. It is an extension of JSON, the universal format of web stuff these days. This means there are plenty of tools that support it, and many applications and frameworks use it.

The properties let you extend the format with additional information about a point. The example has a simple record, and some more complex.

{
   "features" : [
      {
         "properties" : {
            "runways" : [
               {
                  "width" : "60",
                  "length" : "686",
                  "designation" : "16/34",
                  "surface" : "Grass"
               }
            ],
            "name" : "Centre Bush",
            "aip_date" : "2003-09-03",
            "frequencies" : [
               {
                  "desc" : "Unattended",
                  "frequency" : "119.1"
               }
            ],
            "operator" : "T. Kean, PDC Limehills, Southland Tel/Fax (03) 236 050
3 ",
            "aip" : "NZCB"
         },
         "type" : "Feature",
         "geometry" : {
            "type" : "Point",
            "coordinates" : [
               168.311666666667,
               -46.04,
               77
            ]
         }
      },
      {
         "properties" : {
            "aip" : "NZHK",
            "operator" : "Hokitika Airport Ltd, PO Box 76, Hokitika 7842 Adminis
tration: Tel (03) 755 6318 Operations: Tel (03) 755 6318 or (03) 755 7820 Email:
 management@hokitikaairport.co.nz ",
            "frequencies" : [
               {
                  "desc" : "Christchurch Information",
                  "frequency" : "118.5"
               },
               {
                  "desc" : "Unattended",
                  "frequency" : "119.1"
               }
            ],
            "name" : "Hokitika",
            "aip_date" : "2013-02-13",
            "runways" : [
               {
                  "width" : "30",
                  "length" : "1152",
                  "designation" : "03/21",
                  "surface" : "Seal"
               },
               {
                  "surface" : "Seal",
                  "length" : "1176",
                  "designation" : "13/21",
                  "width" : "18"
               }
            ]
         },
         "type" : "Feature",
         "geometry" : {
            "coordinates" : [
               170.985277777778,
               -42.7136111111111,
               46
            ],
            "type" : "Point"
         }
      },
      {
         "properties" : {
            "name" : "Te Anau/Manapouri",
            "aip" : "NZMO"
         },
         "type" : "Feature",
         "geometry" : {
            "coordinates" : [
               167.65,
               -45.5330555555556
            ],
            "type" : "Point"
         }
      }
   ],
   "type" : "FeatureCollection"
}

Converting GPX to GeoJSON

A simple perl program to read a GPX file and output GeoJSON.

#! /usr/bin/perl -w
use strict;
use XML::Simple;
use JSON;

my $gpx = XMLin($ARGV[0]);
my $json = JSON->new;

my $features = ();

foreach my $wpt ( sort keys %{$gpx->{'wpt'}} ){
 my $feature->{'type'} = "Feature";
 my $coordinates = [ 0 + $gpx->{'wpt'}->{$wpt}->{'lon'},
                     0 + $gpx->{'wpt'}->{$wpt}->{'lat'},
                     0 + $gpx->{'wpt'}->{$wpt}->{'ele'} ];
 $feature->{'geometry'}->{'type'} = "Point";
 $feature->{'geometry'}->{'coordinates'} = $coordinates;
 $feature->{'properties'} = $gpx->{'wpt'}->{$wpt}->{'extensions'};
 $feature->{'properties'}->{'desc'} = $gpx->{'wpt'}->{$wpt}->{'desc'};
 $feature->{'properties'}->{'name'} = $wpt;
 push @{$features}, $feature;
}

my $featurecollection->{'type'} = "FeatureCollection";
$featurecollection->{'features'} = $features;
print $json->pretty->encode($featurecollection);

Converting Topo data for leaflet.js

LINZ publish the 1:250,000 and 1:50,000 Topo maps for New Zealand in digital format, free to use. To use this with the leaflet.js map display software in a web browser it has to be converted.

The 1:50,000 maps work at zoom levels 13 to 15 in leaflet.js. To convert the LINZ map tiles to the format leaflet can use.

Download the 1:50,000 maps from LINZ.
LINZ data
Make a virtual file of all the maps
gdalbuildvrt NZ50k.vrt `ls [A-Z]*.jpg`
Convert from NZGD2000 (EPSG:2193) to tiles for leaflet
gdal2tiles.py -s EPSG:2193 -z 13-15 -e -w leaflet -t "NZ Topo50k" NZ50k.vrt webtiles

The 1:250,000 maps work at zoom levels 10 to 12 in leaflet.js. To convert the LINZ map tiles to the format leaflet can use.

Download the 1:250,000 maps from LINZ.
LINZ data
Make a virtual file of all the maps
gdalbuildvrt NZ250k.vrt `ls [A-Z]*.jpg`
Convert from NZGD2000 (EPSG:2193) to tiles for leaflet
gdal2tiles.py -s EPSG:2193 -z 10-12 -e -w leaflet -t "NZ Topo250k" NZ250k.vrt webtiles