I want to convert WKB representations of XY coordinates into a YX format. The code I'm using works with 42 character WKB strings, but when I use it on 50 character strings it gives me an odd YX output. I'm running Python 2.7.5.
Here's my code:
from osgeo import ogr
from binascii import unhexlify
## converts a WKB string into a YX coordinate
input = raw_input("Enter WKB string: ")
wkb = unhexlify(input)
point = ogr.CreateGeometryFromWkb(wkb)
print "%.3f,%.3f" % (point.GetY(), point.GetX())
# no work 0101000020E6100000BD30B7B921A85AC07513F26D8A1A4840
# work 0101000000C458A65F22A85AC0E412471E881A4840
When I input the 42 character string my results are good: POINT (-106.627098 48.207279)
but when I input my 50 character string I get: 355513472847601729897331967629935245053837846890691162677352753848836303684477311589993604618806134471993299583159702126592.000,-0.000
when I print the point only, I get this: POINT (-0.0 too_big)
can anyone help me with an explanation?
Where does this 50 chars string come from? It's header,
0101000020
do not seem to be a valid WKB header, as first01
implies little-endiannes, so geomertry type is translated as0x20000001
, which is undefined.Second, for a point length of WKB representation is 42, never 50, as coordinates are doubles (8 bytes long), hence 16 chars long when hexlified. See for your working example:
It is then clear why your second example do not work, as something like follows happens (not sure how exactly 16 chars substring are extracted by osgeo):