Opened 13 years ago

Closed 11 years ago

#846 closed enhancement (wontfix)

Cleaning up around and enhance point in polygon tests around the code

Reported by: nicklas Owned by: nicklas
Priority: medium Milestone: PostGIS 2.1.0
Component: postgis Version: master
Keywords: Cc:

Description

Today we have four different point in ring tests.

geographic and 3D we leave separate, but the two others can be merged.

pt_in_ring_2d in liblwgeom/measures.c and (counting crossing)
point_in_ring in postgis/lwgeom_functions_analytic.c (counting winding)

they do the same thing in different ways with quite differnt api.

I would like to enhance point_in_ring by reducing the calculations for segments strict above or strict below the point, and then adjust the distance functions to also use this function after moving it to lilwgeom library.

Today pt_in_ring_2d outputs 0 for point outside ring and 1 for point inside.

point_in_ring outputs 1 for point in ring, -1 for opint outside ring and 0 for point on boundary.

Change History (17)

comment:1 by strk, 13 years ago

I think a good plan would be: 1) Move the winding one under liblwgeom/ 2) unit-test the winding one 3) port all clients of the crossing one to the winding one 4) -OPTIONAL- update the interface of the crossing one

I'd think the optional step (4) might be nice for comparing the two algorithms.

comment:2 by nicklas, 13 years ago

Sounds great to me

By updating interface you mean the proposed enhancement?

comment:3 by nicklas, 13 years ago

BTW, don't hesitate if you feel like you want to do it :-)

Otherwise I think I can try to do it coming weekend.

comment:4 by strk, 13 years ago

By updating interface I meant have it return -1, 0 or 1 with the same semantic of the other.

And no, I don't feel like I want to do it, sorry

comment:5 by nicklas, 13 years ago

Hmm, I did forget the fifth point in polygon. The point_in_polygon_rtree.

Does anyone know if that for some reason is called from outside so Doxygen doesn't see it. If so, I guess that should be left in postgis folder and only move point_in_polygon.

BTW, I see Doxygen thinks that one of the 3d distance functions calls point_in_polygon because I have used intersects as variable name. see the graph in the bottom of this link: http://postgis.refractions.net/documentation/postgis-doxygen/de/dd0/lwgeom__functions__analytic_8c_ac03a9d336c58e8ca7b35195ba20513c.html#ac03a9d336c58e8ca7b35195ba20513c

Is that only a doxygen problem or should I change variable name?

comment:6 by strk, 13 years ago

don't rely on doxygen to know what's used and what not. if in dubt, rename the function (where implemented) adding a _ prefix or something and see if the code builds/link…

comment:7 by nicklas, 13 years ago

I think I have found out what point_in_ring_rtree is. It is the prepared geometry version. A 1D index delivers all line segments that is crossing the y-value of the point. That means point_in_ring_rtree iterates through an array of line segments instead of a pointarray. So, we will need that implementation too. But I will at least try to merge pt_in_ring and point_in_ring.

comment:8 by nicklas, 13 years ago

This one was a little harder than I thought. What I wanted to do as described above was to merge the point in polygon functions related to distance and the one related to intersects.

The problem is that the intersects version has implemented a tolerance which is not used in the distance version. The tolerance implementation seems not to be robust as described in #852. Because of that I don't want to get that into the distance-calculations and I don't dare removing it from the intersects calculations because I have difficulties to see all the consequences.

I am afraid that this is quite a big discussion hiding here about how to or how to not handle tolerances. We meet the problems of tolerance in many parts of the code and maybe it gets even more important when getting to 3D when we have the problem of coplanar polygons and linestrings.

So, can anyone guide me. Should we just move it to "future" or close the ticket as won't fix or should we find a strategy for tolerance that can be used all over PostGIS (in this case both distance and intersects)

comment:9 by strk, 13 years ago

Fixing the current operational bug is surely higher priority than moving any code around. Only, if the bogus code is not in liblwgeom/ it would be harder to regress-test, which is the reason for steps (1) and (2) suggested in first comment.

Note that we were using "winding" and "crossing" naming before, while you talk about "intersects" and "distance" now. Which is which ? Naming and inline documentation would help a lot in reducing the confusion.

comment:10 by nicklas, 13 years ago

Sandro

By operational bug, do you mean #852? The rest of the bugs from those areas of the code you have fixed in other tickets I think?

About winding, crossing distance and intersects, sorry for messing things up: distance functions uses counting crossings algorithm and st_intersects (the postgis part, point in polygon) uses counting winding).

comment:11 by strk, 13 years ago

I'm concerned about #884 , dunno if dependent by #852 or not, but it's a nasty one.

comment:12 by chodgson, 13 years ago

#884 is actually just a logical error, there is a difference in the logic between point_in_multipoly_rtree and point_in_multipoly. I'll have a fix for it committed by tomorrow.

#547 advocates removing the _rtree stuff entirely, as long as it is similarly quick to do point_in_poly tests with a prepared geos geom. We still need a postgis-level point_in_poly test for non-cached geoms though.

comment:13 by strk, 12 years ago

too much noise in here! Nicklas: planning to do anything here for 2.0 or should I shift everything to 2.1 ?

comment:14 by nicklas, 12 years ago

Milestone: PostGIS 2.0.0PostGIS 2.1.0

This is connected to #852. This stopped up because I don't understand this "tolerance" implementation discussed in #852 and I don't want to put that in the point in polygon test used in distance before #852 is sorted out and I don't dare removing the tolerance part to clean it up that way. So, I shift it to 2.1 .If you find it irrelevant, just close it. Right now (last year) time is not enough, but I really hope to get back.

comment:15 by strk, 12 years ago

Alright, now #852 is closed and regress tested. I hope it'll make your life easier in moving things around.

comment:16 by robe, 11 years ago

Can I push this one (or close). This thread is too painfully long to read.

comment:17 by nicklas, 11 years ago

Resolution: wontfix
Status: newclosed

I agree. It was a little more complicated than I first thought. I close it and it we have some "cleaning up to do" it maybe should go there.

Note: See TracTickets for help on using tickets.