Created
February 5, 2015 06:15
-
-
Save l34marr/786c1656c0766d7c8eef to your computer and use it in GitHub Desktop.
Setting Geo Data with Plone Maps collective.geo.*
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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