我正在尝试合并两个地理数据框(想查看每个点位于哪个多边形内)。
以下代码首先给我一个警告(“
到底出了什么问题?CRS代表坐标系吗?如果是,为什么它们没有以相同的方式加载?
以下代码首先给我一个警告(“
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))
.crs
属性进行检查。PolygonsGeodataframe
将具有在shapefile中指定的CRS,而PointsGeodataframe
将没有CRS。如果两者具有相同的CRS,则可以执行PointsGeodataframe.crs = PolygonsGeodataframe.crs
。 - joris