Skip to content

Commit

Permalink
Merge branch 'main' into feat/st-line-from-encoded-polyline
Browse files Browse the repository at this point in the history
  • Loading branch information
ybert authored Sep 17, 2024
2 parents 7146655 + cec9e0f commit 08c50f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- PostGIS ST_LineFromEncodedPolyline support
- PostGIS ST_LineLocatePoint support

## [1.6.1](https://github.com/clickbar/laravel-magellan/tree/1.6.1) - 2024-08-08

Expand Down
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 08c50f8

Please sign in to comment.