Database Reference
In-Depth Information
CA | cityPOINT Z (-72.1008333333
41.3555555556 27) | New London,
Connecticut | US |
cityPOINT Z (-0.07857 51.504872
2) |
London |
GB | city...POINT Z (2.33305556
48.90694444 36) | Saint-Ouen,
Seine-Saint-Denis | FR
|POINT Z (2.343333 48.848611
61) |
Sorbonne
| |POINT Z (2.30472222222
48.9325 28) |
Gennevilliers |
FR | city
(60 rows)
How it works...
This Python script uses the
urllib2
(part of the standard Python library) and
simplejson
libraries to fetch data from the GeoNames
wikipediaSearchJSON
web service and the GDAL/OGR library to store geographic information inside the
PostGIS database.
First, you create a PostGIS point table to store the geographic data. This is made
using the GDAL/OGR bindings. You need to instantiate a OGR PostGIS driver (
ht-
tp://www.gdal.org/ogr/drv_pg.html
)
from where it is possible to instantiate a data-
settoconnecttoyour
postgis_cookbook
databaseusingaspecifiedconnection-
string.
The
update
parameterintheconnectionstringspecifiestotheGDALdriverthatwill
open the dataset for updating.
FromthePostGISdataset,wecreatedaPostGISlayernamed
wikiplaces
thatwill
storepoints(
geom_type=ogr.wkbPoint
)usingthe
WGS 84
spatialreferencesys-
tem (
srs.ImportFromEPSG(4326)
). When creating the layer, we specified oth-