[PostGIS] #5082: st_linelocatepoint returns value over 1
PostGIS
trac at osgeo.org
Wed Sep 3 14:06:36 PDT 2025
#5082: st_linelocatepoint returns value over 1
----------------------+--------------------------------
Reporter: andrest | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS PostgreSQL
Component: postgis | Version: 3.1.x
Resolution: | Keywords: st_linelocatepoint
----------------------+--------------------------------
Comment (by ostro):
I managed to reproduce this error. I use `postgis=3.4`.
=== Reproduction data
This is the SQL code, where the invalid value (`1.0000000000000002`) is
returned:
{{{#!sql
select ST_LineLocatePoint(
'LINESTRING (614506.766313283 390577.5124384557, 614494.089082674
390574.5586551775, 614494.8569439995 390562.1301508558, 614493.5246928157
390549.7664042029, 614486.5713433414 390544.32637928444, 614487.6296766759
390492.9548792321, 614487.6296766759 390492.9548792321)'::geometry,
'POINT (614487.6296766759 390492.9548792321)'::geometry
) > 1
}}}
Note that depending on your program, you may see just `1`. In that case,
cast `ST_LineLocatePoint` result to text, to see value with full
precision.
=== Possible solution
This seems to be a normal floating point error that happens in almost all
programming languages (using IEEE 754). Consider this rust code:
{{{#!text/html
fn main() {
let a: f64 = 100.0;
let b: f64 = 0.000_01 * 10_000_000.0;
let c: f64 = b / a;
println!("{:.20}", c);
}
}}}
If I decoded correctly, this is the
[https://gitea.osgeo.org/postgis/postgis/src/commit/799c1d873c39a3ae9c475c24e9dfeda6078aa956/postgis/geography_measurement.c#L1395
function code] that calls this
[https://gitea.osgeo.org/postgis/postgis/src/commit/799c1d873c39a3ae9c475c24e9dfeda6078aa956/liblwgeom/lwgeodetic_measures.c#L551
function library]. So maybe simple `if` will solve this problem?
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5082#comment:2>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list