-
Notifications
You must be signed in to change notification settings - Fork 766
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
Altair not plotting geojson correctly #1612
Comments
Altair (via Vega-Lite) supports topojson for map shapes. I'm not very familiar with the various geographic data formats, so I don't know what to recommend when it comes to shape files. You might ask on the Vega-Lite issue tracker whether there is a way to visualize shapefiles in Vega-Lite; that answer will apply to Altair as well. |
Altair plots by default geographic coordinates in WGS 84 (also known as epsg:4326). Since your coordinates are not coordinates in degrees but in meters and since your data represents England I imagined it is projected in the British National Grid (OSGB 1936, epsg 27700). Setting the projection to import altair as alt
import geopandas as gpd
# load raw url in geodataframe
url = 'https://raw.githubusercontent.com/joepropellernet/Plotting_Police_areas/master/Police_areas.geojson'
gdf = gpd.read_file(url)
# set projection and reproject
gdf.crs = {'init' :'epsg:27700'}
gdf = gdf.to_crs({'init': 'epsg:4326'})
# define inline geojson data object
data_geojson = alt.InlineData(values=gdf.to_json(), format=alt.DataFormat(property='features',type='json'))
# chart object
alt.Chart(data_geojson).mark_geoshape(
).encode(
color=alt.Color("properties.pfa16nm:N", legend=alt.Legend(columns=2))
) |
Fixed the typos! |
That's amazing Matt and Jake! Thanks so much, I had no idea of the different types of geojson and the limitations of Vega-lite. Would it be possible to put the specific projection that Altair prefers in the documentation? |
This issue can be closed since the projection part is documented here: https://altair-viz.github.io/user_guide/data.html#projections |
Thanks! |
I'm trying to plot a geojson in a notebook and while the geopandas plot looks like this;
the Altair output looks like this;
As the data is pretty big, I'll not copy it out in full here! The full notebook and data are here: https://github.com/joepropellernet/Plotting_Police_areas and should be able to replicate the issue.
One thought I had is that the geojson alternates between polygons and multipolygons but even filtering out to either one or the other doesn't solve the issue.
The text was updated successfully, but these errors were encountered: