Changeset 607

Show
Ignore:
Timestamp:
01/08/07 20:54:43
Author:
seang
Message:

GeoRSS feature store so that we can render feeds (#95)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PCL/trunk/PCL-Core/cartography/data/georss.py

    r606 r607  
    3434import feedparser 
    3535 
     36from cartography.styles import Layer 
    3637from cartography.geometry import * 
    3738from cartography.data.feature import * 
    3839from cartography.proj import SpatialReference 
    39 from cartography.data.interfaces import IFeature, IFeatureSource 
     40from cartography.data.interfaces import IFeature, IFeatureSource, IFeatureStore 
    4041 
    4142from zope.interface import implements 
     
    9091        ) 
    9192 
     93def source_layer(source): 
     94    """Factory for a cartographic Layer.""" 
     95    typename = source.document.feed.title 
     96    ds = GeoRSSFeatureStore(sources={typename: source}) 
     97    return Layer(ds, typename) 
     98 
    9299 
    93100class GeoRSSFeature(Feature): 
     
    131138 
    132139    __call__ = iterfeatures 
    133          
     140        
     141 
     142class GeoRSSFeatureStore: 
     143 
     144    """Implements IFeatureStore. 
     145 
     146    A store corresponds to an Atom service document. 
     147    """ 
     148    implements(IFeatureStore) 
     149 
     150    def __init__(self, sources): 
     151        self.sources = sources.copy() 
     152 
     153    def featuretype(self, typename): 
     154        return GeoRSSFeature 
     155 
     156    def source(self, typename, maxfeatures=-1): 
     157        return self.sources[typename] 
     158 
     159    def count(self, typename): 
     160        """Returns the feature count.""" 
     161        return len(self.sources[typename].document.entries) 
     162 
     163    def typenames(self): 
     164        """Returns the typenames available in this store.""" 
     165        return tuple(self.sources.keys()) 
    134166 
    135167