geopandas 连接返回空行
geopandas sjoin returning empty rows
我有一个 table 所有英国输出区域的多边形结构如下:
newpoly
OBJECTID OA11CD LAD11CD Shape__Are Shape__Len TCITY15NM geometry
67519 67520 E00069658 E06000018 3.396296e+04 1006.464423 Nottingham POLYGON ((456069.067 340766.874, 456057.000 34...
67520 67521 E00069659 E06000018 1.014138e+05 1404.327776 Nottingham POLYGON ((456691.549 340778.104, 456557.864 34...
67521 67522 E00069660 E06000018 1.812783e+04 731.882609 Nottingham POLYGON ((456945.994 340821.233, 456969.220 34...
67522 67523 E00069661 E06000018 2.765546e+04 1112.317587 Nottingham POLYGON ((456527.178 340669.119, 456484.993 34...
67523 67524 E00069662 E06000018 3.647822e+04 964.989153 Nottingham POLYGON ((456301.845 340419.759, 456244.357 34...
和 table 点的结构如下:
restaurants
name latitude longitude geometry
0 Restaurant Sat Bains with rooms 52.925050 -1.167712 POINT (-1.16771 52.92505)
1 Revolution Hockley 52.954090 -1.144025 POINT (-1.14403 52.95409)
2 Revolution Cornerhouse 52.955517 -1.150088 POINT (-1.15009 52.95552)
但当我这样做时:
spatial_join = gpd.sjoin(restaurants, newpoly, op = 'contains')
spatial_join
0 行匹配。
餐厅的几何列是通过以下方式制作的:
restaurants = pd.read_csv('Restaurants_clean.csv')
restaurants = gpd.GeoDataFrame(
restaurants, geometry=gpd.points_from_xy(restaurants.longitude, restaurants.latitude))
我尝试了不同的 'op' 参数,但出现了同样的问题。我确信必须有一个连接,因为所有英国输出区域都存在于 table.
我是不是漏掉了什么?
您正在使用不同的投影。我相信 GeoPandas sjoin
实际上会警告你这一点。按照以下方式创建点层:
restaurants = pd.read_csv('Restaurants_clean.csv')
restaurants = gpd.GeoDataFrame(
restaurants,
geometry=gpd.points_from_xy(restaurants.longitude, restaurants.latitude),
crs=4326)
restaurants = restaurants.to_crs(newpoly.crs)
我先指定输入的CRS(为4326,是WS84的EPSG码,即lon/lat坐标)然后我re-projecting数据到同一个CRS newpoly
有(我假设 27700)。
我有一个 table 所有英国输出区域的多边形结构如下:
newpoly
OBJECTID OA11CD LAD11CD Shape__Are Shape__Len TCITY15NM geometry
67519 67520 E00069658 E06000018 3.396296e+04 1006.464423 Nottingham POLYGON ((456069.067 340766.874, 456057.000 34...
67520 67521 E00069659 E06000018 1.014138e+05 1404.327776 Nottingham POLYGON ((456691.549 340778.104, 456557.864 34...
67521 67522 E00069660 E06000018 1.812783e+04 731.882609 Nottingham POLYGON ((456945.994 340821.233, 456969.220 34...
67522 67523 E00069661 E06000018 2.765546e+04 1112.317587 Nottingham POLYGON ((456527.178 340669.119, 456484.993 34...
67523 67524 E00069662 E06000018 3.647822e+04 964.989153 Nottingham POLYGON ((456301.845 340419.759, 456244.357 34...
和 table 点的结构如下:
restaurants
name latitude longitude geometry
0 Restaurant Sat Bains with rooms 52.925050 -1.167712 POINT (-1.16771 52.92505)
1 Revolution Hockley 52.954090 -1.144025 POINT (-1.14403 52.95409)
2 Revolution Cornerhouse 52.955517 -1.150088 POINT (-1.15009 52.95552)
但当我这样做时:
spatial_join = gpd.sjoin(restaurants, newpoly, op = 'contains')
spatial_join
0 行匹配。
餐厅的几何列是通过以下方式制作的:
restaurants = pd.read_csv('Restaurants_clean.csv')
restaurants = gpd.GeoDataFrame(
restaurants, geometry=gpd.points_from_xy(restaurants.longitude, restaurants.latitude))
我尝试了不同的 'op' 参数,但出现了同样的问题。我确信必须有一个连接,因为所有英国输出区域都存在于 table.
我是不是漏掉了什么?
您正在使用不同的投影。我相信 GeoPandas sjoin
实际上会警告你这一点。按照以下方式创建点层:
restaurants = pd.read_csv('Restaurants_clean.csv')
restaurants = gpd.GeoDataFrame(
restaurants,
geometry=gpd.points_from_xy(restaurants.longitude, restaurants.latitude),
crs=4326)
restaurants = restaurants.to_crs(newpoly.crs)
我先指定输入的CRS(为4326,是WS84的EPSG码,即lon/lat坐标)然后我re-projecting数据到同一个CRS newpoly
有(我假设 27700)。