Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sample data

  • Loading branch information...
commit 3762235efaba84f1cfce171a6799552586af9d2b 1 parent 13ad1a3
@springmeyer authored
View
BIN  test/10m-populated-places-simple.zip
Binary file not shown
View
BIN  test/10m_populated_places_simple.dbf
Binary file not shown
View
1  test/10m_populated_places_simple.prj
@@ -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]]
View
BIN  test/10m_populated_places_simple.shp
Binary file not shown
View
BIN  test/10m_populated_places_simple.shx
Binary file not shown
View
44 test/import.py
@@ -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
22 test/test.py
@@ -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')
+
Please sign in to comment.
Something went wrong with that request. Please try again.