Changeset 1245

Show
Ignore:
Timestamp:
04/03/08 15:38:41 (8 months ago)
Author:
sgillies
Message:

Switch to zgeo.geographer.interfaces.IGeoreferenced

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PleiadesEntity/trunk/configure.zcml

    r1244 r1245  
    66 
    77  <!-- ##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    /> 
    819  <!-- ##/code-section configure.zcml --> 
    920 
  • PleiadesEntity/trunk/geo.py

    r1225 r1245  
    2929 
    3030from zope.interface import implements 
     31from zgeo.geographer.interfaces import IGeoreferenced 
    3132 
    32 from Products.PleiadesGeocoder.interfaces import IGeoItemSimple \ 
    33     , IGeoCollectionSimple 
    34 from Products.PleiadesEntity.interfaces import IPlaceContainer \ 
    35     , IPlacefulContainer 
    36  
     33import logging 
     34log = logging.getLogger('PleiadesEntity.geo') 
    3735 
    3836class PlacefulAssociationGeoItem(object): 
    39      
    40     """Python expression of a GeoRSS simple item. 
    41     """ 
    42     implements(IGeoItemSimple) 
     37    implements(IGeoreferenced) 
    4338    
    4439    def __init__(self, context): 
     
    4742 
    4843    @property 
    49     def geom_type(self): 
     44    def type(self): 
    5045        return 'Point' 
    5146 
    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 2D 
    61         npoints = nvalues/2 
    62         coords = [] 
    63         for i in range(npoints): 
    64             coords.append(tuple(values[3*i:3*i+3] + [0.0])) 
    65         return tuple(coords) 
    66  
    6747    @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): 
    7749        x = self.context.getRefs('hasLocation') 
    7850        if len(x) == 0: 
     
    9062        return coords[0] 
    9163 
    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 
    9567 
    9668    @property 
     
    10072            'type': 'Feature', 
    10173            '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} 
    10875            } 
    10976 
     
    11380    """Python expression of a GeoRSS simple item. 
    11481    """ 
    115     implements(IGeoItemSimple
     82    implements(IGeoreferenced
    11683    
    11784    def __init__(self, context): 
     
    11986        self.context = context 
    12087        self._primary_association = None 
    121         for ob in context.listFolderContents(): 
     88        for ob in self.context.values(): 
    12289            try: 
    123                 self._primary_association = IGeoItemSimple(ob) 
     90                self._primary_association = IGeoreferenced(ob) 
    12491            except: 
    12592                continue 
     
    12895            raise Exception, "Could not adapt %s" % str(context) 
    12996 
    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 
    133100 
    134101    @property 
    135     def geom_type(self): 
    136         return self._primary_association.geom_type 
     102    def coordinates(self): 
     103        return IGeoreferenced(self._primary_association).coordinates 
    137104 
    138105    @property 
    139     def coords(self): 
    140         return self._primary_association.coords 
     106    def crs(self): 
     107        return None 
    141108 
    142109    @property 
    143110    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__ 
    159112 
    160113def createGeoItem(context): 
     
    166119 
    167120 
    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 = context 
    177          
    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                     continue 
    187                 yield item 
    188         else: 
    189             try: 
    190                 item = IGeoItemSimple(self.context) 
    191                 assert(item.isGeoreferenced()) 
    192                 yield item 
    193             except: 
    194                 pass 
    195121 
  • PleiadesEntity/trunk/tests/Entities.txt

    r1225 r1245  
    5757--------------------- 
    5858 
    59     >>> from Products.PleiadesGeocoder.interfaces import IGeoItemSimple, IGeoCollectionSimple 
     59    >>> from zgeo.geographer.interfaces import IGeoreferenced 
    6060 
    6161    Place Association 
    6262 
    63     >>> g = IGeoItemSimple(a) 
    64     >>> g.isGeoreferenced() 
    65     True 
     63    >>> g = IGeoreferenced(a) 
    6664    >>> gi = g.__geo_interface__ 
    6765    >>> gi['type'] 
    6866    'Feature' 
    69     >>> gi['geometry']['type'] 
     67    >>> g.type 
    7068    'Point' 
    71     >>> gi['geometry']['coordinates'] 
     69    >>> g.coordinates 
    7270    (-86.480833333333294, 34.769722222222001, 0.0) 
    7371 
    7472    Place 
    7573 
    76     >>> g = IGeoItemSimple(p) 
    77     >>> g.isGeoreferenced() 
    78     True 
     74    >>> g = IGeoreferenced(p) 
    7975    >>> gi = g.__geo_interface__ 
    8076    >>> gi['type'] 
    8177    'Feature' 
    82     >>> gi['geometry']['type'] 
     78    >>> g.type 
    8379    'Point' 
    84     >>> gi['geometry']['coordinates'] 
     80    >>> g.coordinates 
    8581    (-86.480833333333294, 34.769722222222001, 0.0) 
    86     >>> gi['properties']['title'] 
    87     'Civitas Non' 
    8882 
    89     >>> c = IGeoCollectionSimple(places) 
    90     >>> x = list(c.geoItems()) 
    91     >>> len(x) 
    92     1 
    93