[postgis-users] Difference beetween ST_ClosestPoint and ST_Intersection

aperi2007 aperi2007 at gmail.com
Tue Jan 11 13:32:27 PST 2011


Hi,

thx for explanation.

Regards,

Andrea.


Il 11/01/2011 21:53, Nicklas Avén ha scritto:
> Hallo Andrea
>
> The two functions is very different but behave the same way in a few
> specific situations.
>
> St_Intersection I guess you know how works.
>
> ST_Closestpoint is actually a distance function. It is the forst point
> of ST_Shortestline. The pupose of those functions is to use on
> geometries not intersecting at all. Look at the illustrations in the
> documentation:
> http://www.postgis.org/documentation/manual-1.5/ST_ShortestLine.html
>
> ST_Shortestline gives you the line along which ST_Distance has found the
> min distance between two geometries. If you use the shortestline between
> a lake and a road it will give you the shortest possible line between
> the lake and the road.
>
> And as said, ST_Closestpoint is the first point in the shortest line,
> so:
> ST_Startpoint(ST_Shortestline(geometry, geometry)) =
> ST_Closestpoint(geometry, geometry)
>
>
>
> St_closestpoint is there because we expected it to be the most common
> usecase of ST_Shortestline to just find where on my geometry is the
> closest point to that geometry over there.
>
> That it gives you the same answer when using it with a point
> intersecting with a polygon is just a way to handle that situation. The
> alternative is to return null. SQL Server is comming up with a
> corresponding function to ST_Shortestline in their next release, but
> they call it ShortestLineTo. They have choosen to return null in case of
> intersection, while postgis returns a zero-length line with the same
> start and end in any of the intersecting points (if many)
>
> HTH
>
> Nicklas
>
>
> On Tue, 2011-01-11 at 21:19 +0100, aperi2007 wrote:
>> Il 11/01/2011 21:12, Paolo Cavallini ha scritto:
>>> Il giorno mar, 11/01/2011 alle 20.52 +0100, aperi2007 ha scritto:
>>>> Hi,
>>>>
>>>> I need to find the intersection point between two lines,
>>>> the first choice is ST_Intersection, but I notice even the
>>>> ST_ClosestPoint function.
>>>> \df+ st_intersection
>>>> in the case of two lines, the two results converge, but if you have two
>>>> polygons, you can see the difference.
>>>> All the best.
>> Hi Paolo,
>>
>> Of course this is a difference.
>> ST_Intersection is surely more flexible, usable with every kind of geometry.
>>
>> But my question is: "why ST_ClosestPoint exist ?"
>>
>> The only explain I can suppose is that for linear archives it give some
>> advantage (more speed ?)
>>
>> This is the question :)
>>
>> Andrea.
>>
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>




More information about the postgis-users mailing list