[GIS] Converting Shapefile data to GeoJSON

convertgeojsonjavashapefile

I have access to some open data for which I want to obtain some coordinates to put onto a map. Unfortunately, the data is in the Shapefile format which is rather difficult to work with. I am trying to convert it to something easier, preferably geoJSON or some kind of XML-based document.

A requirement is to do this within the client's application in the event that the data changes, so unfortunately I am unable to use some online tool nor can I just open the data in QGIS and export the data in another format.

I attempted to write my own Shapefile parser however I ran into difficulty with IndexOutOfBoundsException while reading some of the records despite having shapes of type 1 (Point). Furthermore, there is a projection file that I have to deal with and I haven't been able to find much on how to map the coordinates according to a PRJ.

Is there any open-source library I can include in my application that can take a Shapefile collection (SHP, SHX, DBF, PRJ, SHP.XML) and convert it to geoJSON? I'm particularly looking into Java for Android/BlackBerry development, possibly Windows Phone in the far future.

Best Answer

There are java bindings for GDAL/ogr - see http://gdal.org/java/ . No idea if they work on Android, though. Apparently ( https://www.google.de/search?q=gdal+on+android ) building gdal on Android is not really easy.

http://sourceforge.net/projects/javashapefilere/ seems to be another option.

Also https://stackoverflow.com/questions/2044876/does-anyone-know-of-a-library-in-java-that-can-parse-esri-shapefiles .

Related Question