Database Reference
In-Depth Information
Working with GPS data
In this recipe, you will work with GPS data. This kind of data is typically saved in a
.gpx
file.Youwillimportabunchof.
gpx
filestoPostGISfromRunKeeper,apopular
social network for runners.
If you have an account on RunKeeper, you can export your
.gpx
files and process
thembyfollowingtheinstructionsinthisrecipe.Otherwise,youcanusetheRunKeep-
er
.gpx
filesincludedinthe
runkeeper-gpx.zip
file,locatedinthe
chp03
direct-
ory included in the code bundle available with this topic.
Youwillfirstcreatea
bash
scriptforimportingthe
.gpx
filestoaPostGIStable,using
ogr2ogr
. After the import is completed, you will try to write a couple of SQL quer-
iesandtestsomeveryusefulfunctions,suchas
ST_MakeLine
togeneratepolylines
from point geometries,
ST_Length
to compute distance, and
ST_Intersects
to
perform a spatial join operation.
Getting ready
Extract the
data/chp03/runkeeper-gpx.zip
file to
working/chp03/run-
keeper_gpx
.Incaseyouhaven'tbeenthrough
Chapter1
,
Moving Data In and Out
of PostGIS
, be sure to have the
countries
dataset in the PostGIS database.
How to do it...
First,besureoftheformatofthe
.gpx
filesthatyouneedtoimporttoPostGIS.Open
oneofthemandcheckthefilestructure—eachfilemustbeintheXMLformatcom-
posedofjustone
<trk>
elementthatcontainsjustone
<trkseg>
elementthatcon-
tainsmany
<trkpt>
elements(thepointsstoredfromtherunner'sGPSdevice).Im-
port these points to a PostGIS
Point
table.
1. Createanewschemanamed
chp03
tostorethedataforalloftherecipesin
this chapter using the following command:
postgis_cookbook=# create schema chp03;