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

Last change on this file since 10922 was 10852, checked in by Don-vip, 8 years ago

fix #13358 - GeoJSON no longer permits projections other than WGS84, see https://tools.ietf.org/html/rfc7946

  • Property svn:eol-style set to native
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.File;
7import java.io.IOException;
8import java.io.Writer;
9import java.nio.charset.StandardCharsets;
10import java.nio.file.Files;
11
12import org.openstreetmap.josm.actions.ExtensionFileFilter;
13import org.openstreetmap.josm.gui.layer.Layer;
14import org.openstreetmap.josm.gui.layer.OsmDataLayer;
15
16/**
17 * Exporter to write map data to a GeoJSON file.
18 * @since 4886
19 */
20public class GeoJSONExporter extends FileExporter {
21
22 /** File extension filter for .geojson files */
23 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
24 "geojson,json", "geojson", tr("GeoJSON Files") + " (*.geojson *.json)");
25
26 /**
27 * Constructs a new {@code GeoJSONExporter} with WGS84 projection.
28 */
29 public GeoJSONExporter() {
30 super(FILE_FILTER);
31 }
32
33 @Override
34 public void exportData(File file, Layer layer) throws IOException {
35 if (layer instanceof OsmDataLayer) {
36 try (Writer out = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
37 out.write(new GeoJSONWriter((OsmDataLayer) layer).write());
38 }
39 } else {
40 throw new IllegalArgumentException(tr("Layer ''{0}'' not supported", layer.getClass().toString()));
41 }
42 }
43}
Note: See TracBrowser for help on using the repository browser.