示例#1
0
 def test_contains(self):
     l = session.query(Lake).filter(Lake.lake_name == 'Lake Blue').one()
     l1 = session.query(Lake).filter(Lake.lake_name == 'Lake White').one()
     p1 = session.query(Spot).filter(Spot.spot_height == 102.34).one()
     p2 = session.query(Spot).filter(Spot.spot_height == 388.62).one()
     containing_lakes = session.query(Lake).filter(
         Lake.lake_geom.gcontains(p1.spot_location)).all()
     ok_(session.scalar(l.lake_geom.gcontains(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.gcontains(p2.spot_location)))
     ok_(l in containing_lakes)
     ok_(l1 not in containing_lakes)
     ok_(
         session.scalar(
             l.lake_geom.gcontains(
                 WKTSpatialElement(
                     'POINT(-88.9055734203822 43.0048567324841)'))))
     containing_lakes = session.query(Lake).filter(
         Lake.lake_geom.gcontains(
             'POINT(-88.9055734203822 43.0048567324841)')).all()
     ok_(l in containing_lakes)
     ok_(l1 not in containing_lakes)
     spots_within = session.query(Spot).filter(
         l.lake_geom.gcontains(Spot.spot_location)).all()
     ok_(session.scalar(l.lake_geom.gcontains(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.gcontains(p2.spot_location)))
     ok_(p1 in spots_within)
     ok_(p2 not in spots_within)
     eq_(
         session.scalar(
             functions.gcontains(
                 'LINESTRING(0 1, 2 1)',
                 'POLYGON((-1 -1, 3 -1, 3 2, -1 2, -1 -1))')), False)
示例#2
0
 def test_contains(self):
     l = session.query(Lake).filter(Lake.lake_name == "Lake Blue").one()
     l1 = session.query(Lake).filter(Lake.lake_name == "Lake White").one()
     p1 = session.query(Spot).filter(Spot.spot_height == 102.34).one()
     p2 = session.query(Spot).filter(Spot.spot_height == 388.62).one()
     containing_lakes = session.query(Lake).filter(Lake.lake_geom.gcontains(p1.spot_location)).all()
     ok_(session.scalar(l.lake_geom.gcontains(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.gcontains(p2.spot_location)))
     ok_(l in containing_lakes)
     ok_(l1 not in containing_lakes)
     ok_(session.scalar(l.lake_geom.gcontains(WKTSpatialElement("POINT(-88.9055734203822 43.0048567324841)"))))
     containing_lakes = (
         session.query(Lake).filter(Lake.lake_geom.gcontains("POINT(-88.9055734203822 43.0048567324841)")).all()
     )
     ok_(l in containing_lakes)
     ok_(l1 not in containing_lakes)
     spots_within = session.query(Spot).filter(l.lake_geom.gcontains(Spot.spot_location)).all()
     ok_(session.scalar(l.lake_geom.gcontains(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.gcontains(p2.spot_location)))
     ok_(p1 in spots_within)
     ok_(p2 not in spots_within)
     eq_(
         session.scalar(functions.gcontains("LINESTRING(0 1, 2 1)", "POLYGON((-1 -1, 3 -1, 3 2, -1 2, -1 -1))")),
         False,
     )
示例#3
0
    def by_location(cls, location):
        location = func.ST_MakePoint(location.longitude, location.latitude)
        filter = functions.gcontains(cls.the_geom, location)
        zone = DBSession.query(cls.tzid).filter(filter).scalar()
        if zone is None:
            return None

        return timezone(unicode(zone))
示例#4
0
 def test_covers(self):
     l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one()
     l1 = session.query(Lake).filter(Lake.lake_name=='Lake White').one()
     p1 = session.query(Spot).filter(Spot.spot_height==102.34).one()
     p2 = session.query(Spot).filter(Spot.spot_height==388.62).one()
     covering_lakes = session.query(Lake).filter(Lake.lake_geom.covers(p1.spot_location)).all()
     ok_(session.scalar(l.lake_geom.covers(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.covers(p2.spot_location)))
     ok_(l in covering_lakes)
     ok_(l1 not in covering_lakes)
     eq_(session.scalar(functions.gcontains('LINESTRING(0 1, 2 1)', 'POLYGON((-1 -1, 3 -1, 3 2, -1 2, -1 -1))')), False)
示例#5
0
 def test_covers(self):
     l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one()
     l1 = session.query(Lake).filter(Lake.lake_name=='Lake White').one()
     p1 = session.query(Spot).filter(Spot.spot_height==102.34).one()
     p2 = session.query(Spot).filter(Spot.spot_height==388.62).one()
     covering_lakes = session.query(Lake).filter(Lake.lake_geom.covers(p1.spot_location)).all()
     ok_(session.scalar(l.lake_geom.covers(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.covers(p2.spot_location)))
     ok_(l in covering_lakes)
     ok_(l1 not in covering_lakes)
     eq_(session.scalar(functions.gcontains('LINESTRING(0 1, 2 1)', 'POLYGON((-1 -1, 3 -1, 3 2, -1 2, -1 -1))')), False)
示例#6
0
 def test_contains(self):
     l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one()
     l1 = session.query(Lake).filter(Lake.lake_name=='Lake White').one()
     p1 = session.query(Spot).get(2)
     p2 = session.query(Spot).get(3)
     containing_lakes = session.query(Lake).filter(Lake.lake_geom.gcontains(p1.spot_location)).all()
     ok_(session.scalar(l.lake_geom.gcontains(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.gcontains(p2.spot_location)))
     ok_(l in containing_lakes)
     ok_(l1 not in containing_lakes)
     ok_(session.scalar(l.lake_geom.gcontains(WKTSpatialElement('POINT(-88.9055734203822 43.0048567324841)'))))
     containing_lakes = session.query(Lake).filter(Lake.lake_geom.gcontains('POINT(-88.9055734203822 43.0048567324841)')).all()
     ok_(l in containing_lakes)
     ok_(l1 not in containing_lakes)
     spots_within = session.query(Spot).filter(l.lake_geom.gcontains(Spot.spot_location)).all()
     ok_(session.scalar(l.lake_geom.gcontains(p1.spot_location)))
     ok_(not session.scalar(l.lake_geom.gcontains(p2.spot_location)))
     ok_(p1 in spots_within)
     ok_(p2 not in spots_within)
     eq_(session.scalar(functions.gcontains('LINESTRING(0 1, 2 1)', 'POLYGON((-1 -1, 3 -1, 3 2, -1 2, -1 -1))')), False)