Skip to content
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

Empty Intersection Issue when executing RS_Clip after RS_Intersects #1583

Closed
rhemanthk93 opened this issue Sep 10, 2024 · 5 comments · Fixed by #1586
Closed

Empty Intersection Issue when executing RS_Clip after RS_Intersects #1583

rhemanthk93 opened this issue Sep 10, 2024 · 5 comments · Fixed by #1586

Comments

@rhemanthk93
Copy link

rhemanthk93 commented Sep 10, 2024

Expected behavior

In PostGIS, when running ST_Clip on the same dataset, it seems to ignore problematic rows / data that may have "empty" intersections. So RS_Clip should not throw an exception for 1 or 2 problematic rows but instead just chose to ignore them as null, since i am relying on RS_Intersects to provide me the intersections between raster and geometry

Actual behavior

RS_Clip throws EmptyIntersectionException("Crop envelope does not intersect in model space") when interceptions identified by RS_Intersects happened to be "insignificant to clip", causing the whole spark job to fail.

Right now i am trying to circumvent this issue to "filter out these problematic interceptions" through the following:

SQL query to filter rows where the raster envelope intersects with the geometry

valid_intercept_df = spark.sql("""
SELECT *
FROM interceptions_table
WHERE
ST_Overlaps(rast_envelope, geometry) OR
ST_Within(rast_envelope, geometry) OR
ST_Contains(rast_envelope, geometry)
""")

where i use RS_envelope on the rast column and then pass it into the aforementioned three where clauses alongside the geometry, since the three methods take in two geoms. Based on trial and error, this is what helped to eliminate the problematic row that was identified by RS_Intercept as an interception but upon attempting to clip using RS_Clip, throws the EmptyIntersectionException.

Steps to reproduce the problem

compute_query = """
SELECT
paoi.project_id,
SUM(RS_CountValue(RS_BandAsArray(RS_Clip(lc.rast, 1, paoi.geometry, 0), 1), 1)) as 1_total_count
FROM
raster_table lc, project_area_of_interest_comparison paoi
WHERE RS_Intersects(lc.rast, paoi.geometry)
Group By
paoi.project_id
"""

Settings

Sedona version = 1.6.1

Apache Spark version = 3.5.0-amzn-1

Apache Flink version = Not Sure

API type = Python

Scala version = NA

JRE version = NA

Python version = 3.9.16

Environment = Jupyter Notebook on EMR Studio (EMR serverless)

Copy link

Thank you for your interest in Apache Sedona! We appreciate you opening your first issue. Contributions like yours help make Apache Sedona better.

@jiayuasu
Copy link
Member

@Kontinuation Would you please take a look?

@Kontinuation
Copy link
Member

@Kontinuation Would you please take a look?

I'd like to make RS_Clip lenient by default, just like what we did to RS_ZonalStats in #1257.

@jiayuasu
Copy link
Member

@Kontinuation Let's do it!

@rhemanthk93
Copy link
Author

thank you for the change! When will this change be released? @jiayuasu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants