首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Geopandas中的EPSG之间切换(绘图和添加背景图)

如何在Geopandas中的EPSG之间切换(绘图和添加背景图)
EN

Stack Overflow用户
提问于 2020-02-28 05:35:03
回答 1查看 176关注 0票数 0

我正试着在纽约市地图上画一些“车站”坐标。我使用Geopandas(gpd)创建了一个GeoDataFrame,并使用EPSG4326从gpd.datasets创建了一个NYC地图。

此外,我还想按照Geopandas教程(https://geopandas.org/gallery/plotting_basemap_background.html)在我的地图上添加一张背景图像。但是,这适用于3857的EPSG。有没有办法维护信息和更改EPSG?

这是我的代码库

代码语言:javascript
复制
# Creating GeoDataFrame
gdf = gpd.GeoDataFrame(stations, geometry=gpd.points_from_xy(stations.Longitude, stations.Latitude))
# Find the NYC Borough map from contextily pkg
nyc = gpd.read_file(gpd.datasets.get_path('nybb')).to_crs(epsg=4326)
ax = nyc.plot(figsize=(10,10), alpha=0.3, edgecolor="k")

# Contextily adding background image
def add_basemap(ax, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png'):
    xmin, xmax, ymin, ymax = ax.axis()
    basemap, extent = ctx.bounds2img(xmin, ymin, xmax, ymax, zoom=zoom, url=url)
    ax.imshow(basemap, extent=extent, interpolation='bilinear')
    # restore original x/y limits
    ax.axis((xmin, xmax, ymin, ymax))

add_basemap(ax, zoom=10, url='http://tile.stamen.com/toner-lite/tileZ/tileX/tileY.png')
# nyc.to_crs(epsg=4326)
gdf.plot(ax=ax, color="red")
ax.set_axis_off()
EN

回答 1

Stack Overflow用户

发布于 2020-07-23 14:55:46

是的有。通常,您可以通过以下方式将数据的EPSG信息传递给的add_basemap()函数

代码语言:javascript
复制
add_basemap(ax, crs=nyc.crs.to_string(), zoom=10, url='...')

唯一需要的是,您已经在您的数据上设置了适当的CRS。

在您的示例中,您可能应该添加contextily.wrap_tiles()函数。

代码语言:javascript
复制
tr_basemap, tr_extent = ctx.wrap_tiles(basemap, extent, t_crs='EPSG:4326')

这应该会给你你想要的。

要进一步阅读,您可以查看此处:

https://contextily.readthedocs.io/en/latest/warping_guide.html#Convert-the-tiles-to-your-data%E2%80%99s-CRS https://contextily.readthedocs.io/en/latest/reference.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60442081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档