
426
|
Chapter 7, Names and Places
#85 Geocode U.S. Locations with the GNIS
HACK
Once we’ve found the place we’re looking for—e.g., Abu Dhabi—we can
look for geospatial information about it:
> SELECT place.name, place.lat,place.lon,feature.name from place, feature
WHERE place.name = 'Abu Dhabi'
AND feature.id = place.feature_type;
We might want a list of all populated places, or all rivers, in a country. This
will be especially useful when we have a list of things and want to figure out
which ones are cities, such as in trying to extract spatial proper nouns from
news items, or extracting spatial references
[Hack #45].
Hacking the Hack
If you have access to a PostGIS database, you can make the gazetteer more
interesting by storing the latitude and longitude as POINT geometry types,
rather than just character strings. With polygons representing country bor-
ders or political administrative areas, you can make much more sophisti-
cated spatial queries; distance between points and “is this place in this area”
are just the start. A further hack that pursues these ideas can be found
online at http://mappinghacks.com/projects/gutenmap/, where the GNS is
used as the basis for a (rough) interactive map of the Peloponnesian War.
See “Build a Spatially Indexed Data Store”
[Hack #87], which covers PostGIS
geometry functions in much more detail.
HACK
#85
Geocode U.S. Locations with the GNIS Hack #85
Make ordinary place ...