2

I am not able to convert the daily NIFC GeoJSON data into KML file using GeoTools lib. I am pretty new to GIS data.

Sample GeoJSON data : https://opendata.arcgis.com/datasets/5da472c6d27b4b67970acc7b5044c862_0.geojson

I have tried the below code so far:

URL url = URLs.fileToUrl(new 
 File("C:\\datasets\\5da472c6d27b4b67970acc7b5044c862_0.geojson"));
HashMap<String, Object> params = new HashMap<>();
params.put("url", url);
DataStore in = DataStoreFinder.getDataStore(params);

if(in == null) {
  throw new IOException("couldn't open datastore from "+url);
}
SimpleFeatureCollection features = in.getFeatureSource(in.getTypeNames()[0]).getFeatures();
Encoder encoder = new Encoder(new KMLConfiguration());
encoder.setIndenting(true);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
  encoder.encode(features, KML.kml, os);
  String out = os.toString().replaceAll("kml:", "");
  System.out.println(out);
} catch (Exception e) {
  e.printStackTrace();
}

The above code DataStore in = DataStoreFinder.getDataStore(params); is not able to find dataStore and is always returning null.

1
  • did you make sure your maven file has a dependency to the gt-geojsonstore module?
    – Ian Turton
    Commented Sep 15, 2020 at 7:38

1 Answer 1

1

Looks like there might be an issue with the current version of the GeoJSONStore handling URLs but your code works if I use the GeoJSONDataStoreFactory.FILE_PARAM.key and a file.

The fix will be in the nightly (25.x) build tonight and will make the 24.0, 23.3 releases in the coming weeks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.