Database Reference
In-Depth Information
open(filepath)return
f.read().splitlines()# first we need to
create a PostGIS table to contains the
places# we must keep the PostGIS OGR
dataset and layer global, for the reasons
# described here: http://trac.osgeo.org/
gdal/wiki/PythonGotchasfrom osgeo import
gdalgdal.UseExceptions()pg_ds, pg_layer =
CreatePGLayer()# query geonames for each
name and store found places in the
tablenames = GetNamesList('names.txt')for
name in names:
AddPlacesToLayer(GetPlaces(name))
5. Now, execute the Python script:
(postgis-cb-env)$ python
import_places.pyCreated a places titled
London Bridge station.Created a places
titled London.Created a places titled
London, Ontario.
...
6. Test whether the table was correctly created and populated using SQL and
eventually use your favorite Desktop GIS tool to display the layer:
postgis_cookbook=# select
ST_AsText(the_geom), title, countrycode,
feature from chp08.wikiplaces;
st_astext
| title |
countrycode |
feature---------------------------------------------+--------------------------------------+-------------+----------------POINT
Z (-0.0866 51.5055 18) | London Bridge
station | GB | railwaystation
POINT Z (-81.2497 42.9837
262) | London,
Ontario |
Search WWH ::




Custom Search