[PostGIS] #5589: ST_3DDistance seems not to work for LINESTRINGs in specified situation.

PostGIS trac at osgeo.org
Thu Nov 2 22:54:57 PDT 2023


#5589: ST_3DDistance seems not to work for LINESTRINGs in specified situation.
-----------------------+---------------------------
  Reporter:  Wenjing   |      Owner:  pramsey
      Type:  defect    |     Status:  new
  Priority:  critical  |  Milestone:  PostGIS 3.5.0
 Component:  postgis   |    Version:  3.4.x
Resolution:            |   Keywords:
-----------------------+---------------------------
Changes (by Wenjing):

 * cc: Wenjing (added)


Old description:

> For the following query involving ST_3DDistance:
>
> {{{
> SELECT ST_3DDistance(b1, b2)
> FROM ST_GeomFromText('LINESTRING Z (0 0 0, 1 0 0)') As b1,
> ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 1)') As b2;
> --  st_3ddistance
> ---------------
> --
> -- (1 row)
> }}}
>
> PostGIS returns a null result which is unexpected.
>
> PostGIS seems not to work for LINESTRINGs (i.e., returning an unexpected
> null result) when
> (1) both LINESTRINGs start from 0,0,0 and
> (2) both LINESTRINGs only involve two points.
>
> (1) For example, when a LINESTRING does not start from 0,0,0
>
> {{{
> SELECT ST_3DDistance(b1, b2)
> FROM ST_GeomFromText('LINESTRING Z (0 0 1, 0 0 0)') As b1,
> ST_GeomFromText('LINESTRING Z (0 0 0, 0 0 1)') As b2;
> --  st_3ddistance
> ---------------
> --              0
> -- (1 row)
> }}}
>
> PostGIS can give the expected result.
>
> (2) or when a LINESTRING involves more than two points
>

> {{{
> SELECT ST_3DDistance(b1, b2)
> FROM ST_GeomFromText('LINESTRING Z (0 0 0, 0 1 0, 0 2 0)') As b1,
> ST_GeomFromText('LINESTRING Z (0 0 0, 1 0 0)') As b2;
> --  st_3ddistance
> ---------------
> --              1
> -- (1 row)
> }}}
>
> PostGIS also works for the case.
>
> The unexpected behavior for ST_3DDistance also propagates to
> ST_3DDWithin.
>
> For example, the following query is expected to have true while PostGIS
> gives false
>

> {{{
> SELECT ST_3DDWithin(b1, b2, 10000)
> FROM ST_GeomFromText('LINESTRING Z (0 0 0, 1 0 0)') As b1,
> ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 1)') As b2;
> --expected{t},actual{f}
> }}}
> The ST_3DDWithin works correctly if we change the start point or add one
> more point as above.
>
> {{{
> SELECT ST_3DDWithin(b1, b2, 10000)
> FROM ST_GeomFromText('LINESTRING Z (0 0 1, 1 0 0)') As b1,
> ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 1)') As b2;
> --result{t}
> }}}
>
> {{{
> SELECT ST_3DDWithin(b1, b2, 10000)
> FROM ST_GeomFromText('LINESTRING Z (0 0 0, 1 0 0, 1 2 1)') As b1,
> ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 1)') As b2;
> --result{t}
> }}}
>
> version:
> POSTGIS="3.5.0dev 3.4.0rc1-705-g5c3ec8392"
> [EXTENSION]
> PGSQL="170"
> GEOS="3.13.0dev-CAPI-1.18.0"
> PROJ="8.2.1 NETWORK_ENABLED=OFF
> URL_ENDPOINT=https://cdn.proj.org
> USER_WRITABLE_DIRECTORY=/tmp/proj
> DATABASE_PATH=/usr/share/proj/proj.db"
> LIBXML="2.9.13" PostgreSQL 17devel on x86_64-pc-linux-gnu, compiled by
> gcc (Ubuntu 11.4.0-
> 1ubuntu1~22.04) 11.4.0, 64-bit

New description:

 Consider the following statement
 {{{
 SELECT ST_3DDistance(b1, b2)
 FROM ST_GeomFromText('LINESTRING Z (0 0 0, 1 0 0)') As b1,
 ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 1)') As b2;
 --  st_3ddistance
 ---------------
 --
 -- (1 row)
 }}}
 The ST_3DDistance function is expected to give the result but it doesn't.

 The version:

 {{{
  POSTGIS="3.5.0dev 3.4.0rc1-705-g5c3ec8392" [EXTENSION] PGSQL="170"
 GEOS="3.13.0dev-CAPI-1.18.0" PROJ="8.2.1 NETWORK_ENABLED=OFF
 URL_ENDPOINT=https://c
 dn.proj.org USER_WRITABLE_DIRECTORY=/tmp/proj
 DATABASE_PATH=/usr/share/proj/proj.db" LIBXML="2.9.13"
 (1 row)
 }}}

--
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5589#comment:3>
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