Unfolding Maps, GeoJSON and MultiLineString

edited September 2014 in Library Questions


I'm trying to import (properly formatted) GeoJSON data into Unfolding Maps using the inbuilt GeoJSONReader.loadData(), but it refuses to import data which contains MultiLineString geometries. When importing, it gives up with an error message "org.json.JSONException: JSONArray[0] is not a JSONArray.". Those GeoJSONs which only contain LineString geometries are imported flawlessly. I've checked through the API documentation and Unfolding source, but I have no clue for fixing this inconsistency.

Could this be a bug or am I misusing the API someway?

Cheers, Vesa


  • edited September 2014

    "org.json.JSONException: JSONArray[0] is not a JSONArray."

    Processing's API got its own class called JSONArray which belongs to package "processing.data".

    Obviously, it doesn't come from a package called "org.json" as that JSONException above implies! [-(
    I believe your GeoJSON class wants a org.json.JSONArray, while you're giving it a processing.data.JSONArray 1!

  • edited September 2014

    Actually, that error is raised by the Unfolding Maps, which uses the org.json.JSONArray Java API.

    I dove deeper into the Unfolding source, and this error is raised by the private method GeoJSONReader.populateLinesFeature(). It fails when a GeoJSON MultiLineString occurs.. Maybe it does not recognize the format used for storing MultiLineString geometries (the format differs from LineString by one additional level of nesting).

    Is there any known tricks or libraries to circumvent this, or am I going to write my own reader?

  • edited September 2014

    Can you post the GeoJSON you are trying to load? Unfolding does support MultiLineStrings, however there might be a bug in the GeoJSON parser. You could post an issue over at github.

    Best would be if you test your GeoJSON before, e.g. on http://geojsonlint.com/

  • Well, that GeoJSON is an export from Moves (https://www.moves-app.com/) and I did validate it via geojsonlint and by imporing it to GIS-software (it is valid). Perhaps I should post an issue.

  • edited September 2014

    Here is a sample code to reproduce the problem:

    import de.fhpotsdam.unfolding.data.GeoJSONReader;
    import de.fhpotsdam.unfolding.data.Feature;
    import java.util.List;
    void setup() {
      List<Feature> features = GeoJSONReader.loadData(this, "test.geojson");

    and this is a sample GeoJSON-file test.geojson:

      "type" : "FeatureCollection",
      "features" : [ {
        "type" : "Feature",
        "geometry" : {
          "type" : "MultiLineString",
          "coordinates" : [ [ [ 22.4373774243, 60.5626498743 ], [ 22.3394774017, 60.2637478048 ], [ 22.1416898926, 60.4639839257 ], [ 22.5433583161, 60.5524560219 ], [ 22.3445105025, 60.4615928548 ], [ 22.4463646728, 60.4613021767 ] ] ]
        "properties" : {
          "type" : "move",
          "startTime" : "20140505T151759+0300",
          "endTime" : "20140505T152008+0300",
          "activities" : [ {
            "activity" : "transport",
            "group" : "transport",
            "manual" : false,
            "startTime" : "20140505T151759+0300",
            "endTime" : "20140505T152008+0300",
            "duration" : 129.0,
            "distance" : 812.0
          } ],
          "lastUpdate" : "20140505T160227Z",
          "date" : "20140505"
      } ]

    This validates ok and contains a MultiLineString, but produces the error

    org.json.JSONException: JSONArray[0] is not a JSONArray.

    from Unfolding library.

    Is there something here that I'm missing or does this sound like a bug?

  • Answer ✓

    Thanks for the example. Can confirm this was a bug in Unfolding.

    Fixed it now. You can find the new version of GeoJSONReader at github, or download a beta version of Unfolding from here: https://dl.dropboxusercontent.com/u/599609/unfolding.0.9.7beta.jar

  • Wow, thanks for fixing it, that was fast!

Sign In or Register to comment.