2013/09/14

Setting Geo Data Programmatically

collective.geo.* allows to geo-reference Plone content types and to display this geo data over a map.

>>> from Testing import makerequest
>>> root = makerequest.makerequest(app)
>>> site = root.mysite

>>> admin = root.acl_users.getUserById('admin')
>>> admin = admin.__of__(site.acl_users)

>>> from AccessControl.SecurityManagement import newSecurityManager
>>> newSecurityManager(None, admin)

>>> from zope.site.hooks import setHooks
>>> from zope.site.hooks import setSite
>>> setHooks()
>>> setSite(site)
>>> site.setupCurrentSkin(site.REQUEST)
>>> folder = site['temples']
>>> folder.objectIds()
['63010023-JTG']

>>> from collective.geo.geographer.interfaces import IGeoreferenced
>>> geo = IGeoreferenced(folder['63010023-JTG'])
>>> geo.coordinates
(121.52559379690797, 25.023316046141368)
>>> geo.hasCoordinates()
True

>>> geo.setGeoInterface('Point', (-105.08, 40.59))

Be careful that coordinates are using floats instead of strings, for example you might get data from CSV files.

Check collective.geo.geographer/README.rst for more details.

No comments: