zgeo.geographer

Geographic location metadata for Zope informed by hard-earned wisdom in GIS*

Describes an interface for annotating objects with geographic location metadata and provides a standard annotator. Not just lat/long point locations, but lines and polygons. You can therefore annotate objects with paths, trajectories, areas, and patches. This geographic location metadata API is used by the other zgeo.* packages to spatially index objects and to make KML and GeoRSS views.

Version 0.2 is incompatible with 0.1.

[*] With apologies to Grok.

Help

Installation

Easiest way to install is to use easy_install

$ easy_install zgeo.geographer

You can also get the code directly from the repository

$ svn co http://svn.gispython.org/svn/zope/zgeo.geographer/trunk zgeo.geographer

Usage

Including zgeo.geographer in your site ZCML registers an annotating adapter. Any object that then provides the zope.annotation.interfaces.IAnnotatable and zgeo.geographer.interfaces.IGeoreferenceable markers can be adapted to IGeoreferenced.

class Placemark(object):
    pass

Use ZCML to declare that instances of the class are georeferenceable:

  ...
  <include package="zgeo.geographer"/>

  <class class=".Placemark">
    <implements interface="zope.annotation.interfaces.IAttributeAnnotatable"/>
    <implements interface="zgeo.geographer.interfaces.IGeoreferenceable"/>
  </class>
  ...

or for Plone 3 (Zope 2.10)

  ...
  <include package="zgeo.geographer"/>

  <five:implements
    class=".Placemark"
    interface="zope.annotation.interfaces.IAttributeAnnotatable
               zgeo.geographer.interfaces.IGeoreferenceable"
    />
  ... 

The IGeoreferenced API is used like this:

>>> placemark = Placemark()
>>> from zgeo.geographer.interfaces import IGeoreferenced
>>> geo = IGeoreferenced(placemark)
>>> geo.setGeoInterface('Point', (-105.08, 40.59))
>>> geo.type
'Point'
>>> geo.coordinates
(-105.08, 40.59) 

Advanced Usage: lines and polygons

Annotate an object with a path (a LineString? in standard GIS terminology) through 3 points (Denver -> Salt Lake -> Seattle in this example):

>>> placemark = Placemark()
>>> from zgeo.geographer.interfaces import IGeoreferenced
>>> geo = IGeoreferenced(placemark)
>>> geo.setGeoInterface('LineString', ((-105.08, 40.59), (-111.95, 40.78), (-122.33, 47.61)))
>>> geo.type
'Point'
>>> geo.coordinates
((-105.08, 40.59), (-111.95, 40.78), (-122.33, 47.61)) 

Annotate an object with a patch (a Polygon in GIS terms) representing the spatial extent of Map 8 (Britannia Superior) of the Barrington Atlas of the Greek and Roman World:

>>> placemark = Placemark()
>>> from zgeo.geographer.interfaces import IGeoreferenced
>>> geo = IGeoreferenced(placemark)
>>> geo.setGeoInterface('Polygon', ((
...     (-7.0655, 53.8223), (-6.00247, 53.85836), (-5.00324, 53.88457),
...     (-4.00219, 53.90175), (-3.00272, 53.91114), (-2.00245, 53.91275),
...     (-1.00317, 53.90616), (-0.00256, 53.89117), (0.99675, 53.86792), 
...     (1.99723, 53.837), (2.3917, 53.82198), (2.30321, 53.00065), 
...     (2.1998, 52.00128), (2.1012, 51.00174), (2.00171, 49.94775), 
...     (1.99767, 49.94787), (0.9978, 49.98176), (-0.00267, 50.00692), 
...     (-1.00278, 50.02322), (-2.00213, 50.03085), (-3.00203, 50.02854),
...     (-4.00246, 50.01832), (-5.00187, 49.99914), (-6.00273, 49.97119),
...     (-6.67377, 49.94766), (-6.77413, 51.00161), (-6.8731, 52.00137),
...     (-6.97699, 53.00093), (-7.0655, 53.8223) ), )
...     )
>>> geo.type
'Polygon'
>>> geo.coordinates
(((-7.0655000000000001, 53.822299999999998), ... ), )

Values used in the coordinates parameter of the setGeoInterface method must follow the proposed GeoJSON  specification.

Browse source

[Tickets]

Credits

 Sean Gillies (for Pleiades)

Pleiades is an international research network and associated web portal and content management system devoted to the study of ancient geography.

See  http://icon.stoa.org/trac/pleiades/wiki.

Funding for the creation of this software was provided by a grant from the U.S. National Endowment for the Humanities ( http://www.neh.gov).