<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE-AT" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">I have a simple LINE-Geometry and a POINT, that I want to query, if it intersects the line.<o:p></o:p></p>
<p class="MsoNormal">The result ist, that ST_Intersects gives „FALSE“, and ST_Distance gives „0“. So, this is contradictory. An analysis with JTS shows, that there is a distance of
<span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#242729;background:white">
6.611191059663252E-13.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#242729;background:white">Should ST_Distance not also return this result?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#242729;background:white"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#242729;background:white">Here are the SQL-Statements:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#242729;background:white"><o:p> </o:p></span></p>
<p class="MsoNormal">WITH point1 as<o:p></o:p></p>
<p class="MsoNormal">(Select ST_GeomFromWKB('\x0101000020167A0000B0A13497E151E5C0E386CC0EACF50D41', 31254) as geom),<o:p></o:p></p>
<p class="MsoNormal">line1 as<o:p></o:p></p>
<p class="MsoNormal">(select ST_GeomFromWKB('\x0102000020167A000002000000000000003952E5C00000005012F60D4100000000AF51E5C0000000E070F50D41', 31254) as geom)<o:p></o:p></p>
<p class="MsoNormal">select ST_Intersects(line1.geom, point1.geom), ST_Distance(line1.geom, point1.geom),<o:p></o:p></p>
<p class="MsoNormal">ST_AsText(ST_Intersection(line1.geom, point1.geom)),<o:p></o:p></p>
<p class="MsoNormal">ST_AsText(ST_ShortestLine(line1.geom, point1.geom))<o:p></o:p></p>
<p class="MsoNormal">from<o:p></o:p></p>
<p class="MsoNormal">line1, point1;<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Even when I try to Snap the point to the line-geometry, it does not work:<o:p></o:p></p>
<p class="MsoNormal">WITH point1 as<o:p></o:p></p>
<p class="MsoNormal">(Select ST_GeomFromWKB('\x0101000020167A0000B0A13497E151E5C0E386CC0EACF50D41', 31254) as geom),<o:p></o:p></p>
<p class="MsoNormal">line1 as<o:p></o:p></p>
<p class="MsoNormal">(select ST_GeomFromWKB('\x0102000020167A000002000000000000003952E5C00000005012F60D4100000000AF51E5C0000000E070F50D41', 31254) as geom)<o:p></o:p></p>
<p class="MsoNormal">select ST_Intersects(line1.geom, ST_ClosestPoint(line1.geom, point1.geom)), ST_Distance(line1.geom, ST_ClosestPoint(line1.geom, point1.geom)),<o:p></o:p></p>
<p class="MsoNormal">ST_AsText(ST_Intersection(line1.geom, ST_ClosestPoint(line1.geom, point1.geom))),<o:p></o:p></p>
<p class="MsoNormal">ST_AsText(ST_ShortestLine(line1.geom, ST_ClosestPoint(line1.geom, point1.geom)))<o:p></o:p></p>
<p class="MsoNormal">from<o:p></o:p></p>
<p class="MsoNormal">line1, point1;<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I know about  the limitations of floating-point-operations (see discussion here:
<a href="https://stackoverflow.com/questions/60298412/wrong-result-using-st-intersection-with-postgis/">
https://stackoverflow.com/questions/60298412/wrong-result-using-st-intersection-with-postgis/</a>), but ST_Distance should give a result different than 0, right?<o:p></o:p></p>
<p class="MsoNormal">Is this a bug in the ST_Distance-function (and probalby in the ST_ClosestPoint-function)?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">I tested this with postgres 9.6.15 and postgis 2.4<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;background:white;vertical-align:baseline;font-variant-ligatures: normal;font-variant-caps: normal;font-variant-numeric: inherit;font-variant-east-asian: inherit;font-stretch: inherit;line-height:inherit;box-sizing: inherit;orphans: 2;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">and also with<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;background:white;vertical-align:baseline;font-variant-ligatures: normal;font-variant-caps: normal;font-variant-numeric: inherit;font-variant-east-asian: inherit;font-stretch: inherit;line-height:inherit;box-sizing: inherit;orphans: 2;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">postgres 12.1 and postgis 3.0, same results.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal">Didi<o:p></o:p></p>
</div>
</body>
</html>