Database Reference
In-Depth Information
ogr.CreateGeometryFromWkt(point_wkt)# we
create a LayerDefn for the feature using
the one from the layerfeatureDefn =
pg_layer.GetLayerDefn()feature =
ogr.Feature(featureDefn)
# now time to assign the geometry
and all the other feature's fields,# if
the keys are contained in the dictionary
(not always the GeoNames# Wikipedia
Fulltext Search contains all of the
information)feature.SetGeometry(point)feature.SetField('title',place['title'].encode("utf-8")
if 'title' in place else
'')feature.SetField('countrycode',place['countryCode']
if 'countryCode' in place else
'')feature.SetField('feature',place['feature']
if 'feature' in place else
'')feature.SetField('thumbnail',place['thumbnailImg']
if 'thumbnailImg' in place else
'')feature.SetField('wikipediaurl',place['wikipediaUrl']
if 'wikipediaUrl' in place else '')# here
we create the feature (the INSERT SQL is
issued
here)pg_layer.CreateFeature(feature)print
'Created a places titled %s.' %
place['title']def
GetPlaces(placename):"""Get the places
list for a given placename."""# uri to
access the JSON GeoNames Wikipedia
Fulltext Search web serviceuri =
('http://api.geonames.org/
wikipediaSearchJSON?formatted=true&q=%s&maxRows=%s&username=%s&style=full'%
(placename, MAXROWS, USERNAME))data =
urllib2.urlopen(uri)js_data =
json.load(data)return
js_data['geonames']def
GetNamesList(filepath):"""Open a file
with a given filepath containing place
names and return a list."""f =
Search WWH ::




Custom Search