collective.geo.geographer 1.4

Geographic annotation for Plone
collective.geo.geographer provides geo annotation for Plone.

How it works

Any object that implements zope.annotation.interfaces.IAttributeAnnotatable and collective.geo.geographer.interfaces.IGeoreferenceable can be adapted and geo-referenced. The former marker is standard for Zope content objects, and the latter can be easily configured via ZCML.

Let's test with an example placemark, which provides both of the marker interfaces mentioned above.

 >>> from zope.interface import implements
 >>> from zope.annotation.interfaces import IAttributeAnnotatable
 >>> from collective.geo.geographer.interfaces import IGeoreferenceable

 >>> class Placemark(object):
 ... implements(IGeoreferenceable, IAttributeAnnotatable)

 >>> placemark = Placemark()

Adapt it to IGeoreferenced

 >>> from collective.geo.geographer.interfaces import IGeoreferenced
 >>> geo = IGeoreferenced(placemark)

Its properties should all be None

 >>> geo.type is None
 >>> geo.coordinates is None
 >>> is None

Now set the location geometry to type "Point" and coordinates 105.08 degrees West, 40.59 degrees North using setGeoInterface()

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

A georeferenced object has "type" and "coordinates" attributes which should give us back what we put in.

 >>> geo.type
 >>> geo.coordinates
 (-105.08, 40.590000000000003)
 >>> is None

An event should have been sent

 >>> from zope.component.eventtesting import getEvents
 >>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent
 >>> events = getEvents(IObjectModifiedEvent)
 >>> len(events)
 >>> events[0].object is placemark

Plone integration

Make a topic in our folder

 >>> self.setRoles(('Manager',))

 >>> folder = self.folder
 >>> oid = self.folder.invokeFactory('Topic', 'topic')
 >>> topic = self.folder[oid]
 >>> c = topic.addCriterion('getGeometry', 'ATBooleanCriterion')

Add geo-referenced content

 >>> oid = self.folder.invokeFactory('Document', 'doc')
 >>> doc = self.folder[oid]

If content type doesn't implements IGeoreferenceable interfaces we need to provide it

 >>> from zope.interface import alsoProvides
 >>> alsoProvides(doc, IGeoreferenceable)

now we can set the coordinates

 >>> from collective.geo.geographer.interfaces import IWriteGeoreferenced
 >>> geo = IWriteGeoreferenced(doc)
 >>> geo.setGeoInterface('Point', (-100, 40))

Check the topic

 >>> brain = [b for b in topic.queryCatalog() if == 'doc'][0]
 >>> brain.zgeo_geometry['type']
 >>> brain.zgeo_geometry['coordinates']
 (-100, 40)

A simple view notify us if a context is geo referenceable

 >>> doc.restrictedTraverse('@@geoview').isGeoreferenceable()

 >>> topic.restrictedTraverse('@@geoview').isGeoreferenceable()

last updated on:
February 16th, 2012, 4:55 GMT
license type:
GPL (GNU General Public License) 
developed by:
Giorgio Borelli
ROOT \ Internet \ Plone Extensions
Download Button

In a hurry? Add it to your Download Basket!

user rating



Rate it!
What's New in This Release:
  • changed tests using [gborelli]
  • Added IGeoCoder utility [gborelli]
  • Marked as deprecated IGeoCoder adapter [gborelli]
  • Added removeGeoInterface to remove coordinates from an object [mircoangelini]
read full changelog

Add your review!