Ignore:
Timestamp:
2016-08-19T02:40:50+02:00 (3 years ago)
Author:
Don-vip
Message:

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

Location:
trunk/src/org/openstreetmap/josm/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java

    r8813 r10852  
    1010import java.nio.file.Files;
    1111
    12 import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.actions.ExtensionFileFilter;
    14 import org.openstreetmap.josm.data.projection.Projection;
    1513import org.openstreetmap.josm.gui.layer.Layer;
    1614import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    17 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    18 import org.openstreetmap.josm.tools.Utils;
    1915
     16/**
     17 * Exporter to write map data to a GeoJSON file.
     18 * @since 4886
     19 */
    2020public class GeoJSONExporter extends FileExporter {
    2121
    22     protected final Projection projection;
     22    /** File extension filter for .geojson files */
    2323    public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
    2424            "geojson,json", "geojson", tr("GeoJSON Files") + " (*.geojson *.json)");
    25     public static final ExtensionFileFilter FILE_FILTER_PROJECTED = new ExtensionFileFilter(
    26             "proj.geojson", "proj.geojson", tr("Projected GeoJSON Files") + " (*.proj.geojson)");
    27 
    28     /**
    29      * A GeoJSON exporter which obtains the current map projection when exporting ({@link #exportData(File, Layer)}).
    30      */
    31     public static class CurrentProjection extends GeoJSONExporter {
    32         public CurrentProjection() {
    33             super(FILE_FILTER_PROJECTED, null);
    34         }
    35     }
    3625
    3726    /**
     
    3928     */
    4029    public GeoJSONExporter() {
    41         this(FILE_FILTER, ProjectionPreference.wgs84.getProjection());
    42     }
    43 
    44     private GeoJSONExporter(ExtensionFileFilter fileFilter, Projection projection) {
    45         super(fileFilter);
    46         this.projection = projection;
     30        super(FILE_FILTER);
    4731    }
    4832
     
    5034    public void exportData(File file, Layer layer) throws IOException {
    5135        if (layer instanceof OsmDataLayer) {
    52             String json = new GeoJSONWriter((OsmDataLayer) layer, Utils.firstNonNull(projection, Main.getProjection())).write();
    5336            try (Writer out = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
    54                 out.write(json);
     37                out.write(new GeoJSONWriter((OsmDataLayer) layer).write());
    5538            }
    5639        } else {
  • trunk/src/org/openstreetmap/josm/io/GeoJSONWriter.java

    r10817 r10852  
    3232import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3333import org.openstreetmap.josm.gui.mappaint.ElemStyles;
     34import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    3435import org.openstreetmap.josm.tools.Pair;
    3536
    3637/**
    3738 * Writes OSM data as a GeoJSON string, using JSR 353: Java API for JSON Processing (JSON-P).
     39 * <p>
     40 * See <a href="https://tools.ietf.org/html/rfc7946">RFC7946: The GeoJSON Format</a>
    3841 */
    3942public class GeoJSONWriter {
     
    4649     * Constructs a new {@code GeoJSONWriter}.
    4750     * @param layer The OSM data layer to save
    48      * @param projection The projection to use for coordinates
     51     * @since 10852
    4952     */
    50     public GeoJSONWriter(OsmDataLayer layer, Projection projection) {
     53    public GeoJSONWriter(OsmDataLayer layer) {
    5154        this.layer = layer;
    52         this.projection = projection;
     55        this.projection = ProjectionPreference.wgs84.getProjection();
    5356    }
    5457
     
    7477            JsonObjectBuilder object = Json.createObjectBuilder()
    7578                    .add("type", "FeatureCollection")
    76                     .add("crs", Json.createObjectBuilder().add("type", "name").add(
    77                             "properties", Json.createObjectBuilder().add("name", projection.toCode())))
    7879                    .add("generator", "JOSM");
    7980            appendLayerBounds(layer.data, object);
Note: See TracChangeset for help on using the changeset viewer.