Opened 13 years ago

Closed 13 years ago

#791 closed enhancement (fixed)

Topology: function GetEdgeByPoint($1,$2,$3)

Reported by: aperi2007 Owned by: strk
Priority: medium Milestone: PostGIS 2.0.0
Component: topology Version: master
Keywords: history Cc:

Description

I have created a simple function to retrieve the IDEDGE give the Point.

GetEdgeByPoint(topology, geometry::point, tolerance) return integer

tolerance = 0 mean use the Intersection otherwise ST_DWithin().

It return the integer ID if there is an edge on the Point, but if the Point is even a Node it raise an exception.

If there isn't any edge in the Point, GetEdgeByPoint return 0.

If near the point there are two or more edges it throw an exception.

The patch with the code is attach to this ticket.

Attachments (5)

patch.zip (1.0 KB ) - added by aperi2007 13 years ago.
patch for add GetEdgeByPoint
GetEdgeByPoint.xml (2.1 KB ) - added by aperi2007 13 years ago.
GetEdgeByPoint documentation
GetEdgeByPoint.sql (1.4 KB ) - added by aperi2007 13 years ago.
Test regress
GetEdgeByPoint_expected (119 bytes ) - added by aperi2007 13 years ago.
Expected test regress
getedgebypoint.zip (3.2 KB ) - added by aperi2007 13 years ago.
getedgebypoint pack

Download all attachments as: .zip

Change History (20)

by aperi2007, 13 years ago

Attachment: patch.zip added

patch for add GetEdgeByPoint

comment:1 by strk, 13 years ago

Nice to see this coming up. Just a note: ST_Intersects already performs && check, so don't need to do that explicitly.

Do you feel like providing regression test too ? It'd go under topology/test/regress/getEdgeByPoint.sql See wiki for informations about how to do that: http://trac.osgeo.org/postgis/wiki/DevWikiPGRegress

comment:2 by robe, 13 years ago

Oh and while we are asking for things. A doc patch would be nice too :)

http://trac.osgeo.org/postgis/wiki/DevWikiDocNewFeature

comment:3 by aperi2007, 13 years ago

added documentation. I hope is ok. Xml is unknown for me.

by aperi2007, 13 years ago

Attachment: GetEdgeByPoint.xml added

GetEdgeByPoint documentation

by aperi2007, 13 years ago

Attachment: GetEdgeByPoint.sql added

Test regress

by aperi2007, 13 years ago

Attachment: GetEdgeByPoint_expected added

Expected test regress

comment:4 by aperi2007, 13 years ago

Add the test regress and expected results. The package is complete.

comment:5 by robe, 13 years ago

Andrea,

This looks good except that you made the mistake of picking up our bad habits and are using antiquated aliasing syntax.

Can you revise:

So instead of:

topology.GetEdgeByPoint(varchar, geometry, float8)

Do topology.GetEdgeByPoint(atopology varchar, apoint geometry, tol1 float8)

and get rid of your alias stuff.

I think Strk started changing some functions, but can't recall which ones now.

Also can you change your "point" in the documentation to "apoint". Ideally the doc arg names should match the functions arg names (just in case people start doing that named parameter calling stuff). Since I've been guilty of breaking this rule, just because i don't like the names of some of the function arguments it feels cruel of me to force it on you.

Strk you have any comments or issues with accepting his patches? — I haven't inspected the function that closely.

comment:6 by strk, 13 years ago

One issue is I'd always use DWithin rather than switching to use ST_Intersects when tolerance is zero. Is there any reason for the ST_Intersects ?

Other minor issues:

  • this should probably not be in a file called 'populate.sql' as it's a query-only function.
  • exception messages should all start with Uppercase ("two or more edges found" doesn't).
  • "Tollerance" → "Tolerance" (and simpler: "Tolerance must be ≥ 0")

comment:7 by robe, 13 years ago

I think for the reason that Nicklas had stated that ST_Intersects in theory should be faster, but I haven't done any official tests myself to be sure. We tend to use ST_DWithin for most everything just because for most cases we need a little bit of tolerance (or are working with less than perfect geometries) which we don't get with ST_Intersects.

I would have said before 1.5 that ST_Intersects was most definitely faster, but now that ST_DWithin speed has improved for larger geometries, I'm not so sure.

comment:8 by strk, 13 years ago

Maybe for long edges it might be faster, but you have to take into account the conversion to geos too (in the ST_Intersects case) and the ST_Intersects computes full intersection matrix too, which means no early exit ever happens.

Would be interesting to hear Nicklas opinion (but even better: profile data) on the matter

comment:9 by nicklas, 13 years ago

Hallo

I don't know the ST_Intersects algorithm but the problem for ST_Dwithin is that the faster way of doing it in 1.5 will not be used in the cases where the bounding-boxes intersect. In the case of using ST_DWithin as a intersection test the faster algorithm will never get used because the cases with no intersecting bounding boxes will be sorted away already by the index.

So, until Paul implements his indexing of vertexes in distance/intersection presented

here http://postgis.refractions.net/pipermail/postgis-devel/2009-December/007710.html

and here http://blog.cleverelephant.ca/2009/11/is-good-enough-good-enough.html

until then, I am afraid we will have to live with the brute force way of doing the calculation for ST_DWithin(geoemtry, 0)

But what I enhanced in 1.5 was also that I put in a lot of more "Is the answer already given" tests, which might give quite a lot better performance in those cases. Before 1.5 this was only tested once per interior ring.

strk, do you have insight in ST_Intersects algorithm?

Regards Nicklas

comment:10 by aperi2007, 13 years ago

hi Robe, if is ok. I will use a new file named <function>_code.sql for declaring each of these two functions instead of apply directly into the populate.sql file ?

for example: GetEdgeByPoint will have these 4 files

GetEdgeByPoint_code.sql (the function definition) GetEdgeByPoint.xml (the doc) GetEdgeByPoint.sql (the regress test) GetEdgeByPoint_expected (the results expected)

comment:11 by robe, 13 years ago

Yah that would be fine with me.

by aperi2007, 13 years ago

Attachment: getedgebypoint.zip added

getedgebypoint pack

comment:13 by strk, 13 years ago

Keywords: history added

Code and regress test in r6865 @robe would you take care of the documentation, which comes in a nice external .xml ?

comment:14 by robe, 13 years ago

sure

comment:15 by robe, 13 years ago

Resolution: fixed
Status: newclosed

documentation completed at r6869.

The errors are very cute but grammatically incorrect I think.

ERROR: Two or more edges founded

I guess we should fix them. Same issue with the GetNodeByPoint. I'll put that in as a separate ticket.

Also I redid the examples with the sample data I had. Andrea, in future for the examples, please also include the output of the query.

Note: See TracTickets for help on using tickets.