Changeset 808
- Timestamp:
- 05/17/07 10:40:18 (2 years ago)
- Files:
-
- Geographer/trunk/configure.zcml (modified) (2 diffs)
- Geographer/trunk/geo.py (modified) (5 diffs)
- Geographer/trunk/interfaces.py (modified) (4 diffs)
- Geographer/trunk/tests/adapters.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Geographer/trunk/configure.zcml
r807 r808 10 10 11 11 <adapter factory=".geo.GeoContentSimple"/> 12 <adapter factory=".geo.GeoBrainSimple"/> 12 13 13 14 <five:implements … … 16 17 /> 17 18 19 <five:implements 20 class="Products.ZCatalog.CatalogBrains.AbstractCatalogBrain" 21 interface=".interfaces.IReadOnlyGeoreferenceableBrain" 22 /> 23 18 24 </configure> 19 25 Geographer/trunk/geo.py
r807 r808 30 30 from zope.component import adapts, createObject 31 31 from zope.component.factory import Factory 32 from zope.component.interfaces import ComponentLookupError 32 33 from zope.interface import implements 33 34 from zope.schema.fieldproperty import FieldProperty … … 39 40 from zope.app.annotation.interfaces import IAnnotations 40 41 42 from Products.ZCatalog.CatalogBrains import AbstractCatalogBrain 43 from Products.CMFPlone import CatalogTool as catalogtool 44 41 45 from Products.Geographer.interfaces import IGeometry, IGeoItemSimple 42 46 from Products.Geographer.interfaces import IGeoreferenceable 47 from Products.Geographer.interfaces import IReadOnlyGeoreferenceableBrain 43 48 44 49 … … 53 58 type = FieldProperty(IGeometry['type']) 54 59 coordinates = FieldProperty(IGeometry['coordinates']) 55 crs = FieldProperty(IGeometry['crs'])56 60 57 61 … … 78 82 def __init__(self, context): 79 83 """Initialize adapter.""" 80 self.context = context 81 annotations = IAnnotations(context) 82 self.geometry = annotations.get(ANNO_KEY) 83 if not self.geometry: 84 annotations[ANNO_KEY] = createObject(u'geographer.Geometry') 85 self.geometry = annotations[ANNO_KEY] 86 self.geometry.type = 'Point' 87 self.geometry.coordinates = () 84 try: 85 self.context = context 86 annotations = IAnnotations(context) 87 self.geometry = annotations.get(ANNO_KEY) 88 if not self.geometry: 89 annotations[ANNO_KEY] = createObject(u'geographer.Geometry') 90 self.geometry = annotations[ANNO_KEY] 91 self.geometry.type = 'Point' 92 self.geometry.coordinates = () 93 except: 94 raise ComponentLookupError(IGeoItemSimple, context) 88 95 89 96 def getInfo(self): … … 107 114 info = property(getInfo,) 108 115 116 117 # Adapts catalog brains 118 119 class GeoBrainSimple(object): 120 121 """Provides geo-referencing properties and the Python feature protocol. 122 """ 123 implements(IGeoItemSimple) 124 adapts(IReadOnlyGeoreferenceableBrain) 125 126 def __init__(self, context): 127 """Initialize adapter.""" 128 try: 129 self.id = context['getId'] 130 self.uri = context.getURL() 131 self.title = context['Title'] 132 self.description = context['Description'] 133 self.geometry = createObject(u'geographer.Geometry') 134 self.geometry.type = context['geom_type'] 135 self.geometry.coordinates = context['geom_coordinates'] 136 self.context = context 137 except: 138 raise ComponentLookupError(IGeoItemSimple, context) 139 140 def getInfo(self): 141 context = self.context 142 return { 143 'id': self.id, 144 'properties': { 145 'title': unicode(self.title), 146 'description': unicode(self.description), 147 'uri': self.uri, 148 }, 149 'geometry': { 150 'type': self.geometry.type, 151 'coordinates': self.geometry.coordinates, 152 } 153 } 154 155 info = property(getInfo,) 156 157 158 # Support for indexing geo-referencing 159 160 def getGeometryType(object, portal, **kw): 161 item = IGeoItemSimple(object, None) 162 if item is not None: 163 return item.geometry.type 164 return None 165 166 def getCoordinates(object, portal, **kw): 167 item = IGeoItemSimple(object, None) 168 if item is not None: 169 return item.geometry.coordinates 170 return None 171 172 catalogtool.registerIndexableAttribute('geom_type', getGeometryType) 173 catalogtool.registerIndexableAttribute('geom_coordinates', getCoordinates) 174 Geographer/trunk/interfaces.py
r807 r808 37 37 38 38 from zope.interface import Interface 39 from zope.schema import BytesLine,Choice, Dict, Id, Object, Tuple, URI39 from zope.schema import Choice, Dict, Id, Object, Tuple, URI 40 40 41 41 # Marker interfaces. These are on the "for" side of a Zope3 adapter. … … 45 45 """Marks an object that may be annotated with georeferencing properties. 46 46 """ 47 47 48 49 class IReadOnlyGeoreferenceableBrain(Interface): 50 51 """Marks a catalog brain. 52 """ 53 48 54 49 55 class IGeoserializable(Interface): … … 73 79 # TODO: geometries other than points 74 80 type = Choice( 75 values=("Point",), 81 values=("Point",), # Eventually add LineString, Polygon, etc. 76 82 title=u"Geometry Type", 77 83 description=u"The name of the geometry type. See " … … 87 93 required=False, 88 94 default=(), 89 )90 91 crs = BytesLine(92 title=u"Coordinate Reference System",93 description=u"The PROJ.4 format definition of a coordinate reference "94 "system",95 required=False,96 default="epsg:4326",97 95 ) 98 96 Geographer/trunk/tests/adapters.txt
r807 r808 3 3 4 4 >>> from Products.Geographer.interfaces import IGeoItemSimple 5 >>> folder = self.folder 6 >>> catalog = self.portal.portal_catalog 7 >>> catalog.addColumn('geom_type') 8 >>> catalog.addColumn('geom_coordinates') 5 9 6 10 Target: an AT content object … … 9 13 Add a new document and geo-reference it 10 14 11 >>> self.folder.invokeFactory('Document', id='document', title=u'A Document',15 >>> folder.invokeFactory('Document', id='document', title=u'A Document', 12 16 ... description=u'This is a document') 13 17 'document' 14 >>> item = IGeoItemSimple( self.folder.document)18 >>> item = IGeoItemSimple(folder.document) 15 19 >>> item 16 20 <Products.Geographer.geo.GeoContentSimple object at ...> … … 20 24 >>> item.geometry.type = 'Point' 21 25 >>> item.geometry.coordinates = ((0.0, 0.0, 0.0),) 26 >>> folder.document.reindexObject() 22 27 23 28 Check info … … 25 30 >>> item.info 26 31 {'geometry': {'type': 'Point', 'coordinates': ((0.0, 0.0, 0.0),)}, 'id': 'document', 'properties': {'uri': 'http://nohost/plone/Members/test_user_1_/document', 'description': u'This is a document', 'title': u'A Document'}} 32 33 Target: a catalog brain 34 ----------------------- 27 35 36 Query catalog for the test document 37 38 >>> brain = catalog.searchResults({"getId": "document"})[0] 39 >>> brain.geom_type 40 'Point' 41 >>> brain.geom_coordinates 42 ((0.0, 0.0, 0.0),) 43 >>> item = IGeoItemSimple(brain, None) 44 >>> item.geometry 45 <Products.Geographer.geo.Geometry object at ...> 46 >>> item.geometry.type 47 'Point' 48 >>> item.geometry.coordinates 49 ((0.0, 0.0, 0.0),) 50 >>> item.info 51 {'geometry': {'type': 'Point', 'coordinates': ((0.0, 0.0, 0.0),)}, 'id': 'document', 'properties': {'uri': 'http://nohost/plone/Members/test_user_1_/document', 'description': u'This is a document', 'title': u'A Document'}} 52
