From f4dc26a312f87995c8f147fef77ba98f5a913d2f Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 16 Sep 2024 16:32:00 +0200 Subject: [PATCH 1/3] Add support of ST_LineLocatePoint --- .../MagellanGeometryProcessingFunctions.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php b/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php index 1ae61c1..c319baf 100644 --- a/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php +++ b/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php @@ -5,6 +5,7 @@ use Clickbar\Magellan\Database\MagellanExpressions\GeoParam; use Clickbar\Magellan\Database\MagellanExpressions\MagellanBaseExpression; use Clickbar\Magellan\Database\MagellanExpressions\MagellanGeometryExpression; +use Clickbar\Magellan\Database\MagellanExpressions\MagellanNumericExpression; use Clickbar\Magellan\Enums\DelaunayTrianglesOutput; use Clickbar\Magellan\Enums\EndCap; use Clickbar\Magellan\Enums\GeometryType; @@ -168,6 +169,24 @@ public static function geometricMedian($geometry, float|Expression|\Closure|null return MagellanBaseExpression::geometry('ST_GeometricMedian', [GeoParam::wrap($geometry), $tolerance, $maxIterations, $failIfNotConverged]); } + /** + * Returns a float between 0 and 1 representing the location of the closest point on a LineString to the given Point, as a fraction of 2d line length. + * + * + * @see https://postgis.net/docs/ST_LineLocatePoint.html + */ + public static function lineLocatePoint($geometryA, $geometryB, bool|Expression| Closure|null $useSpheroid = null, ?GeometryType $geometryType = null): MagellanNumericExpression + { + if ($geometryType === null && $useSpheroid !== null) { + $geometryType = GeometryType::Geography; + } + + $useSpheroid = $useSpheroid ?? true; + $optionalParamters = $geometryType === GeometryType::Geography ? [$useSpheroid] : []; + + return MagellanBaseExpression::numeric('ST_LineLocatePoint', [GeoParam::wrap($geometryA), GeoParam::wrap($geometryB), ...$optionalParamters], $geometryType); + } + /** * Returns a LineString or MultiLineString formed by joining together the line elements of a MultiLineString. Lines are joined at their endpoints at 2-way intersections. Lines are not joined across intersections of 3-way or greater degree. * From 996c5d25ee77693c043f2a5eedc093efe02c6b34 Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Mon, 16 Sep 2024 18:09:40 +0200 Subject: [PATCH 2/3] Fix Closure declaration --- .../PostgisFunctions/MagellanGeometryProcessingFunctions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php b/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php index c319baf..96e89e6 100644 --- a/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php +++ b/src/Database/PostgisFunctions/MagellanGeometryProcessingFunctions.php @@ -175,7 +175,7 @@ public static function geometricMedian($geometry, float|Expression|\Closure|null * * @see https://postgis.net/docs/ST_LineLocatePoint.html */ - public static function lineLocatePoint($geometryA, $geometryB, bool|Expression| Closure|null $useSpheroid = null, ?GeometryType $geometryType = null): MagellanNumericExpression + public static function lineLocatePoint($geometryA, $geometryB, bool|Expression|\Closure|null $useSpheroid = null, ?GeometryType $geometryType = null): MagellanNumericExpression { if ($geometryType === null && $useSpheroid !== null) { $geometryType = GeometryType::Geography; From 2df1174ca4651d7db81f834ed732090cff92b9d3 Mon Sep 17 00:00:00 2001 From: Yohann Berthon Date: Tue, 17 Sep 2024 09:46:00 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1cdd92..9848592 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added +- PostGIS ST_LineLocatePoint support + ## [1.6.1](https://github.com/clickbar/laravel-magellan/tree/1.6.1) - 2024-08-08 ### Improved