GeoPandas 空间连接 - 结果数据集中没有匹配的行

问题描述 投票:0回答:1

我有两个 GeoPandas DataFrames 正在尝试加入。我为两者都设置了

crs
,然后使用
sjoin
sjoin_nearest
,但是,我没有看到任何结果。列是
NaNs
.

import pandas as pd
import geopandas as gpd

df1 = pd.DataFrame({
                    'id': [0, 1, 2], 
                    'Lat': [41.8896878, 33.155480, 33.155480],
                    'Long': [-87.6188015, -96.731630, -96.731630]
                  })


gdf1 = gpd.GeoDataFrame(df1, geometry=gpd.points_from_xy(df1.Long, df1.Lat))

# set crs for buffer calculations
gdf1.set_crs("ESRI:102003", inplace=True)



df2 = pd.DataFrame({
                    'val': ['a', 'b', 'c'],
                    'Lat': [41.8896, 33.155480, 33.155480],
                    'Long': [-87.61762, -96.731630, -96.731630]
                  })

    

gdf2 = gpd.GeoDataFrame(df2, geometry=gpd.points_from_xy(df2.Long, df2.Lat))

# set crs for buffer calculations
gdf2.set_crs("ESRI:102003", inplace=True)


# Spatial Join
joined_gdf = gpd.sjoin_nearest(
                               gdf1,  # Point geometry
                               gdf2,  # Point geometry
                               how='left',
                               max_distance = 0.001, # in meters
                               distance_col = "distances"
                              )

我没有看到我期望的结果,即在结果连接的数据框中没有匹配/行。不确定空间连接发生了什么。

右表的列都是

NaNs
。两个 DataFrame 的
crs
是:

<Derived Projected CRS: ESRI:102003>
Name: USA_Contiguous_Albers_Equal_Area_Conic
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: United States (USA) - CONUS onshore - Alabama; Arizona; Arkansas; California; Colorado; Connecticut; Delaware; Florida; Georgia; Idaho; Illinois; Indiana; Iowa; Kansas; Kentucky; Louisiana; Maine; Maryland; Massachusetts; Michigan; Minnesota; Mississippi; Missouri; Montana; Nebraska; Nevada; New Hampshire; New Jersey; New Mexico; New York; North Carolina; North Dakota; Ohio; Oklahoma; Oregon; Pennsylvania; Rhode Island; South Carolina; South Dakota; Tennessee; Texas; Utah; Vermont; Virginia; Washington; West Virginia; Wisconsin; Wyoming.
- bounds: (-124.79, 24.41, -66.91, 49.38)
Coordinate Operation:
- name: USA_Contiguous_Albers_Equal_Area_Conic
- method: Albers Equal Area
Datum: North American Datum 1983
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
pandas geospatial geopandas
1个回答
0
投票

你的点的 crs 是纬度/经度(例如 WGS84/EPSG:4326)。您应该使用 gdf.set_crs

 
set crs,然后使用
gdf.to_crs
转换为所需的 crs,这实际上转换了数据:


gdf1 = (
    gdf1.set_crs("EPSG:4326")
    .to_crs("ESRI:102003")
)

当使用您的代码进行解释时,您提供的值不在您正在使用的 crs 的有效点域内(因为它们都在 (0, 0) 纬度/经度的一百米范围内)。

© www.soinside.com 2019 - 2024. All rights reserved.