rapidsai / cuspatial

CUDA-accelerated GIS and spatiotemporal algorithms
https://docs.rapids.ai/api/cuspatial/stable/
Apache License 2.0
622 stars 154 forks source link

[FEA] Begin supporting GeoPandas `.sjoin` syntax #687

Open thomcom opened 2 years ago

thomcom commented 2 years ago

Is your feature request related to a problem? Please describe. Spatial join is usually an application of either point-in-polygon or geometry intersection. Our point-in-polygon implementation is mature enough to begin using it as pythonic use of spatial join. In this issue I propose that we add GeoDataFrame.sjoin that will implement the functionality for point-in-polygon that GeoPandas gives an example of in https://geopandas.org/en/stable/docs/reference/api/geopandas.sjoin.html

Describe the solution you'd like

countries = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
cities = geopandas.read_file(geopandas.datasets.get_path("naturalearth_cities"))
countries.head()  
    pop_est      continent                      name iso_a3  gdp_md_est                                           geometry
0     920938        Oceania                      Fiji    FJI      8374.0  MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1   53950935         Africa                  Tanzania    TZA    150600.0  POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2     603253         Africa                 W. Sahara    ESH       906.5  POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3   35623680  North America                    Canada    CAN   1674000.0  MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4  326625791  North America  United States of America    USA  18560000.0  MULTIPOLYGON (((-122.84000 49.00000, -120.0000...
cities.head()
        name                   geometry
0  Vatican City  POINT (12.45339 41.90328)
1    San Marino  POINT (12.44177 43.93610)
2         Vaduz   POINT (9.51667 47.13372)
3    Luxembourg   POINT (6.13000 49.61166)
4       Palikir  POINT (158.14997 6.91664)
cities_w_country_data = geopandas.sjoin(cities, countries)
cities_w_country_data.head()  
        name_left                   geometry  index_right   pop_est continent name_right iso_a3  gdp_md_est
0    Vatican City  POINT (12.45339 41.90328)          141  62137802    Europe      Italy    ITA   2221000.0
1      San Marino  POINT (12.44177 43.93610)          141  62137802    Europe      Italy    ITA   2221000.0
192          Rome  POINT (12.48131 41.89790)          141  62137802    Europe      Italy    ITA   2221000.0
2           Vaduz   POINT (9.51667 47.13372)          114   8754413    Europe    Austria    AUT    416600.0
184        Vienna  POINT (16.36469 48.20196)          114   8754413    Europe    Austria    AUT    416600.0

Describe alternatives you've considered It is possible to write this fairly easily, manually, using point-in-polygon.

Additional context This feature shouldn't require any C++ additions.

harrism commented 2 years ago

@jarmak-nv should we create a milestone for Spatial Join?

Bencpr commented 1 year ago

Hi, very interested in this, any news ?

harrism commented 1 year ago

We do not have sjoin but I think GeoSeries.contains or GeoSeries.contains_properly could be used?

CC @thomcom @jarmak-nv

Tadusko commented 1 week ago

Also interested, this would be a great addition.