-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEA]: Support binary predicates with GeoSeries
- shapely.geometry
object
#1316
Comments
Hi @vboussange! Thanks for submitting this issue - our team has been notified and we'll get back to you as soon as we can! |
Hi @vboussange , thank you for making this issue! Per the documentation of polys = cuspatial.GeoSeries([polygon] * len(s))
s_cu = cuspatial.from_geopandas(s) However, this doesn't get you there yet. cuSpatial also has a limitation of only supporting binary predicates between two "single geometry type" geoseries for the moment. import cudf
import cuspatial
from cuspatial.core._column.geometa import Feature_Enum
import geopandas
from shapely.geometry import Polygon, LineString, Point
def extract_single_geometry_from_series(
s: cuspatial.GeoSeries,
ty: cuspatial.core._column.geometa.Feature_Enum
):
"""Extract objects of type `ty` from GeoSeries `s`."""
types = s._column._meta.input_types
ilocs = cudf.Series(cudf.core.column.arange(len(types)))
df = cudf.DataFrame(data={"types": types, "ilocs": ilocs})
selected = df[df.types == ty.value].ilocs
return s.iloc[selected]
s = geopandas.GeoSeries(
[
Polygon([(0, 0), (2, 2), (0, 2)]),
Polygon([(0, 0), (1, 2), (0, 2)]),
LineString([(0, 0), (0, 2)]),
Point(0, 1),
],
)
polygon = Polygon([(0, 0), (2, 2), (0, 2)])
s_cu = cuspatial.from_geopandas(s)
tys = [Feature_Enum.POLYGON, Feature_Enum.LINESTRING, Feature_Enum.POINT]
partials = []
for ty in tys:
ss_cu = extract_single_geometry_from_series(s_cu, ty)
# Caching the index of the single type objects
idx = ss_cu.index
ss_cu = ss_cu.reset_index(drop=True)
polys = cuspatial.GeoSeries([polygon] * len(ss_cu))
# Compute within of single type geoseries
partial = ss_cu.within(polys)
# Restore index and cache partial results
partial.index = idx
partials.append(partial)
# Combine all results.
result = cudf.concat(partials).sort_index()
print(result) Output:
Please beware that this code will behave significantly slower than GeoPandas due to multiple kernels are launched on a small number of data. The kernel launching overhead dominates the latency. However, if you have a very large dataset, you could benefit from compute speedup. |
within
not working for single polygonGeoSeries
- shapely.geometry
object
Hey there, thanks a lot for the explanation and the workaround. For other points = geopandas.GeoSeries([Point(0,1), Point(2,1), Point(4,2)])
polygons = geopandas.GeoSeries([Polygon([(0, 0), (2, 2), (0, 2)]), Polygon([(0, 0), (1, 2), (0, 2)])])
points_cu = cuspatial.from_geopandas(points)
polygons_cu = cuspatial.from_geopandas(polygons)
cuspatial.point_in_polygon(points_cu, polygons_cu) output
|
Cool! Note that |
@isVoid should we close this now, or keep it open? |
I would like to keep it open as a feature request issue to support |
It should be an easy addition for short-term support - a single shapely geometry object can be placed in a GeoSeries and run as such. |
Version
23.12.01
On which installation method(s) does this occur?
Conda
Describe the issue
Method
within
does not work as expected when used with a single polygon object.Minimum reproducible example
Relevant log output
`AttributeError: 'Polygon' object has no attribute 'column_type'`
Environment details
Other/Misc.
No response
The text was updated successfully, but these errors were encountered: