Skip to content

nearestPointOnLine returns invalid segmentIndex when result is at the end of the last segment of the lineString #3016

@smallsaucepan

Description

@smallsaucepan

When calling nearestPointOnLine and the result is at the end of a segment, there is legacy behaviour that sets the segmentIndex to that of the next segment (end point of one segment being the same as the start point of the next). Unsure why this is the behaviour.

Unfortunately, if the original segment was the last in the lineString the segmentIndex is still incremented meaning it now refers to a non-existent segment.

After fixing #2946 with PR #2951, it became apparent in #3008 some users were using the overflowing segmentIndex as an indicator for whether the nearest point was found at the end of the line. Although undocumented, this caused backwards compatibility issues and will be reverted.

This issue aims to fix the problem properly as a breaking change aligned with a major release. Current plan is to:

  1. ensure segmentIndex always refers to a valid segment
  2. stop favouring the start point of the next segment instead (unless a valid reason becomes clear)

There have been requests to add additional meta data to the response properties to make up for the removal of the inferred "end of line" overflow. We're currently leaning away from that to avoid bloating the response. With the already returned lineStringIndex and segmentIndex it should be possible to test that condition in user code if required. Happy to hear examples though if there are other capabilities that would become impossible.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions