Tuesday, 6 June 2017

How To Convert KML File to GeoJson ?

If you want to convert KML file to GeoJson file, refer below mention library for such conversion
  • library Name:osmbonuspack
Example:
In following example we are going use KML file from row folder and convert it in to GeoJson file and sore in SD Card.

 InputStream ins = getResources().openRawResource(  
 getResources().getIdentifier("pmc_election_ward_boundaries",  
 "raw", getPackageName()));  //take file from row folder
 kmlDocument = new KmlDocument();  
 kmlDocument.parseKMLStream(ins, null);  
 fCreated = kmlDocument.saveAsGeoJSON(new File(Environment.getExternalStorageDirectory() + "/sample.geojson"));  

Download Sample Code

Screenshot:
  •  file name sample.geojson is converted from KML file to geoJosn 
  •  GeoJson file plot on mapbox

No comments:

Post a Comment

Create File on External Storage using Storage access framework for android 10

How To Create File on External Storage on android 10 using Storage Access Framework? By default, apps targeting Android 10 and higher a...