Skip to content

Instantly share code, notes, and snippets.

@l34marr
Created February 5, 2015 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l34marr/786c1656c0766d7c8eef to your computer and use it in GitHub Desktop.
Save l34marr/786c1656c0766d7c8eef to your computer and use it in GitHub Desktop.
Setting Geo Data with Plone Maps collective.geo.*
from Testing import makerequest
from AccessControl.SecurityManagement import newSecurityManager
from Products.CMFCore.utils import getToolByName
root = makerequest.makerequest(app)
site = root.mysite
admin = root.acl_users.getUserById('admin')
admin = admin.__of__(site.acl_users)
newSecurityManager(None, admin)
from zope.site.hooks import setHooks
from zope.component.hooks import setSite
setHooks()
site.setupCurrentSkin(site.REQUEST)
ct = getToolByName(site, 'portal_catalog')
from myproj.content.photo import IPhoto
from collective.geo.geographer.interfaces import IGeoreferenceable
from Products.Five.utilities.marker import mark
mark(IPhoto, IGeoreferenceable)
import csv
from collective.geo.geographer.interfaces import IWriteGeoreferenced
with open('my-geo-data.csv', 'rb') as f:
f.seek(0)
reader = csv.reader(f)
for row in reader:
brains = ct.searchResults(id=row[0], path='/mysite/photos')
if len(brains) != 1:
print row[0] + ': Error'
pass
else:
obj = brains[0].getObject()
geo = IWriteGeoreferenced(obj)
geo.setGeoInterface('Point', (float(row[1]), float(row[2])))
obj.reindexObject(idxs=['zgeo_geometry'])
import transaction
transaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment