Skip to content

Commit

Permalink
Merge pull request #62575 from andyyang890/backport21.1-62511
Browse files Browse the repository at this point in the history
release-21.1: geo/geomfn: fix st_linelocatepoint to work with ZM coords
  • Loading branch information
andyyang890 authored Mar 25, 2021
2 parents e118318 + c5b6677 commit 2b37aea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/geo/geomfn/linestring.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ func LineLocatePoint(line geo.Geometry, point geo.Geometry) (float64, error) {
return 0, err
}

lineStart := geom.Coord{lineString.Coord(0).X(), lineString.Coord(0).Y()}
// build new line segment to the closest point we found
lineSegment := geom.NewLineString(geom.XY).MustSetCoords([]geom.Coord{lineString.Coord(0), p.Coords()})
lineSegment := geom.NewLineString(geom.XY).MustSetCoords([]geom.Coord{lineStart, p.Coords()})

// compute fraction of new line segment compared to total line length
return lineSegment.Length() / lineString.Length(), nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/geo/geomfn/linestring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func TestLineLocatePoint(t *testing.T) {
point: geom.NewPointFlat(geom.XY, []float64{3, 1}),
expected: 0.87,
},
{
lineString: geom.NewLineStringFlat(geom.XYZ, []float64{0, 0, 5, 1, 1, 26}),
point: geom.NewPointFlat(geom.XYZ, []float64{0, 1, -1}),
expected: 0.5,
},
}

for index, tc := range testCases {
Expand Down

0 comments on commit 2b37aea

Please sign in to comment.