Aug 13, 2021 09:05 AM
I am having difficulties getting GeoJSON data from a table to generate a Vega-Lite graphic. My table has one formula field called MapGeo which generates the GeoJSON “Feature” (ie the shape), one Feature per record. The “data” property is set as follows. Vega Lite plots the title, nothing else, just blank. No errors shown.
"data":{"values":{"field":"MapGeo","type":"json"}}
I performed a test to see if the data from the table is valid. I copy-pasted the features from each record and set to static data (not from the table). That worked! Below is the static configuration that works, showing two rectangles.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"title": "Test GeoJSON",
"width": "container",
"height": "container",
"data":{"values":[
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[2,3],[4,3],[4,5],[2,5],[2,3]]
}
},
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[0,0],[5,0],[5,2],[0,2],[0,0]]
}
}
]},
"mark": {
"type": "geoshape",
"fill": "#4cc09d",
"stroke": "#757575",
"strokeWidth": 2.5
}
}
However, I need to pull the data from the table, cannot be static. What am I missing?
My suspicion is that the “data” property is not setup correctly and/or that the data coming from the table is wrapped up in additional JSON; which I cannot see in Vega-Lite. Probably need to reference some additional properties to map the data to the feature.
Any suggestion would be appreciated.
Example of the output…
Aug 23, 2021 01:38 PM
No worries - I made a duplicate of your base and have full access. Yea! for poor security in Airtable!
Aug 23, 2021 01:56 PM
I kind of figured you would be able to copy it. Thanks for looking at this.
Aug 25, 2021 08:54 AM
Update - I was able to create a number of examples where features can be stored as JSON and processed in Vega-Lite. I had to refresh my memory on this and to achieve it I used a custom app like this.
Doing it in the Vega-Lite Airtable app is not so easy, but it is possible using transformations and a data source that describes the data source format as json (specifically geoJSON). But doing so requires a very different data model than you’ve shared with me. Example…
I believe data as geoJSON features is only possible if each record contains a feature, so you probably have to rethink your data model to get where you want to go. Also, you will need to transform the data as it is absorbed into the Vega-engine. This, as an example, will not work.
But this approach will… as you can see in this snippet from the mapping example shown here, I’m updating the Vega data object with the feature objects stored in Airtable fields.
Aug 25, 2021 12:25 PM
@Bill_French Thank you kindly for the feedback. I have to agree that plotting the geoshape marks with AirTable data is not simple; even though it works perfectly well as static inline data. I will continue to poke at it some more.
Aug 25, 2021 12:52 PM
Which is the same as saying it doesn’t work at all with Airtable data. :winking_face:
The challenge is that Airtable’s custom app made openly available in GitHub assumes the data is an array of records and fields, and as such, I think you you have four possible outs: