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_transform(self): spot = session.query(Spot).get(1) eq_(session.scalar(functions.wkt(spot.spot_location.transform(2249))), u"POINT(-3890517.610956 3627658.674651)") ok_( session.query(Spot) .filter( sqlite_functions.mbr_contains( functions.buffer(Spot.spot_location.transform(2249), 10), WKTSpatialElement("POINT(-3890517.610956 3627658.674651)", 2249), ) ) .first() is not None ) eq_( session.scalar( functions.wkt( functions.transform( WKTSpatialElement( "POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))", 2249, ), 4326, ) ) ), u"POLYGON((-71.177685 42.39029, -71.177684 42.390383, -71.177584 42.390383, -71.177583 42.390289, -71.177685 42.39029))", )
def test_centroid(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one() ok_(not session.scalar(functions.wkt(r.road_geom.centroid))) eq_(session.scalar(functions.wkt(l.lake_geom.centroid)), 'POINT (-88.921453826951719 43.019149768468026)') ok_(session.query(Spot).filter(Spot.spot_location.centroid == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is None) ok_(session.scalar(functions.wkt(functions.centroid('MULTIPOINT ( -1 0, -1 2, -1 3, -1 4, -1 7, 0 1, 0 3, 1 1, 2 0, 6 0, 7 8, 9 8, 10 6 )'))) is None)
def test_convex_hull(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.convex_hull)), u'POLYGON((-88.5477708726115 42.6988853949045,-88.6096339299363 42.9697452675159,-88.6029460318471 43.0884554585987,-88.5912422101911 43.187101955414,-88.5477708726115 42.6988853949045))') ok_(session.query(Spot).filter(Spot.spot_location.convex_hull == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is not None) eq_(session.scalar(functions.wkt(functions.convex_hull('POINT(-88.5945861592357 42.9480095987261)'))), u'POINT(-88.5945861592357 42.9480095987261)')
def test_end_point(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.end_point)), 'POINT (-88.5912422101911 43.187101955414)') ok_(session.query(Road).filter(Road.road_geom.end_point == WKTSpatialElement('POINT(-88.3655256496815 43.1402866687898)')).first() is not None) eq_(session.scalar(functions.wkt(functions.end_point('LINESTRING(0 1, 0 2)'))), 'POINT (0 2)')
def test_convex_hull(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.convex_hull)), 'POLYGON ((-88.547770872712135 42.698885396122932, -88.5912422100082 43.187101952731609, -88.602946031838655 43.088455460965633, -88.609633930027485 42.969745270907879, -88.547770872712135 42.698885396122932))') ok_(session.query(Spot).filter(Spot.spot_location.convex_hull == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is not None) eq_(session.scalar(functions.wkt(functions.convex_hull('POINT(-88.5945861592357 42.9480095987261)'))), 'POINT (-88.594586159235689 42.948009598726117)')
def test_wkb(self): eq_(session.scalar(functions.wkt(func.ST_GeomFromWKB(self.r.road_geom.wkb, 4326))), 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(self.r.road_geom.centroid)) eq_(session.scalar(functions.wkt(func.ST_GeomFromWKB(centroid_geom.wkb, 4326))), u'POINT(-88.5769371859941 42.9915634871979)')
def test_start_point(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.start_point)), 'POINT(-88.5477708726115 42.6988853949045)') ok_(session.query(Road).filter(Road.road_geom.start_point == WKTSpatialElement('POINT(-88.9139332929936 42.5082802993631)')).first() is not None) eq_(session.scalar(functions.wkt(functions.start_point('LINESTRING(0 1, 0 2)'))), 'POINT(0 1)')
def test_end_point(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.end_point)), 'POINT(-88.5912422101911 43.187101955414)') ok_(session.query(Road).filter(Road.road_geom.end_point == WKTSpatialElement('POINT(-88.3655256496815 43.1402866687898)')).first() is not None) eq_(session.scalar(functions.wkt(functions.end_point('LINESTRING(0 1, 0 2)'))), 'POINT(0 2)')
def test_convex_hull(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.convex_hull)), 'POLYGON((-88.5477708726115 42.6988853949045,-88.6096339299363 42.9697452675159,-88.6029460318471 43.0884554585987,-88.5912422101911 43.187101955414,-88.5477708726115 42.6988853949045))') ok_(session.query(Spot).filter(Spot.spot_location.convex_hull == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is not None) eq_(session.scalar(functions.wkt(functions.convex_hull('POINT(-88.5945861592357 42.9480095987261)'))), '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_start_point(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.start_point)), 'POINT (-88.5477708726115 42.6988853949045)') ok_(session.query(Road).filter(Road.road_geom.start_point == WKTSpatialElement('POINT(-88.9139332929936 42.5082802993631)')).first() is not None) eq_(session.scalar(functions.wkt(functions.start_point('LINESTRING(0 1, 0 2)'))), 'POINT (0 1)')
def test_point_n(self): l = session.query(Lake).get(1) r = session.query(Road).get(1) ok_(session.scalar(l.lake_geom.point_n(1))) ok_(session.query(Road).filter(Road.road_geom.point_n(5) == WKTSpatialElement('POINT(-88.3655256496815 43.1402866687898)')).first() is not None) eq_(session.scalar(functions.wkt(r.road_geom.point_n(5))), 'POINT (-88.3655256496815 43.1402866687898)') eq_(session.scalar(functions.wkt(functions.point_n('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)', 1))) , 'POINT (77.29 29.07)')
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)')
def test_centroid(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one() eq_(session.scalar(functions.wkt(r.road_geom.centroid)), 'POINT(-88.5889975373709 42.941769988935)') eq_(session.scalar(functions.wkt(l.lake_geom.centroid)), 'POINT(-88.9214538261088 43.0191497691548)') ok_(session.query(Spot).filter(Spot.spot_location.centroid == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is not None) eq_(session.scalar(functions.wkt(functions.centroid('MULTIPOINT ( -1 0, -1 2, -1 3, -1 4, -1 7, 0 1, 0 3, 1 1, 2 0, 6 0, 7 8, 9 8, 10 6 )'))), 'POINT(2.30769230769231 3.30769230769231)')
def test_transform(self): spot = session.query(Spot).get(1) # note that we have to cast to 'ST_POINT', because 'functions.x' only works for Points in Oracle assert_almost_equal(float(session.scalar(functions.x(func.ST_POINT(spot.spot_location.transform(2249))))), -3890517.61088792) assert_almost_equal(float(session.scalar(functions.y(func.ST_POINT(spot.spot_location.transform(2249))))), 3627658.6749871401) ok_(session.query(Spot).filter(functions.wkt(Spot.spot_location.transform(2249)) == 'POINT (-3890517.61088792 3627658.67498714)').first() is not None) eq_(session.scalar(functions.wkt(functions.transform(WKTSpatialElement('POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))', 2249), 4326))), u'POLYGON ((-71.1776848522252 42.3902896503503, -71.1776843766327 42.390382946861, -71.1775844305466 42.3903826668518, -71.1775825927231 42.3902893638588, -71.1776848522252 42.3902896503503))')
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)')
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)')
def test_intersection(self): l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one() s = session.query(Spot).get(4) eq_(session.scalar(functions.wkt(l.lake_geom.intersection(s.spot_location, tolerance, auto_diminfo=False))), None) l = session.query(Lake).filter(Lake.lake_name=='Lake White').one() r = session.query(Road).filter(Road.road_name=='Paul St').one() eq_(session.scalar(functions.wkt(l.lake_geom.intersection(r.road_geom))), u'LINESTRING (-88.1430664921296 42.6255530821991, -88.114084510211 42.6230683849207)') ok_(session.query(Lake).filter(functions.equals(Lake.lake_geom.intersection(r.road_geom), WKTSpatialElement('LINESTRING(-88.1430664921296 42.6255530821991, -88.114084510211 42.6230683849207)'))).first() is not None)
def test_centroid(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one() eq_(session.scalar(functions.wkt(r.road_geom.centroid)), u'POINT(-88.5889975373709 42.941769988935)') eq_(session.scalar(functions.wkt(l.lake_geom.centroid)), u'POINT(-88.9214538261088 43.0191497691548)') ok_(session.query(Spot).filter(Spot.spot_location.centroid == WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)')).first() is not None) eq_(session.scalar(functions.wkt(functions.centroid('MULTIPOINT ( -1 0, -1 2, -1 3, -1 4, -1 7, 0 1, 0 3, 1 1, 2 0, 6 0, 7 8, 9 8, 10 6 )'))), u'POINT(2.30769230769231 3.30769230769231)')
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_centroid(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one() # Oracle does not support centroid for LineString eq_(session.scalar(functions.wkt(r.road_geom.centroid)), None) eq_(session.scalar(functions.wkt(l.lake_geom.centroid)), u'POINT (-88.9213649409212 43.0190392609092)') ok_(session.query(Spot).filter(functions.wkt(Spot.spot_location.centroid) == 'POINT (-88.5945861592357 42.9480095987261)').first() is not None) eq_(session.scalar(functions.wkt(functions.centroid('MULTIPOINT((-1 0), (-1 2), (-1 3), (-1 4), (-1 7), (0 1), (0 3), (1 1), (2 0), (6 0), (7 8), (9 8), (10 6) )', diminfo_))), u'POINT (2.30460703912783 3.31788085910597)')
def test_convex_hull(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.convex_hull)), u'POLYGON ((-88.5477708728477 42.6988853969538, -88.5912422100661 43.1871019533972, -88.6029460317718 43.0884554581896, -88.6096339299412 42.9697452675198, -88.5477708728477 42.6988853969538))') # Oracle does not support ConvexHull for points ok_(session.query(Spot).filter(functions.equals(Spot.spot_location.convex_hull, WKTSpatialElement('POINT(-88.5945861592357 42.9480095987261)'))).first() is None) eq_(session.scalar(functions.wkt(functions.convex_hull('LINESTRING(0 0, 1 1, 1 0)', diminfo_))), u'POLYGON ((0.999999915732742 8.48487373222706E-8, 0.999999915755202 0.999999915201249, 8.4273559349594E-8 8.48422467917753E-8, 0.999999915732742 8.48487373222706E-8))')
def test_point_n(self): r = session.query(Road).get(1) ok_(session.query(Road).filter(and_(Road.road_geom.point_n(5) <> None, functions.wkt(Road.road_geom.point_n(5)) == 'POINT (-88.3655256496815 43.1402866687898)')).first() is not None) eq_(session.scalar(r.road_geom.point_n(5).wkt), u'POINT (-88.3655256496815 43.1402866687898)') eq_(session.scalar(functions.wkt(functions.point_n( WKTSpatialElement('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)', geometry_type=LineString.name), 1))), u'POINT (77.29 29.07)')
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_transform(self): spot = session.query(Spot).get(1) # compare the coordinates using a tolerance, because they may vary on different systems assert_almost_equal(session.scalar(functions.x(spot.spot_location.transform(2249))), -3890517.6109559298) assert_almost_equal(session.scalar(functions.y(spot.spot_location.transform(2249))), 3627658.6746507999) ok_( session.query(Spot) .filter( Spot.spot_location.transform(2249) == WKTSpatialElement("POINT(-3890517.61095593 3627658.6746508)", 2249) ) .first() is not None ) eq_( session.scalar( functions.wkt( functions.transform( WKTSpatialElement( "POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))", 2249, ), 4326, ) ) ), u"POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.1776848522251 42.3902896512902))", )
def test_envelope(self): eq_( session.scalar(functions.wkt(self.r.road_geom.envelope)), u"POLYGON((-88.674841 42.936306, -88.439093 42.936306, -88.439093 43.103503, -88.674841 43.103503, -88.674841 42.936306))", ) env = WKBSpatialElement(session.scalar(func.AsBinary(self.r.road_geom.envelope))) eq_(env.geom_type(session), "Polygon")
def test_centroid(self): r = session.query(Road).filter(Road.road_name == 'Graeme Ave').one() l = session.query(Lake).filter(Lake.lake_name == 'Lake Blue').one() ok_(not session.scalar(functions.wkt(r.road_geom.centroid))) eq_(session.scalar(functions.wkt(l.lake_geom.centroid)), u'POINT (-88.921453826951719 43.019149768468026)') ok_( session.query(Spot). filter(Spot.spot_location.centroid == WKTSpatialElement( 'POINT(-88.5945861592357 42.9480095987261)')).first() is None) ok_( session.scalar( functions.wkt( functions.centroid( 'MULTIPOINT ( -1 0, -1 2, -1 3, -1 4, -1 7, 0 1, 0 3, 1 1, 2 0, 6 0, 7 8, 9 8, 10 6 )' ))) is None)
def test_boundary(self): r = session.query(Road).filter(Road.road_name == 'Graeme Ave').one() eq_( session.scalar(functions.wkt(r.road_geom.boundary)), u'MULTIPOINT ((-88.5912422100082 43.187101952731609), (-88.547770872712135 42.698885396122932))' ) ok_( session.query(Road). filter(Road.road_geom.boundary == WKTSpatialElement( 'MULTIPOINT ((-88.5912422100082 43.187101952731609), (-88.547770872712135 42.698885396122932))' )).first() is not None) eq_( session.scalar( functions.wkt( functions.boundary('POLYGON((1 1,0 0, -1 1, 1 1))'))), u'LINESTRING (0 0, 1 1, -1 1, 0 0)')
def test_boundary(self): r = session.query(Road).filter(Road.road_name == 'Graeme Ave').one() eq_( session.scalar(functions.wkt(r.road_geom.boundary)), u'MULTIPOINT(-88.5477708726115 42.6988853949045,-88.5912422101911 43.187101955414)' ) ok_( session.query(Road). filter(Road.road_geom.boundary == WKTSpatialElement( 'MULTIPOINT(-88.9139332929936 42.5082802993631,-88.3655256496815 43.1402866687898)' )).first() is not None) eq_( session.scalar( functions.wkt( functions.boundary('POLYGON((1 1,0 0, -1 1, 1 1))'))), u'LINESTRING(1 1,0 0,-1 1,1 1)')
def test_transform(self): spot = session.query(Spot).get(1) # compare the coordinates using a tolerance, because they may vary on different systems assert_almost_equal(session.scalar(functions.x(spot.spot_location.transform(2249))), -3890517.6109559298) assert_almost_equal(session.scalar(functions.y(spot.spot_location.transform(2249))), 3627658.6746507999) ok_(session.query(Spot).filter(Spot.spot_location.transform(2249).wkt == 'POINT(-3890517.61095593 3627658.6746508)').first() is not None) eq_(session.scalar(functions.wkt(functions.transform(WKTSpatialElement('POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))', 2249), 4326))), 'POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.1776848522251 42.3902896512902))')
def test_convex_hull(self): r = session.query(Road).filter(Road.road_name == 'Graeme Ave').one() eq_( session.scalar(functions.wkt(r.road_geom.convex_hull)), u'POLYGON ((-88.547770872712135 42.698885396122932, -88.5912422100082 43.187101952731609, -88.602946031838655 43.088455460965633, -88.609633930027485 42.969745270907879, -88.547770872712135 42.698885396122932))' ) ok_( session.query(Spot).filter( Spot.spot_location.convex_hull == WKTSpatialElement( 'POINT(-88.5945861592357 42.9480095987261)')).first() is not None) eq_( session.scalar( functions.wkt( functions.convex_hull( 'POINT(-88.5945861592357 42.9480095987261)'))), u'POINT (-88.594586159235689 42.948009598726117)')
def test_envelope(self): eq_( session.scalar(functions.wkt(self.r.road_geom.envelope)), 'POLYGON((-88.674841 42.936306, -88.439093 42.936306, -88.439093 43.103503, -88.674841 43.103503, -88.674841 42.936306))' ) env = WKBSpatialElement( session.scalar(func.AsBinary(self.r.road_geom.envelope))) eq_(env.geom_type(session), 'Polygon')
def test_point_n(self): l = session.query(Lake).get(1) r = session.query(Road).get(1) ok_(session.scalar(l.lake_geom.point_n(1))) ok_( session.query(Road).filter( Road.road_geom.point_n(5) == WKTSpatialElement( 'POINT(-88.3655256496815 43.1402866687898)')).first() is not None) eq_(session.scalar(functions.wkt(r.road_geom.point_n(5))), u'POINT (-88.3655256496815 43.1402866687898)') eq_( session.scalar( functions.wkt( functions.point_n( 'LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)', 1))), u'POINT (77.29 29.07)')
def test_persistent(self): eq_(session.scalar(functions.wkt(func.ST_GeomFromWKB(self.r.road_geom.wkb, 4326))), u'LINESTRING(-88.6748409363057 43.1035032292994,-88.6464173694267 42.9981688343949,-88.607961955414 42.9680732929936,-88.5160033566879 42.9363057770701,-88.4390925286624 43.0031847579618)') geom = WKTSpatialElement('POINT(30250865.9714116 -610981.481754275)', 2249) spot = Spot(spot_height=102.34, spot_location=geom) session.add(spot) session.commit(); assert_almost_equal(session.scalar(spot.spot_location.x), 0) assert_almost_equal(session.scalar(spot.spot_location.y), 0)
def test_persistent(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)') geom = WKTSpatialElement('POINT(30250865.9714116 -610981.481754275)', 2249) spot = Spot(spot_height=102.34, spot_location=geom) session.add(spot) session.commit(); assert_almost_equal(session.scalar(spot.spot_location.x), 0) assert_almost_equal(session.scalar(spot.spot_location.y), 0)
def test_transform(self): spot = session.query(Spot).get(1) eq_(session.scalar(functions.wkt(spot.spot_location.transform(2249))), 'POINT(-3890517.610956 3627658.674651)') ok_( session.query(Spot).filter( sqlite_functions.mbr_contains( functions.buffer(Spot.spot_location.transform(2249), 10), WKTSpatialElement('POINT(-3890517.610956 3627658.674651)', 2249))).first() is not None) eq_( session.scalar( functions.wkt( functions.transform( WKTSpatialElement( 'POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))', 2249), 4326))), 'POLYGON((-71.177685 42.39029, -71.177684 42.390383, -71.177584 42.390383, -71.177583 42.390289, -71.177685 42.39029))' )
def compile_column(element, compiler, **kw): if isinstance(element.table, (Table, Alias)): if kw.has_key("within_columns_clause") and kw["within_columns_clause"] == True: if element.type.wkt_internal: if isinstance(compiler.dialect, PGDialect): return compiler.process(functions.wkt(element)) warnings.warn("WKT Internal GeometryColumn type not " "compatible with %s dialect. Defaulting back to WKB" % compiler.dialect.name, exc.SAWarning) return compiler.process(functions.wkb(element)) return compiler.visit_column(element)
def test_boundary(self): r = session.query(Road).filter(Road.road_name == "Graeme Ave").one() eq_( session.scalar(functions.wkt(r.road_geom.boundary)), u"MULTIPOINT ((-88.5912422100082 43.187101952731609), (-88.547770872712135 42.698885396122932))", ) ok_( session.query(Road) .filter( Road.road_geom.boundary == WKTSpatialElement( "MULTIPOINT ((-88.5912422100082 43.187101952731609), (-88.547770872712135 42.698885396122932))" ) ) .first() is not None ) eq_( session.scalar(functions.wkt(functions.boundary("POLYGON((1 1,0 0, -1 1, 1 1))"))), u"LINESTRING (0 0, 1 1, -1 1, 0 0)", )
def test_persistent(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)') geom = WKTSpatialElement('POINT(30250865.9714116 -610981.481754275)', 2249) spot = Spot(spot_height=102.34, spot_location=geom) session.add(spot) session.commit(); assert_almost_equal(session.scalar(spot.spot_location.x), 0) assert_almost_equal(session.scalar(spot.spot_location.y), 0) spot.spot_location = PersistentSpatialElement(None) ok_(isinstance(spot.spot_location, PersistentSpatialElement))
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))' )
def test_persistent(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)' ) geom = WKTSpatialElement('POINT(30250865.9714116 -610981.481754275)', 2249) spot = Spot(spot_height=102.34, spot_location=geom) session.add(spot) session.commit() assert_almost_equal(session.scalar(spot.spot_location.x), 0) assert_almost_equal(session.scalar(spot.spot_location.y), 0) spot.spot_location = PersistentSpatialElement(None) ok_(isinstance(spot.spot_location, PersistentSpatialElement))
def __get_wkt_for_field(self, options): """Returns the WKT string for the value of a field by making a database query. If necessary the geometry is reprojected. """ if self.raw_value is not None and isinstance(self.raw_value, PersistentSpatialElement): geom_srid = self.field.type.srid map_srid = options.get('map_srid', geom_srid) if geom_srid != map_srid: # if the map uses a different CRS we have to ask the database # to reproject the geometry query = functions.wkt(functions.transform(self.raw_value, map_srid)) else: query = self.raw_value.wkt session = self.field.parent.session return session.scalar(query) else: return '';
def __get_wkt_for_field(self, options): """Returns the WKT string for the value of a field by making a database query. If necessary the geometry is reprojected. """ if self.raw_value is not None and isinstance(self.raw_value, PersistentSpatialElement): geom_srid = self.field.type.srid map_srid = options.get('map_srid', geom_srid) if geom_srid != map_srid: # if the map uses a different CRS we have to ask the database # to reproject the geometry query = functions.wkt( functions.transform(self.raw_value, map_srid)) else: query = self.raw_value.wkt session = self.field.parent.session return session.scalar(query) else: return ''
def test_boundary(self): eq_(session.scalar(functions.wkt(self.r.road_geom.boundary)), 'MULTIPOINT(-88.674841 43.103503, -88.439093 43.003185)')
def test_sdo_geom_sdo_xor(self): eq_(session.scalar(functions.wkt(oracle_functions.sdo_geom_sdo_xor( 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', 'POLYGON((-10 1, 5 1, 5 8, -10 8, -10 1))', tolerance))), u'MULTIPOLYGON (((-10.0 8.0, -10.0 1.0, 0.0 1.00766739404158, 0.0 8.06054845190832, -10.0 8.0)), ((10.0 0.0, 10.0 10.0, 0.0 10.0, 0.0 8.06054845190832, 5.0 8.0, 5.0 1.0, 0.0 1.00766739404158, 0.0 0.0, 10.0 0.0)))')
def test_sdo_geom_sdo_pointonsurface(self): l = session.query(Lake).filter(Lake.lake_name=='Lake Blue').one() eq_(session.scalar(functions.wkt(l.lake_geom.sdo_geom_sdo_pointonsurface)), u'POINT (-89.0694267515924 43.1335987261147)')
def test_sdo_geom_sdo_mbr(self): r = session.query(Road).filter(Road.road_name=='Graeme Ave').one() eq_(session.scalar(functions.wkt(r.road_geom.sdo_geom_sdo_mbr)), u'POLYGON ((-88.6096339299363 42.6988853949045, -88.5477708726115 42.6988853949045, -88.5477708726115 43.187101955414, -88.6096339299363 43.187101955414, -88.6096339299363 42.6988853949045))')
def test_sdo_geom_sdo_difference(self): eq_(session.scalar(functions.wkt(oracle_functions.sdo_geom_sdo_difference( 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', 'POLYGON((-10 1, 5 1, 5 8, -10 8, -10 1))', tolerance))), u'POLYGON ((5.0 1.0, 5.0 8.0, 0.0 8.06054845190832, 0.0 1.00766739404158, 5.0 1.0))')