Search code examples
kmlgeojson

Java converter from kml/shapefile to Geojson


I would like to write a command line program using Java that take in KML/Shapfile and output GeoJSON file. What I usually did is go over ogre2ogre and manually convert my file. Once I got the GeoJson I modified the content of it a little bit before output final GeoJSON.

I would like to skip the manual part and find some API that do the conversion for me.

Anyone could help please.

Thanks


Solution

  • OSMBonusPack provides a KML+GeoJSON toolkit, with both a KML parser/writer and a GeoJSON parser/writer, all in Java. So this allows to read KML content, and write it as GeoJSON.

    You can test this conversion using the demo app OSMNavigator.

    It is targeting Android, so for your need you would have to pick the relevant classes, and remove code sections you don't need (icon loading, overlay building, Parcelable implementation, for instance).