Changeset 10852 in josm for trunk/src/org
- Timestamp:
- 2016-08-19T02:40:50+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r10755 r10852 102 102 org.openstreetmap.josm.io.OsmGzipExporter.class, 103 103 org.openstreetmap.josm.io.OsmBzip2Exporter.class, 104 org.openstreetmap.josm.io.GeoJSONExporter.CurrentProjection.class, // needs to be considered earlier than GeoJSONExporter105 104 org.openstreetmap.josm.io.GeoJSONExporter.class, 106 105 org.openstreetmap.josm.io.WMSLayerExporter.class, -
trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java
r8813 r10852 10 10 import java.nio.file.Files; 11 11 12 import org.openstreetmap.josm.Main;13 12 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 import org.openstreetmap.josm.data.projection.Projection;15 13 import org.openstreetmap.josm.gui.layer.Layer; 16 14 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;18 import org.openstreetmap.josm.tools.Utils;19 15 16 /** 17 * Exporter to write map data to a GeoJSON file. 18 * @since 4886 19 */ 20 20 public class GeoJSONExporter extends FileExporter { 21 21 22 protected final Projection projection;22 /** File extension filter for .geojson files */ 23 23 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 24 24 "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 }36 25 37 26 /** … … 39 28 */ 40 29 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); 47 31 } 48 32 … … 50 34 public void exportData(File file, Layer layer) throws IOException { 51 35 if (layer instanceof OsmDataLayer) { 52 String json = new GeoJSONWriter((OsmDataLayer) layer, Utils.firstNonNull(projection, Main.getProjection())).write();53 36 try (Writer out = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) { 54 out.write( json);37 out.write(new GeoJSONWriter((OsmDataLayer) layer).write()); 55 38 } 56 39 } else { -
trunk/src/org/openstreetmap/josm/io/GeoJSONWriter.java
r10817 r10852 32 32 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 33 33 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 34 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 34 35 import org.openstreetmap.josm.tools.Pair; 35 36 36 37 /** 37 38 * 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> 38 41 */ 39 42 public class GeoJSONWriter { … … 46 49 * Constructs a new {@code GeoJSONWriter}. 47 50 * @param layer The OSM data layer to save 48 * @ param projection The projection to use for coordinates51 * @since 10852 49 52 */ 50 public GeoJSONWriter(OsmDataLayer layer , Projection projection) {53 public GeoJSONWriter(OsmDataLayer layer) { 51 54 this.layer = layer; 52 this.projection = projection;55 this.projection = ProjectionPreference.wgs84.getProjection(); 53 56 } 54 57 … … 74 77 JsonObjectBuilder object = Json.createObjectBuilder() 75 78 .add("type", "FeatureCollection") 76 .add("crs", Json.createObjectBuilder().add("type", "name").add(77 "properties", Json.createObjectBuilder().add("name", projection.toCode())))78 79 .add("generator", "JOSM"); 79 80 appendLayerBounds(layer.data, object);
Note:
See TracChangeset
for help on using the changeset viewer.