Example #1
0
    def _handle_parameters(self):

        response = self.request.response

        # Make sure the _LOCATION_ cookie is correctly set: The old version GUI
        # version used to store the map center and the zoom level which is not
        # understood by new GUI (which stores the map extent as 4 coordinates)
        if '_LOCATION_' in self.request.cookies:
            c = urllib.unquote(self.request.cookies['_LOCATION_'])
            if len(c.split('|')) == 3:
                response.delete_cookie('_LOCATION_')

        # Check if language (_LOCALE_) is set
        if self.request is not None:
            if '_LOCALE_' in self.request.params:
                response.set_cookie('_LOCALE_', self.request.params.get(
                    '_LOCALE_'), timedelta(days=90))
            elif '_LOCALE_' in self.request.cookies:
                pass

        # Check if profile (_PROFILE_) is set
        if self.request is not None:
            if '_PROFILE_' in self.request.params:
                # Set the profile cookie
                profile_code = self.request.params.get('_PROFILE_')
                response.set_cookie(
                    '_PROFILE_', profile_code, timedelta(days=90))

                # Update _LOCATION_ from cookies to profile geometry bbox
                # retrieved from database
                profile_db = DBSession.query(Profile).\
                    filter(Profile.code == profile_code).\
                    first()

                if profile_db is not None:
                    # Calculate and transform bounding box
                    bbox = DBSession.scalar(geofunctions.envelope(
                        geofunctions.transform(
                            profile_db.geometry, '900913')).wkt)

                    geojson = utils.from_wkt(bbox)

                    coords = geojson['coordinates'][0]
                    p1 = coords[0]
                    p2 = coords[2]

                    l = '%s,%s' % (','.join([str(x) for x in p1]),
                        ','.join([str(x) for x in p2]))

                    response.set_cookie(
                        '_LOCATION_', urllib.quote(l), timedelta(days=90))

            elif '_PROFILE_' in self.request.cookies:
                # Profile already set, leave it
                pass
            else:
                # If no profile is set, set the default profile
                response.set_cookie('_PROFILE_', get_default_profile(
                    self.request), timedelta(days=90))
Example #2
0
 def test_envelope(self):
     r = session.query(Road).filter(Road.road_name=='Graeme Ave').one()
     eq_(session.scalar(functions.wkt(r.road_geom.envelope)),
         u'POLYGON ((-88.6096339299363 42.6988853949045, -88.5477708726115 42.6988853949045, -88.5477708726115 43.187101955414, -88.6096339299363 43.187101955414, -88.6096339299363 42.6988853949045))')
     eq_(session.scalar(functions.geometry_type(self.r.road_geom.envelope)), u'ST_POLYGON')
     ok_(session.query(Spot).filter(functions.wkt(Spot.spot_location.envelope) == 'POINT (-88.5945861592357 42.9480095987261)').first() is not None)
     eq_(session.scalar(functions.wkt(functions.envelope(WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)', geometry_type=Point.name)))),
         u'POINT (-88.5945861592357 42.9480095987261)')
Example #3
0
 def test_envelope(self):
     r = session.query(Road).filter(Road.road_name=='Graeme Ave').one()
     eq_(session.scalar(functions.wkt(r.road_geom.envelope)),
         'POLYGON ((-88.6096339299363 42.6988853949045, -88.5477708726115 42.6988853949045, -88.5477708726115 43.187101955414, -88.6096339299363 43.187101955414, -88.6096339299363 42.6988853949045))')
     eq_(session.scalar(functions.geometry_type(self.r.road_geom.envelope)), 'Polygon')
     ok_(session.query(Spot).filter(Spot.spot_location.envelope == WKTSpatialElement('POLYGON ((-88.9055744203822 43.0048557324841, -88.9055724203822 43.0048557324841, -88.9055724203822 43.0048577324841, -88.9055744203822 43.0048577324841, -88.9055744203822 43.0048557324841))')).first() is not None)
     eq_(session.scalar(functions.wkt(functions.envelope('POINT(-88.5945861592357 42.9480095987261)'))),
         'POLYGON ((-88.5945871592357 42.948008598726105, -88.5945851592357 42.948008598726105, -88.5945851592357 42.9480105987261, -88.5945871592357 42.9480105987261, -88.5945871592357 42.948008598726105))')
 def test_envelope(self):
     r = session.query(Road).filter(Road.road_name=='Graeme Ave').one()
     eq_(session.scalar(functions.wkt(r.road_geom.envelope)), 
         u'POLYGON((-88.6096343994141 42.6988830566406,-88.6096343994141 43.1871032714844,-88.5477676391602 43.1871032714844,-88.5477676391602 42.6988830566406,-88.6096343994141 42.6988830566406))')
     eq_(session.scalar(functions.geometry_type(self.r.road_geom.envelope)), 'ST_Polygon')
     ok_(session.query(Spot).filter(Spot.spot_location.envelope == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is not None)
     eq_(session.scalar(functions.wkt(functions.envelope('POINT(-88.5945861592357 42.9480095987261)'))), 
         u'POINT(-88.5945861592357 42.9480095987261)')
Example #5
0
 def test_envelope(self):
     r = session.query(Road).filter(Road.road_name=='Graeme Ave').one()
     eq_(session.scalar(functions.wkt(r.road_geom.envelope)),
         'POLYGON((-88.6096339299363 42.6988853949045,-88.6096339299363 43.187101955414,-88.5477708726115 43.187101955414,-88.5477708726115 42.6988853949045,-88.6096339299363 42.6988853949045))')
     eq_(session.scalar(functions.geometry_type(self.r.road_geom.envelope)), 'ST_Polygon')
     ok_(session.query(Spot).filter(Spot.spot_location.envelope == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is not None)
     eq_(session.scalar(functions.wkt(functions.envelope('POINT(-88.5945861592357 42.9480095987261)'))),
         'POINT(-88.5945861592357 42.9480095987261)')
Example #6
0
 def test_envelope(self):
     eq_(
         b2a_hex(session.scalar(self.r.road_geom.envelope)),
         'e610000001030000000100000005000000d7db0998302b56c036c921ded877454078a18c171a1c56c036c921ded877454078a18c171a1c56c0876f04983f8d4540d7db0998302b56c0876f04983f8d4540d7db0998302b56c036c921ded8774540'
     )
     env = WKBSpatialElement(
         session.scalar(func.AsBinary(self.r.road_geom.envelope)))
     eq_(env.geom_type(session), 'Polygon')
     eq_(
         session.scalar(
             functions.wkt(
                 functions.envelope(
                     'POINT(-88.5945861592357 42.9480095987261)'))),
         'POLYGON((-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261))'
     )
Example #7
0
 def test_envelope(self):
     eq_(b2a_hex(session.scalar(self.r.road_geom.envelope)), 'e610000001030000000100000005000000d7db0998302b56c036c921ded877454078a18c171a1c56c036c921ded877454078a18c171a1c56c0876f04983f8d4540d7db0998302b56c0876f04983f8d4540d7db0998302b56c036c921ded8774540')
     env =  WKBSpatialElement(session.scalar(func.AsBinary(self.r.road_geom.envelope)))
     eq_(env.geom_type(session), 'Polygon')
     eq_(session.scalar(functions.wkt(functions.envelope('POINT(-88.5945861592357 42.9480095987261)'))),
         'POLYGON((-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261,-88.5945861592357 42.9480095987261))')