Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST_Distance doesn't return the minimum distance of two geometries. #12

Open
cuteDen-ECNU opened this issue Oct 30, 2023 · 2 comments
Open

Comments

@cuteDen-ECNU
Copy link
Owner

cuteDen-ECNU commented Oct 30, 2023

According to the crash libgeos/geos#977, the function related to the geometries with EMPTY seems not to be explored by the test suites.
Consider this statement:

geos/build/bin/geosop -a 'MULTIPOINT((-2 0), EMPTY)' -b ' GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,1 0))' distance

# Segmentation fault (core dumped)

According to the following definition, ST_Distance returns the minimum distance between two geometries :

returns the minimum 2D Cartesian (planar) distance between two geometries

But the result of ST_Distance(a2, a1) is 3, which is not the minimum distance.
Meanwhile, the result of ST_Distance(a2, a1) is not same as ST_Distance( a1, a2).
So I believe it is a functional issue that the current test suites haven't explored.

@muchang
Copy link
Collaborator

muchang commented Oct 31, 2023

Consider this statement:

SELECT ST_Distance(a2, a1), ST_Distance(a1, a2)
FROM ST_GeomFromText('MULTIPOINT((-2 0), EMPTY)') As a1
,ST_GeomFromText(' GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,1 0))') As a2;
--actual{3,2}
--expected{2,2}

According to the following definition, ST_Distance returns the minimum distance between two geometries :

returns the minimum 2D Cartesian (planar) distance between two geometries

Therefore, the result of ST_Distance(a2, a1) should be the same as ST_Distance(a1, a2) which is 2.
However, ST_Distance(a2, a1) returns 3, which seems to be a bug.

If we replace the EMPTY from the MULTIPOINT with a concrete point, such as (5, 0), ST_Distance(a2, a1) behaviors correctly.
Thus, this bug might be related to the EMPTY point.

@cuteDen-ECNU cuteDen-ECNU added sytax trans Add point to the boundary of geometry Generator bug-confirm libgeos labels Nov 1, 2023
@cuteDen-ECNU
Copy link
Owner Author

cuteDen-ECNU commented Nov 1, 2023

bugtracker link: libgeos/geos#979
fix link: 13c25a8
reproduce: a7a12f5

@cuteDen-ECNU cuteDen-ECNU added crash and removed sytax trans Add point to the boundary of geometry labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants