我正试着在纽约市地图上画一些“车站”坐标。我使用Geopandas(gpd)创建了一个GeoDataFrame,并使用EPSG4326从gpd.datasets创建了一个NYC地图。
此外,我还想按照Geopandas教程(https://geopandas.org/gallery/plotting_basemap_background.html)在我的地图上添加一张背景图像。但是,这适用于3857的EPSG。有没有办法维护信息和更改EPSG?
这是我的代码库
# 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()发布于 2020-07-23 14:55:46
是的有。通常,您可以通过以下方式将数据的EPSG信息传递给的add_basemap()函数
add_basemap(ax, crs=nyc.crs.to_string(), zoom=10, url='...')唯一需要的是,您已经在您的数据上设置了适当的CRS。
在您的示例中,您可能应该添加contextily.wrap_tiles()函数。
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
https://stackoverflow.com/questions/60442081
复制相似问题