我的线条无法在 altair.chart.mark_geoshape 中正确绘制
My lines won't plot correctly in altair.chart.mark_geoshape
我需要从 this website
绘制爱达荷州的河流
当我将它加载到 geopandas 并尝试通过 altair.Chart().mark_geoshape() 绘制它时,我的图表出现了一堆随机线,但它们没有按预期绘制.我不知道发生了什么,因为我是地理空间数据方面的新手。
我遵循了这个例子中的模式 https://altair-viz.github.io/gallery/london_tube.html 但我无法绘制线条。
任何想法或如何做到这一点都会有很大帮助!下面是我正在使用的代码。谢谢!
import altair as alt
import geopandas as gpd
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url,'states')
hydro = gpd.read_file('drive/MyDrive/data_cse350/hyd250/hyd250.shp')
rivers = hydro.loc[hydro.FEAT_NAME.isin(['Snake River','Henrys Fork'])]
rchart = alt.Chart(rivers).mark_geoshape().encode(color = 'FEAT_NAME')
idaho = alt.Chart(states).mark_geoshape(fill = 'white',stroke = 'black').project(
'albersUsa'
).transform_calculate(state_id = "(datum.id)"
).transform_filter((alt.datum.state_id)==16)
rchart+idaho```
If you can solve this, that would be great! Thank you for your help! I have already spent waaaayyy too many hours on getting this to work.
没有绘制的原因是geopandas数据坐标系不一样,需要转换成表示经纬度的格式。我对这种事情的经验有限,所以我不得不手工弄清楚。我实际上参考了爱达荷州的地图以确保它匹配。
import altair as alt
import geopandas as gpd
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url,'states')
hydro = gpd.read_file('./data/hyd250/hyd250.shp')
hydro_trans = hydro.to_crs(epsg=4612)
rivers = hydro_trans.loc[hydro.FEAT_NAME.isin(['Snake River','Henrys Fork'])]
rchart = alt.Chart(rivers).mark_geoshape(
filled=False,
strokeWidth=2
).encode(
color='FEAT_NAME'
).properties(
width=600,
height=300
)
idaho = alt.Chart(states).mark_geoshape(
fill=None,
stroke='black'
).project(
'albersUsa'
).transform_calculate(
state_id = "(datum.id)"
).transform_filter(
(alt.datum.state_id)==16
)
rchart+idaho
我需要从 this website
绘制爱达荷州的河流当我将它加载到 geopandas 并尝试通过 altair.Chart().mark_geoshape() 绘制它时,我的图表出现了一堆随机线,但它们没有按预期绘制.我不知道发生了什么,因为我是地理空间数据方面的新手。
我遵循了这个例子中的模式 https://altair-viz.github.io/gallery/london_tube.html 但我无法绘制线条。
任何想法或如何做到这一点都会有很大帮助!下面是我正在使用的代码。谢谢!
import altair as alt
import geopandas as gpd
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url,'states')
hydro = gpd.read_file('drive/MyDrive/data_cse350/hyd250/hyd250.shp')
rivers = hydro.loc[hydro.FEAT_NAME.isin(['Snake River','Henrys Fork'])]
rchart = alt.Chart(rivers).mark_geoshape().encode(color = 'FEAT_NAME')
idaho = alt.Chart(states).mark_geoshape(fill = 'white',stroke = 'black').project(
'albersUsa'
).transform_calculate(state_id = "(datum.id)"
).transform_filter((alt.datum.state_id)==16)
rchart+idaho```
If you can solve this, that would be great! Thank you for your help! I have already spent waaaayyy too many hours on getting this to work.
没有绘制的原因是geopandas数据坐标系不一样,需要转换成表示经纬度的格式。我对这种事情的经验有限,所以我不得不手工弄清楚。我实际上参考了爱达荷州的地图以确保它匹配。
import altair as alt
import geopandas as gpd
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url,'states')
hydro = gpd.read_file('./data/hyd250/hyd250.shp')
hydro_trans = hydro.to_crs(epsg=4612)
rivers = hydro_trans.loc[hydro.FEAT_NAME.isin(['Snake River','Henrys Fork'])]
rchart = alt.Chart(rivers).mark_geoshape(
filled=False,
strokeWidth=2
).encode(
color='FEAT_NAME'
).properties(
width=600,
height=300
)
idaho = alt.Chart(states).mark_geoshape(
fill=None,
stroke='black'
).project(
'albersUsa'
).transform_calculate(
state_id = "(datum.id)"
).transform_filter(
(alt.datum.state_id)==16
)
rchart+idaho