Database Reference
In-Depth Information
Writing PostGIS vector data with OGR
Python bindings
Inthisrecipe,youwillusePythonandthePythonbindingsoftheGDAL/OGRlibraryto
createascriptforgeocodingalistofthenamesofplacesusingoneoftheGeoNames
Web services (
http://www.geonames.org/export/ws-overview.html
)
. You will use the
WikipediaFullTextSearchWebservice(
http://www.geonames.org/export/wikipedia-
webservice.html#wikipediaSearch
)
, which for a given search string returns the co-
ordinatesoftheplacesmatchingthatsearchstringastheoutputandsomeotheruse-
ful attributes from Wikipedia, including the Wikipedia
page title
and
url
.
ThescriptshouldfirstcreateaPostGISpointlayernamed
wikiplaces
inwhichall
of the locations and their attributesreturned by the web service will be stored.
This recipe should give you the basis to use other similar web services, such as
Google Maps, Yahoo! BOSS Geo Services, and so on, to get results in a similar way.
Before you start, please note the terms of use of GeoNames:
ht-
tp://www.geonames.org/export/
. In a few words, on the date of writing, you have
30,000credits'dailylimitperapplication(identifiedbythe
username
parameter);the
hourly limit is 2000 credits. A credit is a web service request hit for most services.
YouwillgeneratethePostGIStablecontainingthegeocodedplacenamesusingthe
GDAL/OGR Python bindings (
http://trac.osgeo.org/gdal/wiki/GdalOgrInPython
).
Getting ready
1. To access GeoNames Web services, you need to create a user at
ht-
you will need to change it with your username whenever you query the
GeoNames Web services URL.
2. IfyouareusingWindows,besuretohaveOSGeo4Winstalledassuggested
in the initial instructions of this chapter.
3. IfyouareusingLinux,followtheinitialinstructionsforthischapterandcreate
aPython
virtualenv
,inordertokeepaPython-isolatedenvironmenttobe
used for all the Python recipes of this topic, and activate it: