August 24, 2022

Betterknown: a new WKT & EWKT parser

Our approach to open source is pretty simple: use a lot of it, make some of it, and maintain the things we release as best we can. The best open source projects are the ones heavily used by their creators. Placemark is an especially good place for open source projects to mature: when there's a bug in a parser, generator, or another utility, it'll usually show up because of the many different kinds of data and tasks that people do with this system.

Placemark's open source projects

If you aren't familiar with our open source projects, here are the existing ones:

  • toGeoJSON is a module that Tom started working on in 2013! Such a long time ago. It converts KML, GPX, and TCX - three very popular, XML-based geospatial formats - into GeoJSON. Over the years it's grown to include lots of little features, like support for folders, feature visibility, streaming parsing, GPX extensions, and a lot more. Placemark's fork is used in the importer. At this point, it's super battle-tested, but with our maintenance it'll keep getting better.
  • toKML converts GeoJSON into KML. This one also goes way back, but it's now maintained under the Placemark umbrella and has gotten features like visibility & folder support, plus TypeScript types to make it easier to integrate into applications.
  • check-geojson is the successor to the longstanding geojsonhint module, also written by Placemark's creators. It takes geojsonhint's mission a step further by reporting more specific errors and letting you import only the "good" data from partially-valid files.

Today we're adding another one: betterknown, a new parser and stringifier for WKT.

Betterknown

WKT parsing & stringification can be a challenge. We wrote wellknown, a WKT parser & stringifier, years ago. But it had quite a few basic limitations and was too liberal in the inputs it would accept. Plus, it hasn't been maintained since 2017. Not great. There's also wkx, which was maintained until 2020 and is better than wellknown in some ways - its parser is more mature - but also a large dependency and has some inelegant API touches.

Betterknown aims to be the synthesis of the two - wellknown's simplicity, wkx's correctness, and maintained and updated for software in 2022. It combines parts of wkx, crediting Christian Schwarz's amazing work, with new touches and improvements.

Betterknown is powering Placemark's support for WKT import & export, and will get better as we put it through its paces in production. Try it out - it's now on GitHub!