【发布时间】:2015-12-22 16:28:00
【问题描述】:
我正在尝试合并两个地理数据框(想查看每个点所在的多边形)。
下面的代码首先给我一个警告(“CRS does not match!”)
然后是一个错误(“RTreeError: Coordinates must not have minimums more than maximums”)。
那里到底出了什么问题? CRS是坐标系吗?如果是这样,为什么它们的加载方式不同?
import geopandas as gpd
from shapely.geometry import Point, mapping,shape
from geopandas import GeoDataFrame, read_file
#from geopandas.tools import overlay
from geopandas.tools import sjoin
print('Reading points...')
points=pd.read_csv(points_csv)
points['geometry'] = points.apply(lambda z: Point(z.Latitude, z.Longitude), axis=1)
PointsGeodataframe = gpd.GeoDataFrame(points)
print PointsGeodataframe.head()
print('Reading polygons...')
PolygonsGeodataframe = gpd.GeoDataFrame.from_file(china_shapefile+".shp")
print PolygonsGeodataframe.head()
print('Merging GeoDataframes...')
merged=sjoin(PointsGeodataframe, PolygonsGeodataframe, how='left', op='intersects')
#merged = PointsGeodataframe.merge(PolygonsGeodataframe, left_on='iso_alpha2', right_on='ISO2', how='left')
print(merged.head(5))
复制数据链接: Shapefile, GPS points
【问题讨论】:
-
你能提供一个可重现的例子吗? (一些代码来制作重现问题的两个数据框)
-
CRS 确实是一个坐标参考系统。您可以使用 GeoDataFrame 的
.crs属性进行检查。PolygonsGeodataframe将具有在 shapefile 中指定的 CRS,而PointsGeodataframe将没有 CRS。如果两者都有相同的CRS,你可以做PointsGeodataframe.crs = PolygonsGeodataframe.crs -
@joris 代码有点棘手,因为我不知道如何重现 geopandas 用 shapefile 制作的“几何”列,但我已经编辑了问题以提供指向shapefile,以及我正在使用的简单 csv 的链接。
-
@joris using PointsGeodataframe.crs = PolygonsGeodataframe.crs 确实使警告消失了。然而,关于最小值大于最大值的错误仍然存在。