Is it possible to load a .geojson file, without first converting it to topojson, as data for vega lite? Many public datasets come in geojson formats and not topojson formats, so analyzing them would be easier if this was supported.
GeoJSON is just JSON, so shouldn't (in principle) require any special loading beyond standard JSON support. You may need to use the "format": {"property": "features"} flag to pull out an array of features when loading a GeoJSON FeatureCollection. Hope that helps!
My understanding is that it expects one row per line of the JSON file. With my geojson file, the features key has a list of the rows. Each one has a properties key that has the columns and a geometry key that lists the geo type, like this:
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"OBJECTID":2253,"PIN":"30B-108","MapParID":"30B-108","PID":2569, ...} ,"geometry":{"type":"Polygon","coordinates":[[[-72.4742182539,42.3149885445],[-72.4742908754,42.314618417],[-72.4748813944,42.3146776494],[-72.4750120052,42.3146907594],...
I am not sure exactly where to go from this non working vega lite spec:
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.1.json",
"width": 500,
"height": 300,
"data": {
"url": "https://maps-amherstma.opendata.arcgis.com/datasets/d887750c3b4a40c09e753642988e7aee_0.geojson",
"format": {
"property": "features"
}
},
"mark": "geoshape",
"encoding": {
"color": {
"field": "TotalAssessment",
"type": "quantitative"
}
}
}
The TotalAssessment field is nested within the properties object. Here is a modified spec that works for me:
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.1.json",
"width": 500,
"height": 300,
"data": {
"url": "https://maps-amherstma.opendata.arcgis.com/datasets/d887750c3b4a40c09e753642988e7aee_0.geojson",
"format": {
"property": "features"
}
},
"mark": "geoshape",
"encoding": {
"color": {
"field": "properties.TotalAssessment",
"type": "quantitative"
}
}
}
Wow, that's amazing! Thank you!
This tripped me up too. It would be great if "how to access GeoJSON properties", explaining the nesting under property and the syntax to access it, were in the docs somewhere. Would a documentation PR be welcome?
@daveliepmann, I for one would really appreciate that... The maps examples on the website only seem to use topojson, and I didn't find a simple working GeoJSON example until a web search turned up this GitHub issue.
We very much welcome documentation prs, yes!