Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_function_call(self):
e = RasterElement(self.rast_data)
f = e.ST_Height()
eq_sql(f, 'ST_Height(raster(:raster_1))')
assert f.compile().params == {u'raster_1': self.hex_rast_data}
def test_desc(self):
e = RasterElement(self.rast_data)
assert e.desc == self.hex_rast_data
assert e.srid == 4326
e = RasterElement(self.hex_rast_data)
assert e.desc == self.hex_rast_data
assert e.srid == 4326
def test_Raster(self):
polygon = WKTElement('POLYGON((0 0,1 1,0 1,0 0))', srid=4326)
o = Ocean(polygon.ST_AsRaster(5, 5))
session.add(o)
session.flush()
session.expire(o)
assert isinstance(o.rast, RasterElement)
rast_data = (
'01000001009A9999999999C93F9A9999999999C9BF0000000000000000000000000000F03'
'F00000000000000000000000000000000E610000005000500440001010101010101010100'
'010101000001010000000100000000'
)
assert o.rast.data == rast_data
assert session.execute(
select([Ocean.rast.ST_Height(), Ocean.rast.ST_Width()])
).fetchall() == [(5, 5)]
# Set rast to None
o.rast = None
select([Ocean.rast.ST_Height(), Ocean.rast.ST_Width()])
).fetchall() == [(5, 5)]
# Set rast to None
o.rast = None
# Insert in DB
session.flush()
session.expire(o)
# Check what was updated in DB
assert o.rast is None
assert session.execute(select([Ocean])).fetchall() == [(1, None)]
# Reset rast to initial value
o.rast = RasterElement(rast_data)
# Insert in DB
session.flush()
session.expire(o)
# Check what was updated in DB
assert o.rast.data == rast_data
assert session.execute(
select([Ocean.rast.ST_Height(), Ocean.rast.ST_Width()])
).fetchall() == [(5, 5)]
def test_pickle_unpickle(self):
import pickle
e = RasterElement(self.rast_data)
assert e.srid == 4326
assert e.extended is True
assert e.data == self.hex_rast_data
pickled = pickle.dumps(e)
unpickled = pickle.loads(pickled)
assert unpickled.srid == 4326
assert unpickled.extended is True
assert unpickled.data == self.hex_rast_data
f = unpickled.ST_Height()
eq_sql(f, 'ST_Height(raster(:raster_1))')
assert f.compile().params == {
u'raster_1': self.hex_rast_data,
}
def test_desc(self):
e = RasterElement(self.rast_data)
assert e.desc == self.hex_rast_data
assert e.srid == 4326
e = RasterElement(self.hex_rast_data)
assert e.desc == self.hex_rast_data
assert e.srid == 4326
elif isinstance(bindvalue, WKBElement):
if dialect.name == 'sqlite' or not bindvalue.extended:
# With SpatiaLite or when the WKBElement includes a WKB value rather
# than a EWKB value we use Shapely to convert the WKBElement to an
# EWKT string
if not SHAPELY:
raise ArgumentError('Shapely is required for handling WKBElement bind '
'values when using SpatiaLite or when the bind value '
'is a WKB rather than an EWKB')
shape = to_shape(bindvalue)
return 'SRID=%d;%s' % (bindvalue.srid, shape.wkt)
else:
# PostGIS ST_GeomFromEWKT works with EWKT strings as well
# as EWKB hex strings
return bindvalue.desc
elif isinstance(bindvalue, RasterElement):
return '%s' % (bindvalue.data)
else:
return bindvalue
return process