Changeset 1432

Show
Ignore:
Timestamp:
09/18/08 17:07:12 (2 months ago)
Author:
sgillies
Message:

Add a transform class using pyproj

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pleiades.openlayers/trunk/pleiades/openlayers/browser.py

    r1429 r1432  
    11import os 
    22from shapely.geometry import asShape 
     3from pyproj import Proj 
    34from zope.publisher.browser import BrowserPage 
    45from zgeo.geographer.interfaces import IGeoreferenced 
    56 
    67 
    7 class PlaceOLJS(BrowserPage): 
     8PROJ_900913 = """ 
     9+proj=merc +a=6378137 +b=6378137 
     10+lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 
     11+units=m +nadgrids=@null +no_defs 
     12""" 
    813 
     14class OLSphericalMercatorJS(BrowserPage): 
     15    """Returns coordinates projected to Spherical Mercator for use with  
     16    Google Maps. 
     17    """ 
    918    def __call__(self): 
    1019        response = self.request.response 
    1120        geo = IGeoreferenced(self.context) 
     21         
     22        # Project the geo coordinates 
     23        proj_sm = Proj(PROJ_900913) 
    1224        if geo.type == 'Point': 
    13             centroid = geo 
     25            x, y = proj_sm(*tuple(geo.coordinates)) 
     26            where = dict(type=geo.type, coordinates=[x, y]) 
     27            centroid = where 
    1428        else: 
    15             shape = asShape(geo) 
    16             centroid = shape.centroid 
     29            #shape = asShape(geo) 
     30            #centroid = shape.centroid 
     31            raise NotImplemented, "Points only in this version" 
     32 
    1733        response.setHeader('Content-Type', 'text/javascript') 
    1834        return """ 
     
    2137        """ % dict( 
    2238                uid=self.context.UID(), 
    23                 where=dict(type=geo.type, coordinates=geo.coordinates)
    24                 centroid=centroid.__geo_interface__['geometry'] 
     39                where=where
     40                centroid=centroid 
    2541                ) 
    2642 
     
    3248    def __call__(self): 
    3349        return GMAPS_KEY 
     50 
     51 
     52class EditGeo(BrowserPage): 
     53    pass 
     54     
  • pleiades.openlayers/trunk/pleiades/openlayers/configure.zcml

    r1429 r1432  
    1010    for="Products.PleiadesEntity.content.interfaces.IPlace" 
    1111    name="ol.js" 
    12     class=".browser.PlaceOLJS" 
     12    class=".browser.OLSphericalMercatorJS" 
    1313    permission="zope2.View" 
    1414    /> 
     
    2121    /> 
    2222 
     23  <browser:page 
     24    for="Products.PleiadesEntity.content.interfaces.ILocation" 
     25    name="edit-geo" 
     26    class=".browser.EditGeo" 
     27    permission="cmf.ModifyPortalContent" 
     28    /> 
     29 
    2330</configure> 
  • pleiades.openlayers/trunk/setup.py

    r1429 r1432  
    2727      install_requires=[ 
    2828          'setuptools', 
    29           # -*- Extra requirements: -*- 
     29          'geojson', 
     30          'pyproj' 
    3031      ], 
    3132      entry_points="""