Changeset 1245
- Timestamp:
- 04/03/08 15:38:41 (8 months ago)
- Files:
-
- PleiadesEntity/trunk/configure.zcml (modified) (1 diff)
- PleiadesEntity/trunk/geo.py (modified) (8 diffs)
- PleiadesEntity/trunk/tests/Entities.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
PleiadesEntity/trunk/configure.zcml
r1244 r1245 6 6 7 7 <!-- ##code-section configure.zcml --> 8 <adapter 9 for="Products.PleiadesEntity.content.PlacefulAssociation.PlacefulAssociation" 10 provides="zgeo.geographer.interfaces.IGeoreferenced" 11 factory=".geo.PlacefulAssociationGeoItem" 12 /> 13 14 <adapter 15 for="Products.PleiadesEntity.content.Place.Place" 16 provides="zgeo.geographer.interfaces.IGeoreferenced" 17 factory=".geo.PlaceGeoItem" 18 /> 8 19 <!-- ##/code-section configure.zcml --> 9 20 PleiadesEntity/trunk/geo.py
r1225 r1245 29 29 30 30 from zope.interface import implements 31 from zgeo.geographer.interfaces import IGeoreferenced 31 32 32 from Products.PleiadesGeocoder.interfaces import IGeoItemSimple \ 33 , IGeoCollectionSimple 34 from Products.PleiadesEntity.interfaces import IPlaceContainer \ 35 , IPlacefulContainer 36 33 import logging 34 log = logging.getLogger('PleiadesEntity.geo') 37 35 38 36 class PlacefulAssociationGeoItem(object): 39 40 """Python expression of a GeoRSS simple item. 41 """ 42 implements(IGeoItemSimple) 37 implements(IGeoreferenced) 43 38 44 39 def __init__(self, context): … … 47 42 48 43 @property 49 def geom_type(self):44 def type(self): 50 45 return 'Point' 51 46 52 def getSpatialCoordinates(self):53 x = self.context.getRefs('hasLocation')54 if len(x) == 0:55 return ()56 x0 = x[0]57 values = [float(v) for v in \58 x0.getSpatialCoordinates().split()]59 nvalues = len(values)60 # Our Pleiades Locations are 2D61 npoints = nvalues/262 coords = []63 for i in range(npoints):64 coords.append(tuple(values[3*i:3*i+3] + [0.0]))65 return tuple(coords)66 67 47 @property 68 def spatialCoordinates(self): 69 """GeoRSS Simple coordinate string (2D).""" 70 x = self.context.getRefs('hasLocation') 71 if len(x) == 0: 72 return '' 73 return x[0].getSpatialCoordinates() 74 75 @property 76 def coords(self): 48 def coordinates(self): 77 49 x = self.context.getRefs('hasLocation') 78 50 if len(x) == 0: … … 90 62 return coords[0] 91 63 92 def isGeoreferenced(self):93 """Return True if the object is "on the map"."""94 return bool(len(self.context.getRefs('hasLocation')))64 @property 65 def crs(self): 66 return None 95 67 96 68 @property … … 100 72 'type': 'Feature', 101 73 'id': context.getId(), 102 'properties': { 103 'title': context.title_or_id(), 104 'description': context.Description(), 105 'link': context.absolute_url(), 106 }, 107 'geometry': {'type': self.geom_type, 'coordinates': self.coords} 74 'geometry': {'type': self.type, 'coordinates': self.coordinates} 108 75 } 109 76 … … 113 80 """Python expression of a GeoRSS simple item. 114 81 """ 115 implements(IGeo ItemSimple)82 implements(IGeoreferenced) 116 83 117 84 def __init__(self, context): … … 119 86 self.context = context 120 87 self._primary_association = None 121 for ob in context.listFolderContents():88 for ob in self.context.values(): 122 89 try: 123 self._primary_association = IGeo ItemSimple(ob)90 self._primary_association = IGeoreferenced(ob) 124 91 except: 125 92 continue … … 128 95 raise Exception, "Could not adapt %s" % str(context) 129 96 130 def isGeoreferenced(self):131 """Return True if the object is "on the map"."""132 return self._primary_association.isGeoreferenced()97 @property 98 def type(self): 99 return IGeoreferenced(self._primary_association).type 133 100 134 101 @property 135 def geom_type(self):136 return self._primary_association.geom_type102 def coordinates(self): 103 return IGeoreferenced(self._primary_association).coordinates 137 104 138 105 @property 139 def c oords(self):140 return self._primary_association.coords106 def crs(self): 107 return None 141 108 142 109 @property 143 110 def __geo_interface__(self): 144 context = self.context 145 return { 146 'type': 'Feature', 147 'id': context.getId(), 148 'properties': { 149 'title': context.title_or_id(), 150 'description': context.Description(), 151 'link': context.absolute_url(), 152 }, 153 'geometry': { 154 'type': self._primary_association.geom_type, 155 'coordinates': self._primary_association.coords 156 } 157 } 158 111 return IGeoreferenced(self._primary_association).__geo_interface__ 159 112 160 113 def createGeoItem(context): … … 166 119 167 120 168 class GeoCollectionSimple(object):169 170 """Adapter for Folderish collections of GeoItemSimple.171 """172 implements(IGeoCollectionSimple)173 174 def __init__(self, context):175 """Initialize."""176 self.context = context177 178 def geoItems(self):179 if IPlaceContainer.providedBy(self.context):180 #hasattr(self.context, 'listFolderContents'):181 for ob in self.context.listFolderContents():182 try:183 item = IGeoItemSimple(ob)184 assert(item.isGeoreferenced())185 except:186 continue187 yield item188 else:189 try:190 item = IGeoItemSimple(self.context)191 assert(item.isGeoreferenced())192 yield item193 except:194 pass195 121 PleiadesEntity/trunk/tests/Entities.txt
r1225 r1245 57 57 --------------------- 58 58 59 >>> from Products.PleiadesGeocoder.interfaces import IGeoItemSimple, IGeoCollectionSimple59 >>> from zgeo.geographer.interfaces import IGeoreferenced 60 60 61 61 Place Association 62 62 63 >>> g = IGeoItemSimple(a) 64 >>> g.isGeoreferenced() 65 True 63 >>> g = IGeoreferenced(a) 66 64 >>> gi = g.__geo_interface__ 67 65 >>> gi['type'] 68 66 'Feature' 69 >>> g i['geometry']['type']67 >>> g.type 70 68 'Point' 71 >>> g i['geometry']['coordinates']69 >>> g.coordinates 72 70 (-86.480833333333294, 34.769722222222001, 0.0) 73 71 74 72 Place 75 73 76 >>> g = IGeoItemSimple(p) 77 >>> g.isGeoreferenced() 78 True 74 >>> g = IGeoreferenced(p) 79 75 >>> gi = g.__geo_interface__ 80 76 >>> gi['type'] 81 77 'Feature' 82 >>> g i['geometry']['type']78 >>> g.type 83 79 'Point' 84 >>> g i['geometry']['coordinates']80 >>> g.coordinates 85 81 (-86.480833333333294, 34.769722222222001, 0.0) 86 >>> gi['properties']['title']87 'Civitas Non'88 82 89 >>> c = IGeoCollectionSimple(places)90 >>> x = list(c.geoItems())91 >>> len(x)92 193
