-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add documentation how to load a local topojson file #1316
Comments
The file needs to be accessible via HTTP from the renderer. In Juypyter notebook, for example, you can put the file in the same directory as the notebook and then pass the filename to |
I tried this , but not working, I save the json file in the same directory
|
What frontend are you using? This won't work, for example, in Binder, but it will work in a local JupyterLab frontend. |
I am using a local jupyter lab, and it produces empty chart |
Does it work if you use a local data file for a basic dataset? i.e. this works for me in a local JupyterLab: import altair as alt
from vega_datasets import data
cars = data.cars()
filename = 'cars.json'
cars.to_json(filename, orient='records')
alt.Chart(filename).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N'
) |
yes that code works |
In that case, I suspect the issue is your topojson file is not correctly formatted. To be honest, I don't know much about topojson and have not used this part of the library, so I'm not going to be much help in debugging it. I'd start by comparing the format of your topojson file with the files used in the examples, and see if there are any glaring inconsistencies. If you figure anything out and would like to add hints to the documentation, that would be greatly appreciated. |
yeah, I found the issue, the second argument in alt.topo_feature has to be the name of the objects not the id, in the attached example "objects":{"foundation":{
for some reason, we need to add "properties" to the field name ? thanks for the help |
I know some of TopoJSON, as 'm working on a Python package regarding this extension of GeoJSON ( Without explaining the format, you are dealing with nested objects. So in the This layer or So in order to access these attribute information you have to add {
"type": "Topology",
"arcs": [[[641, 1092], [0, 116], [89, 0], [0, -116], [-89, 0]]],
"objects": {
"foundation": {
"type": "GeometryCollection",
"geometries": [
{
"arcs": [[0]],
"type": "Polygon",
"properties": {
"id": 22,
"width": 0.000558,
"height": 0.000719,
"area": 0,
"perimeter": 0.002555,
"type": "foundation"
}
}
]
}
}
} Your issue have been discussed before on the Vega-repo: vega/vega#1319
|
Dear future reader:
This will fail due to CORS for reasons I cannot imagine. So, make sure you check the browser console when you do anything in Altair in Jupyter Notebook and make sure you do not run into CORS errors. |
@djouallah your problem literally solved my problem.I wanted to plot for the country India...It is sorted now ` url = "https://raw.githubusercontent.com/deldersveld/topojson/master/countries/india/india-states.json" source = alt.topo_feature(url, "IND_adm1") alt.Chart(source).mark_geoshape().encode( |
is this pseudo code supported
all the documentation is using "data.world_110m.url", how about local topojson or geojson files ?
The text was updated successfully, but these errors were encountered: