Skip to Content
Mapping Hacks
book

Mapping Hacks

by Schuyler Erle, Rich Gibson, Jo Walsh
June 2005
Intermediate to advanced
568 pages
24h 7m
English
O'Reilly Media, Inc.
Content preview from Mapping Hacks
Turn Your Tracklogs into ESRI Shapefiles #71
Chapter 6, Mapping on Your Desktop
|
339
HACK
chomp;
my ($type, $date, $lat, $long) = split /\t/, $_, 4;
my $now = eval { Time::Piece->strptime($date, TIME_FORMAT) };
next unless $now;
if (@vertices) {
add_shape( ) if $now - $previous > TIME_THRESHOLD * 60;
}
push @vertices, [$long, $lat]; # note, long before lat!
$previous = $now;
}
add_shape( );
$shp->save($out);
In its broadest outline, track2shp.pl reads each line from the given tracklog,
splitting the line up into its component fields and throwing away the lines it
can’t parse. The script builds up a set of vertices from the tracklog points,
storing them together as needed in a single PolyLine shape. (PolyLine is just
ESRI’s term for a series of connected line segments.) Finally, all of the accu-
mulated PolyLines are dumped to the shapefile(s).
Running the Code
Assuming the script is marked as executable and is in your current direc-
tory, you can run it as follows:
$ gpstrans -dt > tracklog.txt
$ ./track2shp.pl tracklog.txt tracklog.shp
$ ls
track2shp.pl tracklog.dbf tracklog.shp tracklog.shx tracklog.txt
As you can see, you should have three new files in the same directory: the .shp
file containing the shapes, the .shx index file, and the .dbf datafile.
Figure 6-31 shows a sample map of a trip we made through Los Angeles,
stopping off in Hollywood to pick up friends and then visiting Venice Beach, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

GeoServer Cookbook

GeoServer Cookbook

Stefano Iacovella
Leaflet.js Essentials

Leaflet.js Essentials

Paul Crickard III

Publisher Resources

ISBN: 0596007035Purchase LinkErrata PageOther