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
444
|
Chapter 8, Building the Geospatial Web
#88 Load Your Waypoints into a Spatial Database
HACK
This says that we want to use the spheroid called WGS_1984, which assumes
an Earth radius of 6,378,137 meters (3,963 miles) and a flattening factor of
about 298 meters.
Here is a query to return the distance between any two waypoints.
ORA2 is
the waypoint of the new O’Reilly campus, and
TOLPLZ is the toll plaza for the
Golden Gate Bridge. The query returns the distance in meters, so we divide
the answer by 1609.344, which is the number of meters in a mile, to return
the result in miles:
gpswork-# select distance_spheroid(
w1.location,
w2.location,
'SPHEROID["WGS_1984",6378137,298.257223563]'
) / 1609.344
from waypoint w1, waypoint w2
where w1.name = 'ORA2'
and w2.name = 'TOLPLZ';
?column?
------------------
46.1867561160993
(1 row)
Here’s a brief taste of what we can do with waypoints in PostGIS. This query
calculates the distance from my house to all of my waypoints:
select distinct w1.name, w2.name, round(distance_spheroid(
w1.location,
w2.location,
'SPHEROID["WGS_1984",6378137,298.257223563]'
) / 1609.344) as my_dist
from waypoint w1, waypoint w2
where w1.name = 'HOME'
order by w2.name
The results should look like this (with 496 waypoints you probably don’t
care about omitted):
name | name | my_dist
------+--------+---------
HOME | 100 | 1032
HOME | 588 | 178
HOME | ABSPOT | 80
Not Quite a Cross Tab Query
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

The Three Traps That Stymie Reinvention

The Three Traps That Stymie Reinvention

Ryan Raffaelli
Computing for Numerical Methods Using Visual C++

Computing for Numerical Methods Using Visual C++

Shaharuddin Salleh, Albert Y. Zomaya, Sakhinah A. Bakar

Publisher Resources

ISBN: 0596007035Purchase LinkErrata PageOther