-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
Remove irrelevant points for view #767
Remove irrelevant points for view #767
Conversation
@gluser1357 Looks like it's failing on our bots treating warnings as errors. Can you fix: https://github.com/postgis/postgis/actions/runs/8474473891/job/23259878295?pr=767
|
It looks like this function is actually stepping on the toes of three other things in PostGIS:
Which of these should we combine together so that there aren't too many copies of the code that does pretty much the same thing? I have a feeling that it might be that it's enough to maybe add more docs to ST_Intersection to link to ST_ClipByBox2D and maybe expose alternative range clipper into ST_ClipByBox2D as some argument. What do you think? |
3e28490
to
3a9d2eb
Compare
I changed variables from signed to unsigned int but I'm not sure if this fixes the problem. Can I start the build myself, or how can I test it the same way as your test (treat warnings as errors)? |
Thank you for the feedback! I see that there are three similar functions, and honestly didn't know about ST_ClipByBox2D. Thank you for the hint. Linking this in the ST_Intersection docs would be great :) I'll test performance and result for our use case next week. The both other functions ST_AsMVTGeom and lwgeom_clip_to_ordinate_range I also didn't tested so far. The reason is that our use case is not related to MVT and I'm not sure about the correct parameters for our use case. We also don't want to reduce resolution (I assume that's what the bounds, extent and buffer parameter are introduced for but perhaps I'm wrong with that?) and we don't need to clip exactly (because this is what already the rendering client does). Perhaps someone could assist me on how to choose approriate parameters for ST_AsMVTGeom for our use case and what steps are required to internally use lwgeom_clip_to_ordinate_range? One advantage of the proposed function over the existing ones above might be that no new coordinates are created and no rounding while computing intersection points has to be applied. For keeping validity of polygons I have one more idea that I'd like to test next week, too. It may involve adding the coordinates given by the bbox corners.
This sounds interesting. Perhaps it is better to add one or two optional parameters to ST_Intersection instead of introducing a new function. But I'm not sure with that? |
That fixed the signed warning issue so we are set for this. |
This reverts commit f6488f6.
@Komzpa: I checked ST_ClipByBox2D - the purpose seems to be indeed very similar. Differences are (see updated docs and illustration at https://github.com/gluser1357/postgis-fork/blob/remove_irrelevant_points_for_view/doc/html/images/static/st_removeirrelevantpointsforview.png):
The visual result within the specified view is the same, as well as the fact that polygons may be invalid afterwards because of self-intersections (outside the view area). I have an idea how to solve this by applying cut-offs on all four edges of the view bbox and could try to add this if there is some interest in that. The other functions you metioned, ST_AsMVTGeom and lwgeom_clip_to_ordinate_range, does likely the same as ST_ClipByBox2D but are not (directly) usable. At least I don't know exactly how I would to that for my case. Thus, I'm skipping further evaluation here for now. Further reviews are welcome :-) |
One of the reasons ST_ClipByBox2D is not really used anymore is because it would produce invalid output for some cases, which many MVT renderers very unhappy with. This resulted in a lot of fiddling around and eventually our adoption of the wagyu clipper for generating MVT geometry. |
Thank you for your feedback. I have two questions:
|
As I recall yes ST_ClipByBox2D can create invalid output. It's focus is on speed rather than validaty. @pramsey @Komzpa Any thoughts to @gluser1357 question. I haven't used ST_AsMVT much directly. |
With my latest commit I added some more checks to decrease the resulting point number or even completely empty the result if possible. Some more notes:
Thank you for further reviews, remaining in hope that it'll make it into 3.5.0 :) |
For the sake of completeness I copy the review comments from the original Trac Ticket https://trac.osgeo.org/postgis/ticket/5705 by mdavis in here:
Alternatively,
What dou you think? @Komzpa: Want to add coderabbitai like in #768 here as well? :-) |
Does anyone else have anything to say before I commit this? I think it's been here long enough. |
@coderabbitai review |
WalkthroughWalkthroughThe recent updates introduce a new function, Changes
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files ignored due to path filters (2)
Files selected for processing (7)
Files skipped from review due to trivial changes (2)
Additional comments not posted (4)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
CREATE OR REPLACE FUNCTION ST_RemoveIrrelevantPointsForView(geometry, box2d) | ||
RETURNS geometry | ||
AS 'MODULE_PATHNAME','ST_RemoveIrrelevantPointsForView' | ||
LANGUAGE 'c' VOLATILE STRICT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing the volatility category from VOLATILE to IMMUTABLE.
If ST_RemoveIrrelevantPointsForView
does not modify the database state and always returns the same result for the same inputs, it should be marked as IMMUTABLE instead of VOLATILE. This can improve query performance as IMMUTABLE functions allow results to be cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree 👍 @gluser1357 This should be marked IMMUTABLE, but I can take care of it if you don't get this in time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
Thank you for merging :) |
Pull request for enhancement request https://trac.osgeo.org/postgis/ticket/5705
See details there, thanks.