Permalink
Browse files

sample data

  • Loading branch information...
1 parent 13ad1a3 commit 3762235efaba84f1cfce171a6799552586af9d2b Dane Springmeyer committed Aug 19, 2011
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,44 @@
+
+import os
+import sys
+import pymongo
+import mapnik2 as mapnik
+
+
+# note: only works with point geometries
+
+# http://api.mongodb.org/python/1.1.2%2B/index.html
+# http://www.mongodb.org/pages/viewpage.action?pageId=133415
+
+
+def shp_to_mongo(collection,shapefile,append=False):
+ ds = mapnik.Shapefile(file=shapefile)
+ if not append:
+ print 'Removing features from the collection...'
+ collection.remove({})
+ idx = 0
+ featureset = ds.featureset()
+ feat = featureset.next()
+ while feat:
+ for i in range(0,feat.num_geometries()):
+ coord = feat.get_geometry(i).envelope().center()
+ loc = {'long': coord.x, 'lat': coord.y }
+ collection.insert( {
+ 'name': feat['NAME'],
+ 'id': feat.id(),
+ 'loc': [coord.x,coord.y]
+ #'long': coord.x,
+ #'lat': coord.y
+ })
+ feat = featureset.next()
+
+ idx += 1
+ print 'imported %s features' % idx
+
+
+
+if __name__ == "__main__":
+ connection = pymongo.connection.Connection('localhost', 27017)
+ collection = connection['gisdb']['world']
+ if collection:
+ shp_to_mongo(collection,'10m_populated_places_simple.shp')
View
@@ -0,0 +1,22 @@
+import mapnik2 as mapnik
+
+mapnik.register_plugins('../') # get mongo.input
+
+m = mapnik.Map(600,400)
+m.background = mapnik.Color('white')
+s = mapnik.Style()
+r = mapnik.Rule()
+r.symbols.append(mapnik.PointSymbolizer())
+t = mapnik.TextSymbolizer(mapnik.Expression("[key]"),"DejaVu Sans Book",10,mapnik.Color('black'))
+t.displacement = (15,15)
+r.symbols.append(t)
+s.rules.append(r)
+m.append_style('style',s)
+ds = mapnik.Datasource(type="mongo")
+l = mapnik.Layer('test')
+l.styles.append('style')
+l.datasource = ds
+m.layers.append(l)
+m.zoom_all()
+mapnik.render_to_file(m,'test.png')
+

0 comments on commit 3762235

Please sign in to comment.