I am calculating the geometric data from the latitude/longitude.
https://msdn.microsoft.com/en-us/library/cc280487(v=sql.120).aspx
consultaGeom = ('''select geometry::STGeomFromText('point('+left(?,12)+' '+left(?,12)+')' , 4326)''');
param = (latCIE,lngCIE)
query = ConexionProyecto.execute(consultaGeom,param)
row = query.fetchone()
print(row)
The drawback that the data returned by the query is displayed is
(b'\xe6\x10\x00\x00\x01\x0c\xbdR\x96!\x8e\xa5;\xc0\x1c\xeb\xe26\x1a\\P\xc0', )
when it should be
0xE6100000010C00000000004050C00000000000003CC0
Why does this happen?
I need the returned data to be correct in order to insert it into a geometric field.
What the function returns
fetchone()
is a tuple of a single element. Extracting its first element ([0]
), you get a string ofbytes
, which can be converted to its hexadecimal representation withbytes.hex()
.If you need the addition to be exactly like the example you've shown (ie, with a
0x
leading character and uppercase hex digits), you can usestr.upper()
and concatenate the0x
. So:What you are getting is an object of type
bytes
:Therefore, you can simply call its method
hex()
:You can also use
binascii
: