Example #1
0
    def _within_distance(compiler, geom1, geom2, distance, *args):
        """MySQL does not support the function distance, so we are doing
        a kind of "mbr_within_distance". The MBR of 'geom2' is expanded with
        the amount of 'distance' by manually changing the coordinates.
        Then we test if 'geom1' intersects this expanded MBR.
        """
        mbr = func.ExteriorRing(func.Envelope(geom2))

        lower_left = func.StartPoint(mbr)
        upper_right = func.PointN(mbr, 3)

        xmin = func.X(lower_left)
        ymin = func.Y(lower_left)
        xmax = func.X(upper_right)
        ymax = func.Y(upper_right)

        return func.Intersects(
            geom1,
            func.GeomFromText(
                func.Concat('Polygon((', xmin - distance, ' ', ymin - distance,
                            ',', xmax + distance, ' ', ymin - distance, ',',
                            xmax + distance, ' ', ymax + distance, ',',
                            xmin - distance, ' ', ymax + distance, ',',
                            xmin - distance, ' ', ymin - distance, '))'),
                func.srid(geom2)))
Example #2
0
 def test_centroid(self):
     l = session.query(Lake).get(1)
     r = session.query(Road).get(1)
     s = session.query(Spot).get(1)
     assert_almost_equal(session.scalar(func.X(l.lake_geom.centroid)),
                         -88.7578400578)
     assert_almost_equal(session.scalar(func.Y(l.lake_geom.centroid)),
                         43.1937975407)
     #eq_(b2a_hex(session.scalar(l.lake_geom.centroid)), '0001ffffffff81ec9573803056c04bc4995bce98454081ec9573803056c04bc4995bce9845407c0100000081ec9573803056c04bc4995bce984540fe')
     assert_almost_equal(session.scalar(func.X(r.road_geom.centroid)),
                         -88.6569666079)
     assert_almost_equal(session.scalar(func.Y(r.road_geom.centroid)),
                         42.8422057576)
     #eq_(b2a_hex(session.scalar(r.road_geom.centroid)), '0001ffffffff1cecabbd0b2a56c022b0f465cd6b45401cecabbd0b2a56c022b0f465cd6b45407c010000001cecabbd0b2a56c022b0f465cd6b4540fe')
     assert_almost_equal(session.scalar(func.X(s.spot_location.centroid)),
                         -88.5945861592)
     assert_almost_equal(session.scalar(func.Y(s.spot_location.centroid)),
                         42.9480095987)
Example #3
0
 def test_end_point(self):
     l = session.query(Lake).get(1)
     r = session.query(Road).get(1)
     s = session.query(Spot).get(1)
     ok_(not session.scalar(l.lake_geom.end_point))
     assert_almost_equal(session.scalar(func.X(r.road_geom.end_point)),
                         -88.3655256496815)
     assert_almost_equal(session.scalar(func.Y(r.road_geom.end_point)),
                         43.1402866687898)
     #eq_(b2a_hex(session.scalar(r.road_geom.end_point)), '0001ffffffffccceb1c5641756c02c42dfe9f4914540ccceb1c5641756c02c42dfe9f49145407c01000000ccceb1c5641756c02c42dfe9f4914540fe')
     ok_(not session.scalar(s.spot_location.end_point))
Example #4
0
 def test_start_point(self):
     l = session.query(Lake).get(1)
     r = session.query(Road).get(1)
     s = session.query(Spot).get(1)
     ok_(not session.scalar(l.lake_geom.start_point))
     assert_almost_equal(session.scalar(func.X(r.road_geom.start_point)),
                         -88.9139332929936)
     assert_almost_equal(session.scalar(func.Y(r.road_geom.start_point)),
                         42.5082802993631)
     #eq_(b2a_hex(session.scalar(r.road_geom.start_point)), '0001ffffffff850811e27d3a56c0997b2f540f414540850811e27d3a56c0997b2f540f4145407c01000000850811e27d3a56c0997b2f540f414540fe')
     ok_(not session.scalar(s.spot_location.start_point))