Arrays in GeoJSON

So my last post was very positive. I figured out how to relate the teams that share a stadium with the stadium itself. This was important because I wanted to eliminate the redundant points that were on top of each other. For those who don’t recall, I have an example in this gist:

Now I mentioned that there were issues displaying this in GIS applications and was promptly told I was doing this incorrectly:

If you click on that tweet you’ll see basically that you can’t do it the way I want and I have to go back to the way I was doing it before:

I had a conversation with Bill Dollins about it and he sums it up susinctly:

I get it, but “Do it this way because that’s what the software can handle” is an unsatisfying answer.

So I’m stuck, I honestly don’t care if QGIS can read the data, because it can. It just isn’t optimal. What I do care about is an organized dataset in GeoJSON. So my question that I can’t get a definitive answer, “is the array I have above valid GeoJSON code?”. From what I’ve seen, yes. But nobody wants to go on record as saying absolutely. I could say, hell with it I’m moving forward but I don’t want to go down a dead end road.

Comments

10 responses to “Arrays in GeoJSON”

  1. Georg Jason Avatar
    Georg Jason

    Absolutely. Just read the geojson specs https://tools.ietf.org/html/rfc7946#section-3.2:

    A Feature object has a member with the name "properties". The value of the properties member is an object (any JSON object or JSON null value).

    1. Bruce Rindahl Avatar
      Bruce Rindahl

      https://jsonlint.com/
      Says it’s valid. That’s my definitive source.

      1. James Fee Avatar

        Everyone is saying its valid except for QGIS people for some reason.

  2. Samuel Jenkins Avatar
    Samuel Jenkins

    Have you considered you might be trying to fit a square peg into a round hole? Regardless if what you are producing is or isn’t valid GeoJSON, GeoJSON is very clearly not the optimal storage format for your data model. All the bitching & moaning in the world isn’t going to change that.

    1. James Fee Avatar

      How so, how is it not optimal? GeoJSON is perfectly fine.

      1. Samuel Jenkins Avatar
        Samuel Jenkins

        You should do a twitter poll, and see how many of your followers think GeoJSON makes any sense for your data model.

        1. James Fee Avatar

          Seriously? I don’t need a poll to tell me most folks think this is just fine. You still didn’t tell me how it isn’t optimal?

          1. Samuel Jenkins Avatar
            Samuel Jenkins

            I look forward to your forthcoming blog entry “Just Because You Can Doesn’t Mean You Should”

  3. Dmitri from 2008 Avatar
    Dmitri from 2008

    Manifold would read that better than any other inferior GIS.

    1. Todd Avatar
      Todd

      NESTED GEOJSON OBJECTS AND QGIS
      I know this post is a couple of years old, but I ran across it when researching the exact issue with my own geojson data in QGIS. I don’t know if this will hit everyone’s use case, but I did find a solution to pulling multi-level array/dict data out of the geojson properties. In my case I needed to display labels based on values a couple of levels down in the json. Simplified it looked like this:

      “properties”:{
      “object1”: “1”
      “object2”: “a”
      “metrics”: [
      { “name”: “metric1”, “score”: “score1” },
      { “name”: “metric2”, “score”: “score2” },
      { “name”: “metric3”, “score”: “score3” }
      ]

      The actual data was a lot more complicated, but you get the idea. I needed to display “score3” for each feature (polygon) on the map. It took a bit of experimentation, but I was able to build an expression in the expression dialog (next to the Label in Layer Styling) – actually quite simple:

      from_json(metrics)[2][‘score’]

      The ‘from_json’ function converts the string from ‘metrics’ to a json object, that can then be addressed by index for an array and/or key for a dict type object. I saved the expression in ‘User expression’ and then also was able to save the Style, so that all I need to do is load the saved style and it works. I can also share the Style file with others. The expression dialog shows up in a lot of places, making this something that could be useful across a number of QGIS capabilities. It also looks like something more complex could be done with the Function Editor. Hope this helps someone else.