Skip to content

Commit

Permalink
Add support of ST_LineLocatePoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ybert committed Sep 16, 2024
1 parent 8421042 commit f4dc26a
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit f4dc26a

Please sign in to comment.