Changeset 1225

Show
Ignore:
Timestamp:
11/05/07 18:16:43 (1 year ago)
Author:
sgillies
Message:

Update to use simpler PleiadesGeocoder interfaces

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PleiadesEntity/trunk/geo.py

    r1184 r1225  
    4646        self.context = context 
    4747 
    48     def getSRS(self): 
    49         return 'EPSG:4326' 
    50  
    51     def setSRS(self, srs): 
    52         pass 
    53          
    54     def getGeometryType(self): 
    55         return 'point' 
    56  
    5748    @property 
    5849    def geom_type(self): 
    5950        return 'Point' 
    60  
    61     def setGeometryType(self, geomtype): 
    62         pass 
    6351 
    6452    def getSpatialCoordinates(self): 
     
    10290        return coords[0] 
    10391 
    104     def setGeometry(self, geomtype, coords): 
    105         value = '' 
    106         for point in coords: 
    107             if len(point) == 3: 
    108                 value = ' '.join([value, "%f %f %f" % point]) 
    109             elif len(point) == 2: 
    110                 value = ' '.join([value, "%f %f 0.0" % point]) 
    111             else: 
    112                 raise ValueError, \ 
    113                 "Insufficient number of ordinates: %s" % str(point) 
    114         x0 = self.context.getRefs('hasLocation')[0] 
    115         x0.setSpatialCoordinates(value.lstrip()) 
    116          
    11792    def isGeoreferenced(self): 
    11893        """Return True if the object is "on the map".""" 
    11994        return bool(len(self.context.getRefs('hasLocation'))) 
    120  
    121     def hasPoint(self): 
    122         return 1 
    123          
    124     def hasLineString(self): 
    125         return 0 
    126  
    127     def hasPolygon(self): 
    128         return 0 
    129  
    130     def getInfo(self, dims=3): 
    131         """Return an informative dict.""" 
    132         context = self.context 
    133         info = {'srs':                  self.getSRS(), 
    134                 'geometryType':         self.getGeometryType(), 
    135                } 
    136         points = self.getSpatialCoordinates() 
    137         coords = [] 
    138         for i in range(len(points)): 
    139             coords.extend([str(v) for v in points[i][0:dims]]) 
    140         info['spatialCoordinates'] = ' '.join(coords) 
    141  
    142         # Content objects 
    143         info.update( 
    144                {'id':           context.getId(), 
    145                 'title':        context.title_or_id(), 
    146                 'description':  context.Description(), 
    147                 'url':          context.absolute_url(),} 
    148             ) 
    149         return info 
    15095 
    15196    @property 
     
    15398        context = self.context 
    15499        return { 
     100            'type': 'Feature', 
    155101            'id': context.getId(), 
    156102            'properties': { 
     
    182128            raise Exception, "Could not adapt %s" % str(context) 
    183129 
    184     def getSRS(self): 
    185         return 'EPSG:4326' 
    186  
    187     def setSRS(self, srs): 
    188         pass 
    189          
    190     def getGeometryType(self): 
    191         return 'point' 
    192  
    193     def setGeometryType(self, geomtype): 
    194         pass 
    195  
    196     def getSpatialCoordinates(self): 
    197         return self._primary_association.getSpatialCoordinates() 
    198  
    199     @property 
    200     def spatialCoordinates(self): 
    201         return self._primary_association.spatialCoordinates 
    202  
    203     def setGeometry(self, geomtype, coords): 
    204         raise NotImplementedError 
    205          
    206130    def isGeoreferenced(self): 
    207131        """Return True if the object is "on the map".""" 
    208132        return self._primary_association.isGeoreferenced() 
    209133 
    210     def hasPoint(self): 
    211         return self._primary_association.hasPoint() 
    212          
    213     def hasLineString(self): 
    214         return self._primary_association.hasLineString() 
     134    @property 
     135    def geom_type(self): 
     136        return self._primary_association.geom_type 
    215137 
    216     def hasPolygon(self): 
    217         return self._primary_association.hasPolygon() 
    218          
    219     def getInfo(self, dims=3): 
    220         """Return an informative dict.""" 
    221         context = self.context 
    222         info = self._primary_association.getInfo(dims) 
    223         info.update( 
    224                {'id':           context.getId(), 
    225                 'title':        context.title_or_id(), 
    226                 'description':  context.Description(), 
    227                 'url':          context.absolute_url(),} 
    228             ) 
    229         return info 
     138    @property 
     139    def coords(self): 
     140        return self._primary_association.coords 
    230141 
    231142    @property 
     
    233144        context = self.context 
    234145        return { 
     146            'type': 'Feature', 
    235147            'id': context.getId(), 
    236148            'properties': { 
     
    282194                pass 
    283195 
    284     def getItemsInfo(self): 
    285         infos = [] 
    286         for item in self.geoItems(): 
    287             infos.append(item.getInfo()) 
    288         return infos 
    289  
    290     def getBoundingBox(self): 
    291         raise NotImplementedError 
    292          
  • PleiadesEntity/trunk/tests/Entities.txt

    r746 r1225  
    6464    >>> g.isGeoreferenced() 
    6565    True 
    66     >>> info = {'srs': 'EPSG:4326', 'geometryType': 'point', 'description': '', 'spatialCoordinates': '34.7697222222 -86.4808333333 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/%s/%s' % (pid, aid), 'title': 'Civitas Non', 'id': aid} 
    67     >>> g.getInfo() == info 
    68     True 
     66    >>> gi = g.__geo_interface__ 
     67    >>> gi['type'] 
     68    'Feature' 
     69    >>> gi['geometry']['type'] 
     70    'Point' 
     71    >>> gi['geometry']['coordinates'] 
     72    (-86.480833333333294, 34.769722222222001, 0.0) 
    6973 
    7074    Place 
     
    7377    >>> g.isGeoreferenced() 
    7478    True 
    75     >>> info = {'srs': 'EPSG:4326', 'geometryType': 'point', 'description': '', 'spatialCoordinates': '34.7697222222 -86.4808333333 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/%s' % pid, 'title': 'Civitas Non', 'id': pid} 
    76     >>> g.getInfo() == info 
    77     True 
     79    >>> gi = g.__geo_interface__ 
     80    >>> gi['type'] 
     81    'Feature' 
     82    >>> gi['geometry']['type'] 
     83    'Point' 
     84    >>> gi['geometry']['coordinates'] 
     85    (-86.480833333333294, 34.769722222222001, 0.0) 
     86    >>> gi['properties']['title'] 
     87    'Civitas Non' 
    7888 
    7989    >>> c = IGeoCollectionSimple(places) 
    80     >>> c.getItemsInfo() == [{'srs': 'EPSG:4326', 'geometryType': 'point', 'description': '', 'spatialCoordinates': '34.7697222222 -86.4808333333 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/%s' % pid, 'title': 'Civitas Non', 'id': pid}] 
    81     True 
     90    >>> x = list(c.geoItems()) 
     91    >>> len(x) 
     92    1 
    8293 
  • PleiadesEntity/trunk/tests/GeoRSS_KML.txt

    r686 r1225  
    7373    <?xml version="1.0" encoding="utf-8"?> 
    7474    <feed xmlns="http://www.w3.org/2005/Atom" 
    75           xmlns:georss="http://www.georss.org/georss"> 
     75          xmlns:georss="http://www.georss.org/georss" 
     76          xmlns:gml="http://www.opengis.net/gml"> 
    7677    <BLANKLINE> 
    7778    <BLANKLINE> 
     
    9091        <updated/> 
    9192        <summary>A testing entity</summary> 
    92         <georss:point>0.0 0.0</georss:point> 
     93    <BLANKLINE> 
     94    <BLANKLINE> 
     95        <georss:where> 
     96          <gml:Point> 
     97            <gml:pos>0.000000 0.000000</gml:pos> 
     98          </gml:Point> 
     99        </georss:where> 
     100    <BLANKLINE> 
     101    <BLANKLINE> 
     102    <BLANKLINE> 
    93103      </entry> 
    94     <BLANKLINE> 
    95104    </feed> 
    96105    <BLANKLINE> 
    97106    <BLANKLINE> 
    98  
    99107 
    100108    >>> browser.open("%s/kml" % url) 
     
    106114    <BLANKLINE> 
    107115    <BLANKLINE> 
    108       <Folder> 
     116      <Document> 
     117        <Style id="defaultStyle"> 
     118          <LineStyle> 
     119            <color>ffff0000</color> 
     120            <width>2</width> 
     121          </LineStyle> 
     122          <PolyStyle> 
     123            <color>33ff0000</color> 
     124          </PolyStyle> 
     125        </Style> 
    109126        <name></name> 
    110127        <visibility>0</visibility> 
     
    124141          </description> 
    125142    <BLANKLINE> 
     143          <styleUrl>#defaultStyle</styleUrl> 
    126144    <BLANKLINE> 
    127145          <Point> 
    128             <coordinates>0.0,0.0,0.0</coordinates> 
     146            <coordinates>0.000000,0.000000,0.000000</coordinates> 
    129147          </Point> 
    130148    <BLANKLINE> 
     149    <BLANKLINE> 
     150    <BLANKLINE> 
    131151        </Placemark> 
    132       </Folder
     152      </Document
    133153    </kml> 
    134154    <BLANKLINE> 
     
    142162    <?xml version="1.0" encoding="utf-8"?> 
    143163    <feed xmlns="http://www.w3.org/2005/Atom" 
    144           xmlns:georss="http://www.georss.org/georss"> 
     164          xmlns:georss="http://www.georss.org/georss" 
     165          xmlns:gml="http://www.opengis.net/gml"> 
    145166    <BLANKLINE> 
    146167    <BLANKLINE> 
     
    159180        <updated/> 
    160181        <summary>A testing entity</summary> 
    161         <georss:point>0.0 0.0</georss:point> 
     182    <BLANKLINE> 
     183    <BLANKLINE> 
     184        <georss:where> 
     185          <gml:Point> 
     186            <gml:pos>0.000000 0.000000</gml:pos> 
     187          </gml:Point> 
     188        </georss:where> 
     189    <BLANKLINE> 
     190    <BLANKLINE> 
     191    <BLANKLINE> 
    162192      </entry> 
    163     <BLANKLINE> 
    164193    </feed> 
    165194    <BLANKLINE> 
     
    172201    <BLANKLINE> 
    173202    <BLANKLINE> 
    174       <Folder> 
     203      <Document> 
     204        <Style id="defaultStyle"> 
     205          <LineStyle> 
     206            <color>ffff0000</color> 
     207            <width>2</width> 
     208          </LineStyle> 
     209          <PolyStyle> 
     210            <color>33ff0000</color> 
     211          </PolyStyle> 
     212        </Style> 
    175213        <name>Neverpolis</name> 
    176214        <visibility>0</visibility> 
     
    190228          </description> 
    191229    <BLANKLINE> 
     230          <styleUrl>#defaultStyle</styleUrl> 
    192231    <BLANKLINE> 
    193232          <Point> 
    194             <coordinates>0.0,0.0,0.0</coordinates> 
     233            <coordinates>0.000000,0.000000,0.000000</coordinates> 
    195234          </Point> 
    196235    <BLANKLINE> 
     236    <BLANKLINE> 
     237    <BLANKLINE> 
    197238        </Placemark> 
    198       </Folder
     239      </Document
    199240    </kml> 
    200241    <BLANKLINE> 
  • PleiadesEntity/trunk/tests/LoadEntity.txt

    r1107 r1225  
    8181    ['BAtlas 65 A2 Aphrodisias/Ninoe', 'RE Aphrodisias 2', 'NPauly Aphrodisias 1', 'RE Ninoe'] 
    8282    >>> [(assoc[s.id].getItem(), assoc[s.id].getRange()) for s in srs] 
    83     [('http://www.unc.edu/awmc/pleiades/bibliography/batlas.html', '65 A2 Aphrodisias/Ninoe'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'Aphrodisias 1'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'Ninoe')] 
     83    [('http://www.unc.edu/awmc/pleiades/bibliography/batlas.html', 'BAtlas 65 A2 Aphrodisias/Ninoe'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'RE Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'NPauly Aphrodisias 1'), ('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'RE Ninoe')] 
    8484 
    8585    Test names 
     
    133133    ['RE Aphrodisias 2', 'NPauly Aphrodisias 1'] 
    134134    >>> [(n0[s.id].getItem(), n0[s.id].getRange()) for s in srs] 
    135     [('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'Aphrodisias 1')] 
     135    [('http://www.unc.edu/awmc/pleiades/bibliography/re.html', 'RE Aphrodisias 2'), ('http://www.unc.edu/awmc/pleiades/bibliography/npauly.html', 'NPauly Aphrodisias 1')] 
    136136 
    137137 
     
    259259    >>> g.isGeoreferenced() 
    260260    True 
    261     >>> g.getInfo() 
    262     {'description': 'An ancient settlement, attested during the Classical, Roman and Late Antique periods (modern location: Geyre). It was known in antiquity by the names: Aphrodisias and Ninoe.', 'spatialCoordinates': '37.7145 28.7289 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638753', 'title': 'Aphrodisias/Ninoe', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638753'} 
     261    >>> g.geom_type 
     262    'Point' 
     263    >>> g.coords 
     264    (28.728899999999999, 37.714500000000001, 0.0) 
     265    >>> gi = g.__geo_interface__ 
     266    >>> gi['type'] 
     267    'Feature' 
     268    >>> gi['properties']['title'] 
     269    'Aphrodisias/Ninoe' 
     270    >>> gi['properties']['description'] 
     271    'An ancient settlement, attested during the Classical, Roman and Late Antique periods (modern location: Geyre). It was known in antiquity by the names: Aphrodisias and Ninoe.' 
    263272 
    264273    >>> c = IGeoCollectionSimple(folder.places) 
    265     >>> c.getItemsInfo(
    266     [{'description': 'An ancient settlement, attested during the Classical, Roman and Late Antique periods (modern location: Geyre). It was known in antiquity by the names: Aphrodisias and Ninoe.', 'spatialCoordinates': '37.7145 28.7289 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638753', 'title': 'Aphrodisias/Ninoe', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638753'}] 
     274    >>> len(list(c.geoItems())
     275    1 
    267276 
    268277Load one nameless entity 
     
    294303    >>> g.isGeoreferenced() 
    295304    True 
    296     >>> g.getInfo() 
    297     {'description': 'An ancient fort, attested during the Roman period (modern location: Emeriye). Its ancient name is not known.', 'spatialCoordinates': '37.1751 31.7324 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638830', 'title': '638830', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638830'} 
    298  
    299305 
    300306Reload that entity