JTS Topology Suite TestBuilder supports WKT, WKB and GML inputs. What's a quick and easy way to get the geometry for a KML feature into one of these formats for input into JTS TestBuilder?

For clarification, I'd like to avoid using OGR, FME, etc. which will likely do their own validation and potentially mess with the original coordinates. I'm thinking I'm more looking for a dumb text-to-text transformation tool.


Use the ogr2ogr utility to convert your KML to GML. See some samples on how to use the utility here.

ogr2ogr -f GML output.gml input.kml

should do the trick.

  • Whoops, see my clarification I just snuck in. Will OGR mess with the coordinates, vertex ordering, etc.? – blah238 Jan 11 '13 at 19:09
  • 1
    Any converter can potentially touch the geometries to "fix" them. Even more so if there is something invalid in the geometry. If you want to guarantee that is exact, you can open the KML file with a text editor and copy and paste the geometries. WKT is easy to do by hand en.wikipedia.org/wiki/Well-known_text . If you have too many geometries, then you can write a simple parser that does it. What is the source of the geometries? – Ragi Yaser Burhum Jan 11 '13 at 19:20
  • Yeah looking to maintain any errors in the geometry to see if JTS catches it. I'm using scribblemaps.com to generate the KMLs and trying to see if I can produce an invalid geometry with it. KML to WKT is probably what I'm after, and yeah I have done the hand-editing before but I figured someone else would have gotten tired of that by now and created a tool for me :) – blah238 Jan 11 '13 at 19:25
  • Cool tool. Does it support export to CSV? If so, you could import to PostGIS as a "normal" table and do all the isValid() checks using SQL. – Ragi Yaser Burhum Jan 11 '13 at 19:36
  • 1
    Not mine, but yes it's handy (lots of basemaps to choose from). I don't think it has CSV output. OGR 1.6 choked on reading the KML but 1.9 was able to convert it to GML for me. Also this blog post has some ways of getting WKT out of OGR (it doesn't have a WKT driver per se), one way using the CSV driver. – blah238 Jan 11 '13 at 19:39

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.