[postgis-users] [Question] Point returned in ST_LineLocatePoint and ST_ClosestPoint is not able to detect in ST_Contains

Paul Ramsey pramsey at cleverelephant.ca
Wed Sep 30 05:24:45 PDT 2015


Unfortunately, due to the vagaries of the IEEE double precision grid,
your constructed point probably does not like *exactly* on your line,
but ever-so-slightly off. Try testing instead for ST_DWithin(line,
point, 0.00001) or something and it should work better.

P

On Tue, Sep 29, 2015 at 9:59 PM, Dharshan Bharathur
<dharshan4help at gmail.com> wrote:
> Hi all, Need experts advice.
>
> This is the same question I have asked here.
>
> I am using postgis's ST_LineLocatePoint to find out the closest point on a
> LineString to the given Point, and using  ST_LineInterpolatePoint to extract
> a Point from the returned float number.(as referred here)
>
> This is my ST_LineLocatePoint Query
>
> SELECT ST_AsText(ST_LineInterpolatePoint(foo.the_line,
>          ST_LineLocatePoint(foo.the_line,ST_GeomFromText('POINT(12.962315
>          77.584841)')))) AS g FROM (SELECT
> ST_GeomFromText('LINESTRING(12.96145
>          77.58408,12.96219 77.58447,12.96302 77.58489,12.96316
> 77.58496,12.96348
>          77.58511)') AS the_line) AS foo;
>
>
> Output:
>
>                   g
> ------------------------------------------
>  POINT(12.9624389808159 77.5845959902924)
>
> Which exactly lies on the linestring I have passed. Demonstration is
> displayed here.
>
>
> query with St_Closest function also returns the same points.
>
> But when I check whether this point lies in the same linestring using
> ST_Contains it always return false, even though the point lies within.
>
> My ST_Contains Query:
>
> SELECT ST_Contains(ST_GeomFromText('LINESTRING(12.96145 77.58408,12.96219
> 77.58447,12.96302 77.58489, 12.96316 77.58496, 12.96348
> 77.58511)'),ST_GeomFromText('POINT(12.9624389808159 77.5845959902924)'));
>
> Output:
>
> st_contains
> -------------
> f
>
> I am not getting where I am doing wrong, why I am getting false. Can anyone
> help me in this.
>
>
> I am using Postgresql : 9.4, postgis : 2.1
>
>
>
>
> Thanks & Regards
> Dharshan
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users


More information about the postgis-users mailing list