Changeset 15499 in josm


Ignore:
Timestamp:
2019-11-03T15:00:47+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #18287 - more robust parsing of GeoJSON coordinates

File:
1 edited

Legend:

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

    r15442 r15499  
    77import java.util.List;
    88import java.util.Map;
     9import java.util.Objects;
    910import java.util.Optional;
    1011import java.util.TreeMap;
     
    1314import javax.json.Json;
    1415import javax.json.JsonArray;
     16import javax.json.JsonNumber;
    1517import javax.json.JsonObject;
    1618import javax.json.JsonString;
     
    197199    private LatLon getLatLon(final JsonArray coordinates) {
    198200        return projection.eastNorth2latlon(new EastNorth(
    199                 coordinates.getJsonNumber(0).doubleValue(),
    200                 coordinates.getJsonNumber(1).doubleValue()));
     201                parseCoordinate(coordinates.get(0)),
     202                parseCoordinate(coordinates.get(1))));
     203    }
     204
     205    private static double parseCoordinate(JsonValue coordinate) {
     206        if (coordinate instanceof JsonString) {
     207            return Double.parseDouble(((JsonString) coordinate).getString());
     208        } else if (coordinate instanceof JsonNumber) {
     209            return ((JsonNumber) coordinate).doubleValue();
     210        } else {
     211            throw new IllegalArgumentException(Objects.toString(coordinate));
     212        }
    201213    }
    202214
Note: See TracChangeset for help on using the changeset viewer.