11

There are many questions & answers here addressing how to convert between WKT and WKB geometries, and about the specifications or implementation details. But what are the considerations for choosing between them in general, when there are no external requirements? For example, is WKB faster?

Or for my specific use case: I want to convert a shapefile to SQLite in QGIS, and have to choose between WKT and WKB. When should I choose one over the other?

5
  • 2
    What did you research tell you? My quick search suggested that WKB is a binary equivalent used for storing the information in a database. See Well-known text on Wikipedia.
    – Midavalo
    Commented Apr 6, 2017 at 15:55
  • 3
    If you're storing it in a database such as SQLite, then I would lean towards WKB. If it needs to be human readable however, then you might want to use WKT.
    – T_Bacon
    Commented Apr 6, 2017 at 15:59
  • 2
    The question is put on hold as too broad, but it is a specific question (the second paragraph about SQLite is just one example when you would want to know the answer to the question). I'm not sure how to make it more specific. // @Midavalo and T_Bacon: the information encoded is obviously equivalent, but two formats have been standardized and implemented. And both WKT and WKB are options for storing geometries in a database.
    – arjan
    Commented Apr 8, 2017 at 18:41
  • 2
    Now, it's possible that the answer is simply that WKT is meant for human-readability. But in that case you would expect there are also downsides to WKT, why else would WKB exist? Hence my note about potential speed differences (or perhaps space usage?). And in that case I would expect rules-of-thumb like "use WKB for very large data sets". But I didn't find such guidelines.
    – arjan
    Commented Apr 8, 2017 at 18:42
  • 3
    @arjan human readability for WKT, binary storage in a database for WKB. Tidier to store but harder to read, and vice versa
    – Midavalo
    Commented Apr 8, 2017 at 18:44

1 Answer 1

5

The comments cover this pretty well, but I'll summarize them in an answer.

WKT is text and human readable. So use this if you want a human to read them (eg. for quick verification that the data is reasonable), or if you might want to work the data using text tools (eg. regex).

WKB takes up less space - so good for bulk storage. Also it is in theory at least, a little quicker to read/process for two reasons. First there is less data to load/transfer/cache, and second there is no text to parse. In most applications the potential speed difference is probably immaterial unless you are processing large amounts of data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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