Geographic annotation for Plone
Project description
Introduction
============
.. role:: class(raw)
:format: html
.. role:: meth(raw)
:format: html
.. role:: mod(raw)
:format: html
:mod:`collective.geo.geographer` provides geo-annotation for `Plone`_.
This package is based on Sean Gillies's idea (`zgeo.geographer`_) and integrates
its functionalities in collective.geo project.
.. image:: https://secure.travis-ci.org/collective/collective.geo.geographer.png
:target: http://travis-ci.org/collective/collective.geo.geographer
Found a bug? Please, use the `issue tracker`_.
.. contents:: Table of contents
Requirements
============
* `Plone`_ >= 4
Installation
============
This addon can be installed like any other addon, please follow the official
documentation_.
How it works
============
Any object that implements
:class:`IAttributeAnnotatable <zope.annotation.interfaces.IAttributeAnnotatable>`
and
:class:`IGeoreferenceable <collective.geo.geographer.interfaces.IGeoreferenceable>`
can be adapted and geo-referenced.
All Zope content objects provide the former,
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
:class:`IGeoreferenced <collective.geo.geographer.interfaces.IGeoreferenced>`::
>>> from collective.geo.geographer.interfaces import IGeoreferenced
>>> geo = IGeoreferenced(placemark)
Its properties should all be ``None``::
>>> geo.type is None
True
>>> geo.coordinates is None
True
>>> geo.crs is None
True
Check whether the geo-referenceable object has coordinates or not::
>>> geo.hasCoordinates()
False
Now set the location geometry to type *Point* and coordinates
*105.08 degrees West, 40.59 degrees North* using
:meth:`setGeoInterface <IWritableGeoreference.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
'Point'
>>> tuple(['%.2f' % x for x in geo.coordinates])
('-105.08', '40.59')
>>> geo.crs is None
True
Now the :meth:`hasCoordinates <IGeoView.hasCoordinates>`
method returns True::
>>> geo.hasCoordinates()
True
An event should have been sent::
>>> from zope.component.eventtesting import getEvents
>>> from collective.geo.geographer.event import IObjectGeoreferencedEvent
>>> events = getEvents(IObjectGeoreferencedEvent)
>>> events[-1].object is placemark
True
To remove the coordinate from a georeferenced object, we can
use the :meth:`removeGeoInterface <IWritableGeoreference.removeGeoInterface>`
method::
>>> geo.removeGeoInterface()
>>> geo.type is None
True
>>> geo.coordinates is None
True
>>> geo.crs is None
True
Plone integration
-----------------
Add geo-referenced content::
>>> from plone.app.testing import setRoles
>>> from plone.app.testing import TEST_USER_ID
>>> portal = layer['portal']
>>> setRoles(portal, TEST_USER_ID, ['Manager'])
>>> oid = portal.invokeFactory('Document', 'doc')
>>> doc = portal[oid]
If the content type doesn't implement
:class:`IGeoreferenceable <collective.geo.geographer.interfaces.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))
and reindex the document::
>>> doc.reindexObject(idxs=['zgeo_geometry'])
We can create a subscriber for
:class:`IObjectGeoreferencedEvent <collective.geo.geographer.event.IObjectGeoreferencedEvent>`
to do that automatically.
Check the catalog results::
>>> from Products.CMFCore.utils import getToolByName
>>> catalog = getToolByName(portal, 'portal_catalog')
>>> brain = [b for b in catalog({'getId': 'doc'})][0]
>>> brain.zgeo_geometry['type']
'Point'
>>> brain.zgeo_geometry['coordinates']
(-100, 40)
A simple view (:class:`geoview <collective.geo.geographer.interfaces.IGeoView>`)
notifies us if a context is geo-referenceable::
>>> view = doc.restrictedTraverse('@@geoview')
>>> view.isGeoreferenceable()
True
and allows us to find its coordinates::
>>> view.getCoordinates()
('Point', (-100, 40))
When we remove the coordinates, the corresponding index will return ``None``::
>>> geo.removeGeoInterface()
>>> doc.reindexObject(idxs=['zgeo_geometry'])
>>> brain = [b for b in catalog({'getId': 'doc'})][0]
>>> brain.zgeo_geometry
Missing.Value
.. _zgeo.geographer: http://pypi.python.org/pypi/zgeo.geographer
.. _Plone: http://plone.org
.. _issue tracker: https://github.com/collective/collective.geo.bundle/issues
.. _documentation: http://plone.org/documentation/kb/installing-add-ons-quick-how-to
Contributors
============
* Sean Gillies
* Giorgio Borelli
* Christian Ledermann
* Mirco Angelini
Changelog
=========
2.1 (2016-10-26)
----------------
- Removed unittest2 using unittest instead.
[giorgio]
- using PLONE_APP_CONTENTTYPES_FIXTURE to make tests plone5 compatible
[pbauer]
- ``IObjectGeoreferencedEvent`` doesn't acquire from ``IObjectModifiedEvent``
anymore. See `issue 5 on collective.geo.geographer`_.
[keul]
2.0 (2013-10-29)
----------------
- Changed package layout
[gborelli]
- remove style key from zgeo_geometry metadata
[gborelli]
- move IGeoCoder utility to c.geo.mapwidget
[gborelli]
- remove IGeoCoder adapter
[gborelli]
1.7 (2013-04-11)
----------------
- Fixed permission on GeoreferencingAnnotator. See #3 [gborelli]
- Moved showCoordinatesTab to c.geo.contentlocations [gborelli]
- Added hasCoordinates method to GeoreferencingAnnotator to check
whether an object has been georeferenced or not [gborelli]
- Added a method in order to hidden Coordinates tab for dexterity
content types [valentinaB]
- Changed Version of Geopy (moved from 0.94.2 to 0.95) to support
Google api v3 in geocoder [cippino]
1.6 (2013-01-28)
----------------
- Fixed MANIFEST.in [gborelli]
1.5 (2013-01-28)
----------------
- Added Sphinx documentation [gborelli]
- Added travis-ci configurations [gborelli]
- Moved reindexDocSubscriber to collective.geo.contentlocations [gborelli]
- Refactored test and removed dependency from old Topic content type [gborelli]
1.4 (2012-02-11)
----------------
* changed tests using plone.app.testing [gborelli]
* Added IGeoCoder utility [gborelli]
* Marked as deprecated IGeoCoder adapter [gborelli]
* Added removeGeoInterface to remove coordinates from an object [mircoangelini]
0.1.3 (2011-09-05)
------------------
* plone 4.1 fixes [gborelli]
* include Products.CMFCore to make plone 4.1 happy [nan010]
* changed Browser import from Testing.testbrowser [gborelli]
* added z3c.autoinclude entry point [gborelli]
0.1.2 (2010-12-28)
------------------
* Moved IGeoView from c.geo.contentlocations
0.1.1 (2010-11-13)
------------------
* moved geocoderview to portal root
0.1 (2010-10-31)
----------------
* removed zgeo.geographer dependency
* zgeo.plone.geographer code refactoring
* moved from zgeo.plone.geographer
.. _`issue 5 on collective.geo.geographer`: https://github.com/collective/collective.geo.geographer/issues/5
============
.. role:: class(raw)
:format: html
.. role:: meth(raw)
:format: html
.. role:: mod(raw)
:format: html
:mod:`collective.geo.geographer` provides geo-annotation for `Plone`_.
This package is based on Sean Gillies's idea (`zgeo.geographer`_) and integrates
its functionalities in collective.geo project.
.. image:: https://secure.travis-ci.org/collective/collective.geo.geographer.png
:target: http://travis-ci.org/collective/collective.geo.geographer
Found a bug? Please, use the `issue tracker`_.
.. contents:: Table of contents
Requirements
============
* `Plone`_ >= 4
Installation
============
This addon can be installed like any other addon, please follow the official
documentation_.
How it works
============
Any object that implements
:class:`IAttributeAnnotatable <zope.annotation.interfaces.IAttributeAnnotatable>`
and
:class:`IGeoreferenceable <collective.geo.geographer.interfaces.IGeoreferenceable>`
can be adapted and geo-referenced.
All Zope content objects provide the former,
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
:class:`IGeoreferenced <collective.geo.geographer.interfaces.IGeoreferenced>`::
>>> from collective.geo.geographer.interfaces import IGeoreferenced
>>> geo = IGeoreferenced(placemark)
Its properties should all be ``None``::
>>> geo.type is None
True
>>> geo.coordinates is None
True
>>> geo.crs is None
True
Check whether the geo-referenceable object has coordinates or not::
>>> geo.hasCoordinates()
False
Now set the location geometry to type *Point* and coordinates
*105.08 degrees West, 40.59 degrees North* using
:meth:`setGeoInterface <IWritableGeoreference.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
'Point'
>>> tuple(['%.2f' % x for x in geo.coordinates])
('-105.08', '40.59')
>>> geo.crs is None
True
Now the :meth:`hasCoordinates <IGeoView.hasCoordinates>`
method returns True::
>>> geo.hasCoordinates()
True
An event should have been sent::
>>> from zope.component.eventtesting import getEvents
>>> from collective.geo.geographer.event import IObjectGeoreferencedEvent
>>> events = getEvents(IObjectGeoreferencedEvent)
>>> events[-1].object is placemark
True
To remove the coordinate from a georeferenced object, we can
use the :meth:`removeGeoInterface <IWritableGeoreference.removeGeoInterface>`
method::
>>> geo.removeGeoInterface()
>>> geo.type is None
True
>>> geo.coordinates is None
True
>>> geo.crs is None
True
Plone integration
-----------------
Add geo-referenced content::
>>> from plone.app.testing import setRoles
>>> from plone.app.testing import TEST_USER_ID
>>> portal = layer['portal']
>>> setRoles(portal, TEST_USER_ID, ['Manager'])
>>> oid = portal.invokeFactory('Document', 'doc')
>>> doc = portal[oid]
If the content type doesn't implement
:class:`IGeoreferenceable <collective.geo.geographer.interfaces.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))
and reindex the document::
>>> doc.reindexObject(idxs=['zgeo_geometry'])
We can create a subscriber for
:class:`IObjectGeoreferencedEvent <collective.geo.geographer.event.IObjectGeoreferencedEvent>`
to do that automatically.
Check the catalog results::
>>> from Products.CMFCore.utils import getToolByName
>>> catalog = getToolByName(portal, 'portal_catalog')
>>> brain = [b for b in catalog({'getId': 'doc'})][0]
>>> brain.zgeo_geometry['type']
'Point'
>>> brain.zgeo_geometry['coordinates']
(-100, 40)
A simple view (:class:`geoview <collective.geo.geographer.interfaces.IGeoView>`)
notifies us if a context is geo-referenceable::
>>> view = doc.restrictedTraverse('@@geoview')
>>> view.isGeoreferenceable()
True
and allows us to find its coordinates::
>>> view.getCoordinates()
('Point', (-100, 40))
When we remove the coordinates, the corresponding index will return ``None``::
>>> geo.removeGeoInterface()
>>> doc.reindexObject(idxs=['zgeo_geometry'])
>>> brain = [b for b in catalog({'getId': 'doc'})][0]
>>> brain.zgeo_geometry
Missing.Value
.. _zgeo.geographer: http://pypi.python.org/pypi/zgeo.geographer
.. _Plone: http://plone.org
.. _issue tracker: https://github.com/collective/collective.geo.bundle/issues
.. _documentation: http://plone.org/documentation/kb/installing-add-ons-quick-how-to
Contributors
============
* Sean Gillies
* Giorgio Borelli
* Christian Ledermann
* Mirco Angelini
Changelog
=========
2.1 (2016-10-26)
----------------
- Removed unittest2 using unittest instead.
[giorgio]
- using PLONE_APP_CONTENTTYPES_FIXTURE to make tests plone5 compatible
[pbauer]
- ``IObjectGeoreferencedEvent`` doesn't acquire from ``IObjectModifiedEvent``
anymore. See `issue 5 on collective.geo.geographer`_.
[keul]
2.0 (2013-10-29)
----------------
- Changed package layout
[gborelli]
- remove style key from zgeo_geometry metadata
[gborelli]
- move IGeoCoder utility to c.geo.mapwidget
[gborelli]
- remove IGeoCoder adapter
[gborelli]
1.7 (2013-04-11)
----------------
- Fixed permission on GeoreferencingAnnotator. See #3 [gborelli]
- Moved showCoordinatesTab to c.geo.contentlocations [gborelli]
- Added hasCoordinates method to GeoreferencingAnnotator to check
whether an object has been georeferenced or not [gborelli]
- Added a method in order to hidden Coordinates tab for dexterity
content types [valentinaB]
- Changed Version of Geopy (moved from 0.94.2 to 0.95) to support
Google api v3 in geocoder [cippino]
1.6 (2013-01-28)
----------------
- Fixed MANIFEST.in [gborelli]
1.5 (2013-01-28)
----------------
- Added Sphinx documentation [gborelli]
- Added travis-ci configurations [gborelli]
- Moved reindexDocSubscriber to collective.geo.contentlocations [gborelli]
- Refactored test and removed dependency from old Topic content type [gborelli]
1.4 (2012-02-11)
----------------
* changed tests using plone.app.testing [gborelli]
* Added IGeoCoder utility [gborelli]
* Marked as deprecated IGeoCoder adapter [gborelli]
* Added removeGeoInterface to remove coordinates from an object [mircoangelini]
0.1.3 (2011-09-05)
------------------
* plone 4.1 fixes [gborelli]
* include Products.CMFCore to make plone 4.1 happy [nan010]
* changed Browser import from Testing.testbrowser [gborelli]
* added z3c.autoinclude entry point [gborelli]
0.1.2 (2010-12-28)
------------------
* Moved IGeoView from c.geo.contentlocations
0.1.1 (2010-11-13)
------------------
* moved geocoderview to portal root
0.1 (2010-10-31)
----------------
* removed zgeo.geographer dependency
* zgeo.plone.geographer code refactoring
* moved from zgeo.plone.geographer
.. _`issue 5 on collective.geo.geographer`: https://github.com/collective/collective.geo.geographer/issues/5
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file collective.geo.geographer-2.1.tar.gz
.
File metadata
- Download URL: collective.geo.geographer-2.1.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3895df92447e18e4b73c9848654f5b62cd0cc9eaab1a0efffa812fc682322700 |
|
MD5 | 70b4547abd954efd6cfa22694b8180c8 |
|
BLAKE2b-256 | d2bbab1a1eb35bdc44ae3438cf26c90d3cab066448e984f550f794660b2e76ae |