def test_wkt(self): l = session.query(Lake).get(1) assert session.scalar( self.r.road_geom.wkt ) == 'LINESTRING (-88.6748409363057 43.1035032292994, -88.6464173694267 42.9981688343949, -88.607961955414 42.9680732929936, -88.5160033566879 42.9363057770701, -88.4390925286624 43.0031847579618)' eq_( session.scalar(l.lake_geom.wkt), 'POLYGON ((-88.7968950764331 43.2305732929936, -88.7935511273885 43.1553344394904, -88.716640299363 43.1570064140127, -88.7250001719745 43.2339172420382, -88.7968950764331 43.2305732929936))' ) ok_(not session.query(Spot).filter( Spot.spot_location.wkt == 'POINT (0,0)').first()) ok_( session.query(Spot).get(1) is session.query(Spot).filter( Spot.spot_location == 'POINT (-88.5945861592357 42.9480095987261)').first()) r = session.query(Road).get(1) p = DBSpatialElement(session.scalar(r.road_geom.point_n(5))) eq_(session.scalar(p.wkt), u'POINT (-88.3655256496815 43.1402866687898)') eq_( session.scalar( WKTSpatialElement( 'POINT (-88.5769371859941 42.9915634871979)').wkt), u'POINT (-88.5769371859941 42.9915634871979)') eq_( session.query( Spot.spot_location.wkt).filter(Spot.spot_id == 1).first(), (u'POINT (-88.5945861592357 42.9480095987261)', ))
def test_wkb(self): eq_(session.scalar(functions.wkt(func.ST_GeomFromWKB(self.r.road_geom.wkb, 4326))), 'LINESTRING(-88.6748409363057 43.1035032292994,-88.6464173694267 42.9981688343949,-88.607961955414 42.9680732929936,-88.5160033566879 42.9363057770701,-88.4390925286624 43.0031847579618)') eq_(session.scalar(self.r.road_geom.wkb), self.r.road_geom.geom_wkb) ok_(not session.query(Spot).filter(Spot.spot_location.wkb == '101').first()) centroid_geom = DBSpatialElement(session.scalar(self.r.road_geom.centroid)) eq_(session.scalar(functions.wkt(func.ST_GeomFromWKB(centroid_geom.wkb, 4326))), 'POINT(-88.5769371859941 42.9915634871979)')
def test_reduce(self): r = session.query(Road).first() eq_( session.scalar( DBSpatialElement(session.scalar(r.road_geom.reduce(0.5))).wkt), u'LINESTRING (-88.9139332929936 42.5082802993631, -88.3655256496815 43.1402866687898)' ) eq_( session.scalar( DBSpatialElement(session.scalar( r.road_geom.reduce(0.05))).wkt), u'LINESTRING (-88.9139332929936 42.5082802993631, -88.6113059044586 42.9680732929936, -88.3655256496815 43.1402866687898)' ) eq_( session.scalar( DBSpatialElement( session.scalar(r.road_geom.reduce(0.0000000000001))).wkt), session.scalar(r.road_geom.wkt))
def test_wkb(self): eq_( b2a_hex(session.scalar(self.r.road_geom.wkb)).upper(), '010200000005000000D7DB0998302B56C0876F04983F8D45404250F5E65E2956C068CE11FFC37F4540C8ED42D9E82656C0EFC45ED3E97B45407366F132062156C036C921DED877454078A18C171A1C56C053A5AF5B68804540' ) eq_(session.scalar(self.r.road_geom.wkb), self.r.road_geom.geom_wkb) envelope_geom = DBSpatialElement( session.scalar(self.r.road_geom.envelope)) eq_( b2a_hex(session.scalar(envelope_geom.wkb)).upper(), '01030000000100000005000000D7DB0998302B56C036C921DED877454078A18C171A1C56C036C921DED877454078A18C171A1C56C0876F04983F8D4540D7DB0998302B56C0876F04983F8D4540D7DB0998302B56C036C921DED8774540' )
def test_within(self): l = session.query(Lake).filter(Lake.lake_name==u'Lake Blue').one() p1 = session.query(Spot).filter(Spot.spot_height==102.34).one() p2 = session.query(Spot).filter(Spot.spot_height==388.62).one() spots_within = session.query(Spot).filter(Spot.spot_location.within(l.lake_geom)).all() ok_(session.scalar(p1.spot_location.within(l.lake_geom))) ok_(not session.scalar(p2.spot_location.within(l.lake_geom))) ok_(p1 in spots_within) ok_(p2 not in spots_within) envelope_geom = DBSpatialElement(session.scalar(l.lake_geom.envelope)) spots_within = session.query(Spot).filter(l.lake_geom.within(envelope_geom)).all() ok_(p1 in spots_within) ok_(p2 in spots_within)
def test_wkb(self): eq_( session.scalar( functions.wkt(func.GeomFromWKB(self.r.road_geom.wkb, 4326))), 'LINESTRING(-88.674841 43.103503, -88.646417 42.998169, -88.607962 42.968073, -88.516003 42.936306, -88.439093 43.003185)' ) eq_(session.scalar(self.r.road_geom.wkb), self.r.road_geom.geom_wkb) centroid_geom = DBSpatialElement( session.scalar(self.r.road_geom.centroid)) eq_( session.scalar( functions.wkt(func.GeomFromWKB(centroid_geom.wkb, 4326))), 'POINT(-88.576937 42.991563)')
def test_make_valid(self): session.add( Shape(shape_name=u'Invalid Shape', shape_geom=WKTSpatialElement( u'LINESTRING(0 2, 1 1, 1 0, 1 1, 2 2)'))) invalid_line = session.query(Shape).filter( Shape.shape_name == u'Invalid Shape').first() eq_(session.scalar(invalid_line.shape_geom.is_valid), 0) invalid_line.shape_geom = DBSpatialElement( session.scalar(invalid_line.shape_geom.make_valid)) valid_line = session.query(Shape).filter( Shape.shape_name == u'Invalid Shape').first() eq_(session.scalar(valid_line.shape_geom.is_valid), 1)
def test_within(self): l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one() p1 = session.query(Spot).filter(Spot.spot_height==102.34).one() p2 = session.query(Spot).filter(Spot.spot_height==388.62).one() spots_within = session.query(Spot).filter(Spot.spot_location.within(l.lake_geom)).all() ok_(session.scalar(p1.spot_location.within(l.lake_geom))) ok_(not session.scalar(p2.spot_location.within(l.lake_geom))) ok_(p1 in spots_within) ok_(p2 not in spots_within) eq_(session.scalar(functions.within('LINESTRING(0 1, 2 1)', 'POLYGON((-1 -1, 3 -1, 3 2, -1 2, -1 -1))')), True) buffer_geom = DBSpatialElement(session.scalar(l.lake_geom.buffer(10.0))) spots_within = session.query(Spot).filter(l.lake_geom.within(buffer_geom)).all() ok_(p1 in spots_within) ok_(p2 in spots_within)
def test_wkb(self): eq_( session.scalar( WKBSpatialElement(session.scalar(self.r.road_geom.wkb)).wkt), u'LINESTRING (-88.6748409363057 43.1035032292994, -88.6464173694267 42.9981688343949, -88.607961955414 42.9680732929936, -88.5160033566879 42.9363057770701, -88.4390925286624 43.0031847579618)' ) eq_(session.scalar(self.r.road_geom.wkb), self.r.road_geom.geom_wkb) ok_(not session.query(Spot).filter( Spot.spot_location.wkb == '101').first()) centroid_geom = DBSpatialElement( session.scalar(session.query(Lake).first().lake_geom.centroid)) eq_( session.scalar( WKBSpatialElement(session.scalar(centroid_geom.wkb)).wkt), u'POINT (-88.757840057564835 43.193797540630335)')
def test_wkt(self): eq_( session.scalar(self.r.road_geom.wkt), 'LINESTRING(-88.674841 43.103503, -88.646417 42.998169, -88.607962 42.968073, -88.516003 42.936306, -88.439093 43.003185)' ) centroid_geom = DBSpatialElement( session.scalar(self.r.road_geom.centroid)) eq_(session.scalar(centroid_geom.wkt), 'POINT(-88.576937 42.991563)') ok_(not session.query(Spot).filter( Spot.spot_location.wkt == 'POINT(0,0)').first()) ok_( session.query(Spot).get(1) is session.query(Spot).filter( Spot.spot_location == 'POINT(-88.5945861592357 42.9480095987261)').first()) eq_( session.scalar( WKTSpatialElement( 'POINT(-88.5769371859941 42.9915634871979)').wkt), 'POINT(-88.576937 42.991563)')
def _proto_read(layer, request): """ Read features for the layer based on the request. """ if layer.public: return _get_protocol_for_layer(layer).read(request) if request.user is None: return FeatureCollection([]) user = request.user proto = _get_protocol_for_layer(layer) cls = proto.mapped_class geom_attr = proto.geom_attr ra = DBSession.query(RestrictionArea.area.collect) ra = ra.join(RestrictionArea.roles) ra = ra.join(RestrictionArea.layers) ra = ra.filter(RestrictionArea.area.area > 0) ra = ra.filter(Role.id == user.role.id) ra = ra.filter(Layer.id == layer.id).scalar() ra = DBSpatialElement(ra) filter_ = and_(create_filter(request, cls, geom_attr), ra.gcontains(getattr(cls, geom_attr))) return proto.read(request, filter=filter_)