Skip to main content
1 of 3
user avatar
user avatar

How can I pretty-print WKT strings?

Is there a tool that will pretty-print well-known-text strings? One that would accept for instance

MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 45 20, 30 5, 20 35)))

and output something like

MULTIPOLYGON (
  (
    (
      40 40,
      20 45,
      45 30,
      40 40
    ),
  ),
  (
    (
      20 35,
      45 20,
      30  5,
      20 35
    )
  )

Ideally this would be an online tool that runs in a browser (along the lines of the many JSON formatters that exist), but an offline tool would still be useful.

There are a number of online tools for viewing and editing WKT-format data, but none that seem to offer any support for reformatting. The OpenLayers vector-formats example app has a checkbox tantalizing labelled "Pretty print", but selecting it seems not to do anything when WKT is set as the output format.

user55284