I have a probably base64 encoded WKB string. How would I load that feature represented by the string into QGis or ArcGIS?

I found the QGis QuickWKT plugin, but that does not handle my base64 encoded string.

I have some Python programming skills.

Get your own WKB from http://nibis.lbeg.de/net3/public/ogc.ashx?Service=WMS&PKGID=22&cardo3SessionGuid=C3_2d80a40c-529e-4574-912b-53a3858b173c&layers=L160&query_layers=L160&width=1&request=GetFeatureInfo&height=1&srs=EPSG%3A31467&version=1.1.1&bbox=3585999%2C5743699%2C3586001%2C5743701&info_format=text%2Fplain&y=1&x=1 if you like.

  • where is the wkb in the link, after GEOM_R1 ? – gene Oct 28 '13 at 14:28
  • Yeah, after GEOM_R1 – til_b Oct 28 '13 at 14:31
  • ...at least I hope this is WKB/WKT. Am not sure, though. Will test further. – til_b Oct 28 '13 at 14:39
  • It is the response of a WMS service and not a WKB – gene Oct 28 '13 at 15:11
  • So the string decodes to an image file? – til_b Oct 29 '13 at 9:18

If you have a string object, you can use the .decode() method on it to get it from base64 to the original string. For example,

shape_base64 = "BXsAAAEEKwAAACL99gXlXEt...<omitted for brevity>...gAAAAABAAAA/////wAAAAAD"
shape_string = shape_base64.decode("base64")

From there you can use the standard methods. I don't know about QGIS, but in ArcGIS you can use the FromWKB function to get an arcpy geometry object, or if you're using a da cursor you can use the SHAPE@WKB token as a column name to directly insert the decoded WKB string.

  • 1
    For QGIS you can use the QgsGeometry.fromWkb() function shape_string = '\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08@\x00\x00\x00\x00\x00\x00\x10@' geom = QgsGeometry() geom.fromWkb(shape_string) – Matthias Kuhn Oct 28 '13 at 16:38
  • Which import should be used for QgsGeometry? It gives me SyntaxError: invalid syntax – Mr. P Mar 3 '15 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.