question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map view fails if GeoJSON transform is passed a `null` feature value.

See original GitHub issue

When linking a data source to a geo data source with lookup, we have two choices. Either make the geo data the primary data source and lookup the secondary attribute data; or make the attribute data primary and lookup the geo data.

When the geo data are primary and not all secondary data match, only those matched are encoded, which is expected and desired behaviour:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {
    "url": "https://vega.github.io/vega-lite/data/us-10m.json",
    "format": {"type": "topojson", "feature": "states"}
  },
  "projection": {"type": "albersUsa"},
  "transform": [
    {
      "lookup": "id",
      "from": {
        "data": {
          "values": [
            {"attId": 53, "att": "Washington"},
            {"attId": 12, "att": "Florida"}
          ]
        },
        "key": "attId",
        "fields": ["att"]
      }
    }
  ],
  "encoding": {"color": {"field": "att", "type": "nominal"}},
  "mark": "geoshape"
}
primaryGeo

If the attribute data are made primary, only the matched attributes are shown, which again is desired and expected behaviour:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {
    "values": [
      {"attId": 12, "att": "Florida"},
      {"attId": 53, "att": "Washington"}
    ]
  },
  "projection": {"type": "albersUsa"},
  "transform": [
    {
      "lookup": "attId",
      "from": {
        "data": {
          "url": "https://vega.github.io/vega-lite/data/us-10m.json",
          "format": {"type": "topojson", "feature": "states"}
        },
        "key": "id"
      },
      "as": "geo"
    }
  ],
  "encoding": {
    "color": {"field": "att", "type": "nominal"},
    "shape": {"field": "geo", "type": "geojson"}
  },
  "mark": "geoshape"
}
primaryAtt

However, in this attribute-as-primary spec, if one of the attributes is not found, then none of the map features is shown (line 7):

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {
    "values": [
      {"attId": 12, "att": "Florida"},
      {"attId": 53, "att": "Washington"},
      {"attId": 999, "att": "Dummy attribute"}
    ]
  },
  "projection": {"type": "albersUsa"},
  "transform": [
    {
      "lookup": "attId",
      "from": {
        "data": {
          "url": "https://vega.github.io/vega-lite/data/us-10m.json",
          "format": {"type": "topojson", "feature": "states"}
        },
        "key": "id"
      },
      "as": "geo"
    }
  ],
  "encoding": {
    "color": {"field": "att", "type": "nominal"},
    "shape": {"field": "geo", "type": "geojson"}
  },
  "mark": "geoshape"
}

This seems like a bug to me. I would expect it to show at least the matched geoshapes rather than nothing at all. It is problematic because it is not always obvious what the complete set of feature ids/properties are in a topojson file, so it can be quite easy to include a non-matching attribute.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
jheercommented, Apr 19, 2019

Thanks @jwoLondon! @domoritz: this is not about full joins, a lookup is perfectly sufficient here.

The problem is that D3’s auto-fit logic for projections is breaking because we’re passing a `null` GeoJSON feature into it. So I consider this a Vega bug (fortunately an easy one to fix: just add a filter to our GeoJSON marshaling) and I will transfer the issue over to vega/vega.

In the meantime, if you add explicit scale and/or translate parameters to the projection definition the auto-fit logic will be disabled and you can see the map (though without automatic fitting, of course).

0reactions
mattijncommented, Feb 24, 2021

Ah v5 fixed it (by this issue: https://github.com/vega/vega-lite/issues/6163). image Congrats!

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenLayers3 and GeoJSON data with null features
If your GeoJSON has "features": null , then it is is invalid. From the GeoJSON spec: An object of type "FeatureCollection" must have...
Read more >
No content to map due to end-of-input jackson parser
In my case the problem was caused by my passing a null InputStream to the ObjectMapper.readValue call:
Read more >
Handling JSON null and empty arrays and objects - IBM
JSON has a special value called null which can be set on any type of data including arrays, objects, number and boolean types....
Read more >
3 ways to ignore null fields while converting Java object to ...
For example, if you have a Java object which has a String field whose value is null when you convert this object to...
Read more >
Debugging guide | Google Earth Engine
The " ...is not a function " error may result from Earth Engine not knowing the type of a variable. Common manifestations of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found