We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
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
Answers
Processing's API got its own class called JSONArray which belongs to
package
"processing.data".https://github.com/processing/processing/blob/master/core/src/processing/data/JSONArray.java
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!
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?
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.
Here is a sample code to reproduce the problem:
and this is a sample GeoJSON-file test.geojson:
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?
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!