Opened 3 weeks ago

Last modified 7 days ago

#5816 new defect

Add ST_3DRemoveRepeatedPoints

Reported by: nbvfgh Owned by: pramsey
Priority: high Milestone: PostGIS 3.6.0
Component: postgis Version: 3.5.x
Keywords: Cc:

Description

I used a function called ST_RemoveRepeatedPoint, which takes two parameters, a geometry and a floating-point tolerance. When I tried to use this function to delete two points that are equal on x and y but not equal on the z-axis, a possible logical error occurred:

ST_RemoveRepeatedPoint(geometry geom, float8 tolerance): Returns a version of the given geometry with duplicate consecutive points removed. The function processes only (Multi)LineStrings, (Multi)Polygons and MultiPoints but it can be called with any kind of geometry.If the tolerance parameter is provided, vertices within the tolerance distance of one another are considered to be duplicates.

Query statement:

SELECT ST_AsText(ST_RemoveRepeatedPoints('MULTIPOINT(10 10 10, 10 10 13)', 2)); 

-- expected:{MULTIPOINT Z ((10 10 10), (10 10 13))};
-- actual:  {MULTIPOINT Z ((10 10 13))};

It is obvious that the difference between the two points in MULTIPOINT (10 10 10, 10 10 13) on the z-axis is 3(bigger than the tolerance), and the point(10, 10, 10) has still been deleted, which seems to be a bug.

And the query statement:

SELECT ST_AsText(ST_RemoveRepeatedPoints('MULTIPOINT(10 10 10, 13 10 10)', 2));

-- expected:{MULTIPOINT Z ((10 10 10), (13 10 10))};
-- actual:  {MULTIPOINT Z ((10 10 10), (13 10 10))};

When these two points only differ on the x-axis and are 3(bigger than the tolerance),no point was deleted, this is the correct result.

In the [official documentation](https://postgis.net/docs/manual-3.5/ST_RemoveRepeatedPoints.html), ST_RemoveRepeatedPoints is stated as a function that supports 3D, but it seems to be invalid for tolerance on the z-axis.

geos version is GEOS="3.13.0-CAPI-1.19.0"

Change History (7)

comment:1 by mdavis, 3 weeks ago

"Supports 3D" has a somewhat broad meaning. In this case it means that Z values are preserved. However, the function uses a 2D distance metric to determine points to remove. This should be made clear in the documentation.

A mode that uses a 3D distance metric seems like a nice addition. It could be invoked via a flag to this function, or perhaps via a new function ST_RemoveRepeatedPointsZ?

comment:2 by nbvfgh, 2 weeks ago

Last edited 2 weeks ago by nbvfgh (previous) (diff)

in reply to:  1 comment:3 by nbvfgh, 2 weeks ago

The use of 3D distance measurement mode is a great idea, and I suggest supporting it with new functions, just like other functions that handle 2D and 3D under the same semantics.

Meanwhile, I suggest checking if there are any other spatial functions that have similar issues.

Could this be a logical error caused by unclear documentation for users?

Replying to mdavis:

"Supports 3D" has a somewhat broad meaning. In this case it means that Z values are preserved. However, the function uses a 2D distance metric to determine points to remove. This should be made clear in the documentation.

A mode that uses a 3D distance metric seems like a nice addition. It could be invoked via a flag to this function, or perhaps via a new function ST_RemoveRepeatedPointsZ?

comment:4 by pramsey, 2 weeks ago

This is definitely not a bug, it's desired behaviour. As mdavis notes, having a second ST_3DRemoteRepeatedPoints() that used the Z in the calculation would match our pattern of "which functions ignore Z and which take it into account".

in reply to:  4 comment:5 by nbvfgh, 2 weeks ago

Thank you for your prompt response. Replying to pramsey:

This is definitely not a bug, it's desired behaviour. As mdavis notes, having a second ST_3DRemoteRepeatedPoints() that used the Z in the calculation would match our pattern of "which functions ignore Z and which take it into account".

comment:6 by mdavis, 7 days ago

The doc has been updated to clarify 2D only: https://postgis.net/docs/manual-dev/ST_RemoveRepeatedPoints.html

comment:7 by robe, 7 days ago

Milestone: PostGIS 3.5.1PostGIS 3.6.0
Summary: Failed Z-axis tolerance in ST_RemoveRepeatedPointsAdd ST_3DRemoveRepeatedPoints

I've changed this to a feature request.

@mdavis, want to backport your doco change to 3.5 unless you have already.

Note: See TracTickets for help on using tickets.