source: josm/trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java@ 7267

Last change on this file since 7267 was 7214, checked in by simon04, 10 years ago

GeoJOSN: change default file extension to .geojson

File size: 1.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.BufferedWriter;
7import java.io.File;
8import java.io.FileOutputStream;
9import java.io.IOException;
10import java.io.OutputStreamWriter;
11import java.io.Writer;
12import java.nio.charset.StandardCharsets;
13
14import org.openstreetmap.josm.actions.ExtensionFileFilter;
15import org.openstreetmap.josm.gui.layer.Layer;
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17
18public class GeoJSONExporter extends FileExporter {
19
20 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
21 "geojson,json", "geojson", tr("GeoJSON Files") + " (*.geojson *.json)");
22
23 /**
24 * Constructs a new {@code GeoJSONExporter}.
25 */
26 public GeoJSONExporter() {
27 super(FILE_FILTER);
28 }
29
30 @Override
31 public void exportData(File file, Layer layer) throws IOException {
32 if (layer instanceof OsmDataLayer) {
33 String json = new GeoJSONWriter((OsmDataLayer) layer).write();
34 try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) {
35 out.write(json);
36 }
37 } else {
38 throw new IllegalArgumentException(tr("Layer ''{0}'' not supported", layer.getClass().toString()));
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.