Changeset 1307

Show
Ignore:
Timestamp:
05/06/08 17:05:00 (7 months ago)
Author:
sgillies
Message:

Switch over to single-field geometry representation using a condensed form of GeoJSON

Files:

Legend:

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

    r581 r1307  
    106106        if len(values) == 2: 
    107107            values.append('0.0') 
    108         en.setSpatialCoordinates(' '.join(values)) 
     108        en.setGeometry('Point:[%s,%s]' % (values[1], values[0]) #SpatialCoordinates(' '.join(values)) 
    109109     
    110110    # add any names as children of the entity 
  • PleiadesEntity/trunk/Extensions/loader.py

    r1249 r1307  
    6767    coords = xmlcontext.xpath( 
    6868        "adlgaz:spatialLocation/georss:point", 
    69         {'adlgaz': ADLGAZ, 'georss': GEORSS} 
     69        namespaces={'adlgaz': ADLGAZ, 'georss': GEORSS} 
    7070        )[0].text.split() 
    7171 
     
    201201    srs =  xmlcontext.find("{%s}secondaryReferences" % AWMC) 
    202202    if srs: 
    203         bibls = srs.xpath('tei:bibl', {'tei': TEI}) 
     203        bibls = srs.xpath('tei:bibl', namespaces={'tei': TEI}) 
    204204        if not bibls: 
    205205            raise EntityLoadError, "Encountered an empty secondaryReferences"  
    206206        else: 
    207207            for bibl in bibls: 
    208                 title_elem = bibl.xpath('tei:title', {'tei': TEI}) 
     208                title_elem = bibl.xpath('tei:title', namespaces={'tei': TEI}) 
    209209                if not title_elem: 
    210210                    continue 
     
    376376 
    377377    for e in root.findall("{%s}spatialLocation" % ADLGAZ): 
    378         coords = e.findall("{%s}point" % GEORSS)[0].text 
     378        coords = e.findall("{%s}point" % GEORSS)[0].text.split() 
    379379 
    380380        lid = portalcontext.invokeFactory('Location', 
    381                     geometryType='Point', 
    382                     spatialCoordinates=str(coords), 
     381                    geometry='Point:[%s,%s]' % (coords[1], coords[0]), 
    383382                    creators=creators, 
    384383                    contributors=contributors, 
  • PleiadesEntity/trunk/configure.zcml

    r1295 r1307  
    66 
    77  <!-- ##code-section configure.zcml --> 
     8  <adapter 
     9    for="Products.PleiadesEntity.content.Location.Location" 
     10    provides="zgeo.geographer.interfaces.IGeoreferenced" 
     11    factory=".geo.LocationGeoItem" 
     12    /> 
     13 
    814  <adapter 
    915    for="Products.PleiadesEntity.content.PlacefulAssociation.PlacefulAssociation" 
  • PleiadesEntity/trunk/content/Location.py

    r1244 r1307  
    2929 
    3030    StringField( 
    31         name='geometryType', 
    32         default="Point", 
    33         widget=SelectionWidget( 
    34             label="Geometry Type", 
    35             label_msgid='PleiadesEntity_label_geometryType', 
    36             i18n_domain='PleiadesEntity', 
    37         ), 
    38         enforceVocabulary=1, 
    39         vocabulary=['Point'], 
    40     ), 
    41     StringField( 
    42         name='spatialCoordinates', 
     31        name='geometry', 
    4332        widget=StringField._properties['widget']( 
    44             label="Spatial Coordinates", 
    45             description="Use GeoRSS-Simple representation.", 
    46             label_msgid='PleiadesEntity_label_spatialCoordinates', 
    47             description_msgid='PleiadesEntity_help_spatialCoordinates', 
     33            label="Geometry", 
     34            description="""Geometry using GeoJSON shorthand representation such as "Point: (-105.0, 40.0)" for a point""", 
     35            label_msgid='PleiadesEntity_label_geometry', 
     36            description_msgid='PleiadesEntity_help_geometry', 
    4837            i18n_domain='PleiadesEntity', 
    4938        ), 
     
    8271        """Return a title string derived from the geometry type.""" 
    8372        try: 
    84             return "%s %s" % (self.getGeometryType(), self.getId()) 
     73            return "%s %s" % (self.getGeometry().split(':')[0], self.getId()) 
    8574        except AttributeError: 
    8675            return 'Unidentified Location' 
  • PleiadesEntity/trunk/geo.py

    r1245 r1307  
    2929 
    3030from zope.interface import implements 
    31 from zgeo.geographer.interfaces import IGeoreferenced 
     31from zgeo.geographer.interfaces import IGeoreferenced, IWriteGeoreferenced 
     32import simplejson 
    3233 
    3334import logging 
    3435log = logging.getLogger('PleiadesEntity.geo') 
     36 
     37 
     38class LocationGeoItem(object): 
     39    implements(IGeoreferenced) 
     40 
     41    def __init__(self, context): 
     42        self.context = context 
     43 
     44    @property 
     45    def __geo_interface__(self): 
     46        """Expect getGeometry() returns a string like 
     47        'Point:[-105.0, 40.0]' 
     48        """ 
     49        d = self.context.getGeometry().split(':') 
     50        x = simplejson.loads('{"type": "%s", "coordinates": %s}' % (d[0], d[1])) 
     51        return dict(type=str(x['type']), coordinates=x['coordinates']) 
     52 
     53    @property 
     54    def type(self): 
     55        return self.__geo_interface__['type'] 
     56 
     57    @property 
     58    def coordinates(self): 
     59        return self.__geo_interface__['coordinates'] 
     60 
     61    @property 
     62    def crs(self): 
     63        return None 
     64 
    3565 
    3666class PlacefulAssociationGeoItem(object): 
     
    4272 
    4373    @property 
     74    def primary_location(self): 
     75        x = self.context.getRefs('hasLocation') 
     76        if len(x) == 0: 
     77            return None 
     78        else: 
     79            return IGeoreferenced(x[0]) 
     80 
     81    @property 
    4482    def type(self): 
    45         return 'Point' 
     83        return self.primary_location.type 
    4684 
    4785    @property 
    4886    def coordinates(self): 
    49         x = self.context.getRefs('hasLocation') 
    50         if len(x) == 0: 
    51             return () 
    52         x0 = x[0] 
    53         values = [float(v) for v in \ 
    54             x0.getSpatialCoordinates().split()] 
    55         nvalues = len(values) 
     87        return self.primary_location.coordinates 
     88        # 
     89        #x = self.context.getRefs('hasLocation') 
     90        #if len(x) == 0: 
     91        #    return () 
     92        #x0 = x[0] 
     93        #values = [float(v) for v in \ 
     94        #    x0.getSpatialCoordinates().split()] 
     95        #nvalues = len(values) 
    5696        # Our Pleiades Locations are 2D 
    57         npoints = nvalues/2 
    58         coords = [] 
    59         for i in range(npoints): 
    60             #coords.append(tuple(values[3*i:3*i+3] + [0.0])) 
    61             coords.append((values[3*i+1], values[3*i], 0.0)) 
    62         return coords[0] 
     97        #npoints = nvalues/2 
     98        #coords = [] 
     99        #for i in range(npoints): 
     100        #    #coords.append(tuple(values[3*i:3*i+3] + [0.0])) 
     101        #    coords.append((values[3*i+1], values[3*i], 0.0)) 
     102        #return coords[0] 
    63103 
    64104    @property 
     
    69109    def __geo_interface__(self): 
    70110        context = self.context 
    71         return { 
    72             'type': 'Feature', 
    73             'id': context.getId(), 
    74             'geometry': {'type': self.type, 'coordinates': self.coordinates} 
    75             } 
     111        return dict( 
     112            type='Feature', 
     113            id=context.getId(), 
     114            geometry=self.primary_location.__geo_interface__ 
     115            ) 
    76116 
    77117 
  • PleiadesEntity/trunk/profiles/default/import_steps.xml

    r1270 r1307  
    77    handler="Products.PleiadesEntity.setuphandlers.installVocabularies" 
    88    title="Install Vocabularies for PleiadesEntity" 
    9     version="2008-03-26T14:25:35.985572"> 
     9    version="2008-05-05T16:43:15.936158"> 
    1010   <dependency step="PleiadesEntity-QI-dependencies"/> 
    1111   Installs the vocabulary files into vocabulary library for PleiadesEntity 
     
    1616    handler="Products.PleiadesEntity.setuphandlers.updateRoleMappings" 
    1717    title="Update Workflow role mappings for PleiadesEntity" 
    18     version="2008-03-26T14:25:35.985572"> 
     18    version="2008-05-05T16:43:15.936158"> 
    1919   <dependency step="PleiadesEntity-QI-dependencies"/> 
    2020   updates the workflow role mappings for PleiadesEntity 
     
    2525    handler="Products.PleiadesEntity.setuphandlers.postInstall" 
    2626    title="manual coded post-install for PleiadesEntity" 
    27     version="2008-03-26T14:25:35.985572"> 
     27    version="2008-05-05T16:43:15.936158"> 
    2828   <dependency step="PleiadesEntity-QI-dependencies"/> 
    2929   manual coded post-install for PleiadesEntity 
  • PleiadesEntity/trunk/tests/Entities.txt

    r1249 r1307  
    3131    Set location coordinates 
    3232 
    33     >>> _ = x.setSpatialCoordinates('34.769722222222 -86.4808333333333 0.0') 
     33    >>> _ = x.setGeometry('Point:[-86.4808333333333, 34.769722222222]') 
    3434 
    3535Test the geo adapters 
     
    4747    'Point' 
    4848    >>> g.coordinates 
    49     (-86.480833333333294, 34.769722222222001, 0.0) 
     49    [-86.480833333333294, 34.769722222222001] 
    5050 
    5151    Place 
     
    5858    'Point' 
    5959    >>> g.coordinates 
    60     (-86.480833333333294, 34.769722222222001, 0.0) 
    61  
     60    [-86.480833333333294, 34.769722222222001] 
  • PleiadesEntity/trunk/tests/LoadEntity.txt

    r1249 r1307  
    146146    >>> lid = r['location_ids'][0] 
    147147    >>> l = getattr(folder.locations, lid) 
    148     >>> l.geometryType 
    149     u'Point' 
    150     >>> l.getGeometryType() 
    151     'Point' 
    152     >>> l.spatialCoordinates 
    153     u'37.7145 28.7289' 
    154     >>> l.getSpatialCoordinates() 
    155     '37.7145 28.7289' 
     148    >>> l.getGeometry() 
     149    'Point:[28.7289,37.7145]' 
    156150    >>> l.title_or_id() == "Point %s" % lid 
    157151    True 
  • PleiadesEntity/trunk/tests/LocationViews.txt

    r1249 r1307  
    88    >>> lid = folder.locations.invokeFactory('Location') 
    99    >>> x = getattr(folder.locations, lid) 
    10     >>> _ = x.setSpatialCoordinates('34.769722222222 -86.4808333333333 0.0') 
    11     >>> _ = x.setGeometryType('Point') 
     10    >>> _ = x.setGeometry('Point:[-86.4808333333333,34.769722222222]') 
    1211 
    1312 
     
    7574     
    7675    >>> browser.contents 
    77     '...Spatial Coordinates...34.769722222222 -86.4808333333333 0.0...' 
     76    '...Geometry...Point:[-86.4808...' 
    7877 
  • PleiadesEntity/trunk/version.txt

    r1244 r1307  
    1 0.2 build 279 
     10.2 build 280