简体   繁体   English

如何使用GeoPandas绘制多个图层

[英]How to plot several layers using GeoPandas

I am trying to use geopandas to plot some info over a map. 我正在尝试使用geopandas在地图上绘制一些信息。 The first thing that I do is to upload a shape file of New York City: 我要做的第一件事是上传纽约市的形状文件:

nyc_boroughBoundaries = geopandas.read_file ("nybb_19b2")

This is returning a geodataframe: 这将返回地理数据框:

type (nyc_boroughBoundaries)

geopandas.geodataframe.GeoDataFrame

And has a geometry column: 并具有一个几何列:

geometry

(POLYGON ((1012821.805786133 229228.2645874023...
(POLYGON ((970217.0223999023 145643.3322143555...
(POLYGON ((1029606.076599121 156073.8142089844...

I am repeating the same process to load some information about new constructions in NYC 我正在重复相同的过程以加载有关纽约市新建筑的一些信息

geo_df_NB_2018["Coordinates"]

POINT (40.62722 -73.969634)
POINT (40.764575 -73.955421)
POINT (40.525584 -74.166414)
POINT (40.742845 -73.89083100000001)
POINT (40.679859 -73.93992

Then I am trying to plot both geodataframes in one single map doing the following: 然后,我尝试在一个单一的地图中绘制两个地理数据框,并执行以下操作:

fig, ax = plt.subplots (figsize = (15,15))
geo_df_NB_2018.plot(ax = ax, alpha = 0.7, color = "pink")
nyc_boroughBoundaries.plot(ax = ax)

However, they are being displayed in different parts of the figure. 但是,它们显示在图的不同部分。

在此处输入图片说明

Thanks! 谢谢!

You have different projections. 您有不同的预测。 They need to be the same to be plotted together. 它们必须相同才能一起绘制。 Look at your coordinates, they are clearly different. 看你的坐标,它们显然是不同的。 Moreover, as @steven pointed out, you have switched latitude and longitude. 此外,正如@steven所指出的,您已经切换了纬度和经度。 Fix that first and then reproject: 首先修复该问题,然后重新投影:

# convert CRS to the same as nyc_boroughBoundaries has
geo_df_NB_2018 = geo_df_NB_2018.to_crs(nyc_boroughBoundaries.crs)

fig, ax = plt.subplots(figsize=(15, 15))
geo_df_NB_2018.plot(ax=ax, alpha=0.7, color="pink")
nyc_boroughBoundaries.plot(ax=ax)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM