Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Last active September 27, 2016 02:50
Show Gist options
  • Save NathanW2/7604d7210c64513d221c92b4e1bed9c3 to your computer and use it in GitHub Desktop.
Save NathanW2/7604d7210c64513d221c92b4e1bed9c3 to your computer and use it in GitHub Desktop.
SELECT geometry::STGeomFromText('POINT (635641.32 5815631.39 100)', 28355) geom
SELECT CONVERT(varchar(max), geometry::STGeomFromText('POINT (635641.32 5815631.39 100)', 28355).AsBinaryZM(), 2) zmhex
SELECT CONVERT(varchar(max), geometry::STGeomFromText('POINT (635641.32 5815631.39 100)', 28355).STAsBinary(), 2) nozmhex
geom
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0xC36E0000010D3D0AD7A3F26523418FC2F5D8532F56410000000000005940
zmhex
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
01E90300003D0AD7A3F26523418FC2F5D8532F56410000000000005940
nozmhex
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
01010000003D0AD7A3F26523418FC2F5D8532F5641
sqldata = u'01E90300003D0AD7A3F26523418FC2F5D8532F56410000000000005940'
print "In SQL Server:", sqldata
data = str(bytearray.fromhex(sqldata))
gotback = binascii.hexlify(data).upper()
point = ogr.CreateGeometryFromWkb(data)
print "ogr wkt:", point.ExportToWkt()
wkbfromogr = point.ExportToWkb().encode('hex')
print "ogr wkb:", wkbfromogr
print sqldata == wkbfromogr, "Matched to sql server in Python"
print sqldata == gotback, "Matched to sql server in Python"
@NathanW2
Copy link
Author

In SQL Server: 01E90300003D0AD7A3F26523418FC2F5D8532F56410000000000005940
ogr wkt: POINT (635641.32 5815631.39 100)
ogr wkb: 0080000001412365f2a3d70a3d41562f53d8f5c28f4059000000000000
False Matched to sql server in Python
True Matched to sql server in Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment