diff --git a/API.md b/API.md
index c256179..850ef57 100644
--- a/API.md
+++ b/API.md
@@ -33,20 +33,20 @@ In addition, `GeometryCollection` also has these functions:
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]),
]);
-echo $geometryCollection->getGeometries()[1]->latitude; // 180
+echo $geometryCollection->getGeometries()[1]->latitude; // 0
// or access as an array:
-echo $geometryCollection[1]->latitude; // 180
+echo $geometryCollection[1]->latitude; // 0
```
## Available spatial scopes
@@ -79,20 +79,20 @@ Retrieves the distance between 2 geometry objects. Uses [ST_Distance](https://de
Example
```php
-Place::create(['location' => new Point(0, 0)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
$placeWithDistance = Place::query()
- ->withDistance('location', new Point(1, 1))
+ ->withDistance('location', new Point(1, 1, 4326))
->first();
-echo $placeWithDistance->distance; // 1.4142135623731
+echo $placeWithDistance->distance; // 156897.79947260793
// when using alias:
$placeWithDistance = Place::query()
- ->withDistance('location', new Point(1, 1), 'distance_in_meters')
+ ->withDistance('location', new Point(1, 1, 4326), 'distance_in_meters')
->first();
-echo $placeWithDistance->distance_in_meters; // 1.4142135623731
+echo $placeWithDistance->distance_in_meters; // 156897.79947260793
```
@@ -110,11 +110,11 @@ Filters records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman
Example
```php
-Place::create(['location' => new Point(0, 0)]);
-Place::create(['location' => new Point(100, 100)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
+Place::create(['location' => new Point(50, 50, 4326)]);
$placesCountWithinDistance = Place::query()
- ->whereDistance('location', new Point(1, 1), '<', 1.5)
+ ->whereDistance('location', new Point(1, 1, 4326), '<', 160000)
->count();
echo $placesCountWithinDistance; // 1
@@ -136,15 +136,15 @@ Orders records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman/
```php
Place::create([
'name' => 'first',
- 'location' => new Point(0, 0),
+ 'location' => new Point(0, 0, 4326),
]);
Place::create([
'name' => 'second',
- 'location' => new Point(100, 100),
+ 'location' => new Point(50, 50, 4326),
]);
$places = Place::query()
- ->orderByDistance('location', new Point(1, 1), 'desc')
+ ->orderByDistance('location', new Point(1, 1, 4326), 'desc')
->get();
echo $places[0]->name; // second
@@ -165,20 +165,20 @@ Retrieves the spherical distance between 2 geometry objects. Uses [ST_Distance_S
Example
```php
-Place::create(['location' => new Point(0, 0)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
$placeWithDistance = Place::query()
- ->withDistanceSphere('location', new Point(1, 1))
+ ->withDistanceSphere('location', new Point(1, 1, 4326))
->first();
-echo $placeWithDistance->distance; // 157249.0357231545
+echo $placeWithDistance->distance; // 157249.59776850493
// when using alias:
$placeWithDistance = Place::query()
- ->withDistanceSphere('location', new Point(1, 1), 'distance_in_meters')
+ ->withDistanceSphere('location', new Point(1, 1, 4326), 'distance_in_meters')
->first();
-echo $placeWithDistance->distance_in_meters; // 157249.0357231545
+echo $placeWithDistance->distance_in_meters; // 157249.59776850493
```
@@ -196,11 +196,11 @@ Filters records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mys
Example
```php
-Place::create(['location' => new Point(0, 0)]);
-Place::create(['location' => new Point(100, 100)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
+Place::create(['location' => new Point(50, 50, 4326)]);
$placesCountWithinDistance = Place::query()
- ->whereDistanceSphere('location', new Point(1, 1), '<', 160000)
+ ->whereDistanceSphere('location', new Point(1, 1, 4326), '<', 160000)
->count();
echo $placesCountWithinDistance; // 1
@@ -222,15 +222,15 @@ Orders records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mysq
```php
Place::create([
'name' => 'first',
- 'location' => new Point(0, 0),
+ 'location' => new Point(0, 0, 4326),
]);
Place::create([
'name' => 'second',
- 'location' => new Point(100, 100),
+ 'location' => new Point(100, 100, 4326),
]);
$places = Place::query()
- ->orderByDistanceSphere('location', new Point(1, 1), 'desc')
+ ->orderByDistanceSphere('location', new Point(1, 1, 4326), 'desc')
->get();
echo $places[0]->name; // second
@@ -250,7 +250,7 @@ Filters records by the [ST_Within](https://dev.mysql.com/doc/refman/8.0/en/spati
Example
```php
-Place::create(['location' => new Point(0, 0)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
Place::query()
->whereWithin('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'))
@@ -273,7 +273,7 @@ Filters records by the [ST_Contains](https://dev.mysql.com/doc/refman/8.0/en/spa
Place::create(['area' => Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'),]);
Place::query()
- ->whereContains('area', new Point(0, 0))
+ ->whereContains('area', new Point(0, 0, 4326))
->exists(); // true
```
@@ -290,7 +290,7 @@ Filters records by the [ST_Touches](https://dev.mysql.com/doc/refman/8.0/en/spat
Example
```php
-Place::create(['location' => new Point(0, 0)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
Place::query()
->whereTouches('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[0,-1],[0,0],[-1,0],[-1,-1]]]}'))
@@ -310,7 +310,7 @@ Filters records by the [ST_Intersects](https://dev.mysql.com/doc/refman/8.0/en/s
Example
```php
-Place::create(['location' => new Point(0, 0)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
Place::query()
->whereIntersects('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'))
@@ -350,7 +350,7 @@ Filters records by the [ST_Disjoint](https://dev.mysql.com/doc/refman/8.0/en/spa
Example
```php
-Place::create(['location' => new Point(0, 0)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
Place::query()
->whereDisjoint('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[-0.5,-1],[-0.5,-0.5],[-1,-0.5],[-1,-1]]]}'))
@@ -370,10 +370,10 @@ Filters records by the [ST_Equal](https://dev.mysql.com/doc/refman/8.0/en/spatia
Example
```php
-Place::create(['location' => new Point(0, 0)]);
+Place::create(['location' => new Point(0, 0, 4326)]);
Place::query()
- ->whereEquals('location', new Point(0, 0))
+ ->whereEquals('location', new Point(0, 0, 4326))
->exists(); // true
```
diff --git a/src/GeometryCast.php b/src/GeometryCast.php
index 9f665cf..475874b 100644
--- a/src/GeometryCast.php
+++ b/src/GeometryCast.php
@@ -71,19 +71,19 @@ public function set($model, string $key, $value, array $attributes): Expression|
$wkt = $value->toWkt();
- return DB::raw("ST_GeomFromText('{$wkt}', {$value->srid})");
+ return DB::raw("ST_GeomFromText('{$wkt}', {$value->srid}, 'axis-order=long-lat')");
}
private function extractWktFromExpression(Expression $expression): string
{
- preg_match('/ST_GeomFromText\(\'(.+)\', .+\)/', (string) $expression, $match);
+ preg_match('/ST_GeomFromText\(\'(.+)\', .+, .+\)/', (string) $expression, $match);
return $match[1];
}
private function extractSridFromExpression(Expression $expression): int
{
- preg_match('/ST_GeomFromText\(\'.+\', (.+)\)/', (string) $expression, $match);
+ preg_match('/ST_GeomFromText\(\'.+\', (.+), .+\)/', (string) $expression, $match);
return (int) $match[1];
}
diff --git a/src/SpatialBuilder.php b/src/SpatialBuilder.php
index 181b2eb..af4a618 100644
--- a/src/SpatialBuilder.php
+++ b/src/SpatialBuilder.php
@@ -265,7 +265,7 @@ protected function toExpression(Geometry|string $geometryOrColumn): Expression
if ($geometryOrColumn instanceof Geometry) {
$wkt = $geometryOrColumn->toWkt();
- return DB::raw("ST_GeomFromText('{$wkt}')");
+ return DB::raw("ST_GeomFromText('{$wkt}', {$geometryOrColumn->srid}, 'axis-order=long-lat')");
}
return DB::raw("`{$geometryOrColumn}`");
diff --git a/tests/GeometryCastTest.php b/tests/GeometryCastTest.php
index b1ebcf4..0d965d3 100644
--- a/tests/GeometryCastTest.php
+++ b/tests/GeometryCastTest.php
@@ -16,7 +16,7 @@
});
it('updates a model record', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
$point2 = new Point(0, 0);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
@@ -28,7 +28,7 @@
});
it('updates a model record with null geometry', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
@@ -38,7 +38,7 @@
});
it('gets original geometry field', function (): void {
- $point = new Point(180, 0, 4326);
+ $point = new Point(0, 180, 4326);
$point2 = new Point(0, 0, 4326);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
@@ -51,7 +51,7 @@
});
it('serializes a model record to array with geometry', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
@@ -62,7 +62,7 @@
});
it('serializes a model record to json with geometry', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
@@ -78,8 +78,8 @@
expect(function (): void {
TestPlace::factory()->make([
'point' => new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
})->toThrow(InvalidArgumentException::class);
diff --git a/tests/Objects/GeometryCollectionTest.php b/tests/Objects/GeometryCollectionTest.php
index 08c432a..65a9f7a 100644
--- a/tests/Objects/GeometryCollectionTest.php
+++ b/tests/Objects/GeometryCollectionTest.php
@@ -13,14 +13,14 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
/** @var TestPlace $testPlace */
@@ -34,14 +34,14 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
/** @var TestPlace $testPlace */
@@ -54,17 +54,17 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
- $geometryCollectionFromJson = GeometryCollection::fromJson('{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]},{"type":"Point","coordinates":[0,180]}]}');
+ $geometryCollectionFromJson = GeometryCollection::fromJson('{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]},{"type":"Point","coordinates":[180,0]}]}');
expect($geometryCollectionFromJson)->toEqual($geometryCollection);
});
@@ -73,17 +73,17 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
- $geometryCollectionFromJson = GeometryCollection::fromJson('{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]},{"type":"Point","coordinates":[0,180]}]}', 4326);
+ $geometryCollectionFromJson = GeometryCollection::fromJson('{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]},{"type":"Point","coordinates":[180,0]}]}', 4326);
expect($geometryCollectionFromJson)->toEqual($geometryCollection);
});
@@ -92,17 +92,17 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
- $geometryCollectionFromFeatureCollectionJson = GeometryCollection::fromJson('{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}},{"type":"Feature","properties":[],"geometry":{"type":"Point","coordinates":[0,180]}}]}');
+ $geometryCollectionFromFeatureCollectionJson = GeometryCollection::fromJson('{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}},{"type":"Feature","properties":[],"geometry":{"type":"Point","coordinates":[180,0]}}]}');
expect($geometryCollectionFromFeatureCollectionJson)->toEqual($geometryCollection);
});
@@ -111,19 +111,19 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
$json = $geometryCollection->toJson();
- $expectedJson = '{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]},{"type":"Point","coordinates":[0,180]}]}';
+ $expectedJson = '{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]},{"type":"Point","coordinates":[180,0]}]}';
expect($json)->toBe($expectedJson);
});
@@ -131,19 +131,19 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
$featureCollectionJson = $geometryCollection->toFeatureCollectionJson();
- $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}},{"type":"Feature","properties":[],"geometry":{"type":"Point","coordinates":[0,180]}}]}';
+ $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}},{"type":"Feature","properties":[],"geometry":{"type":"Point","coordinates":[180,0]}}]}';
expect($featureCollectionJson)->toBe($expectedFeatureCollectionJson);
});
@@ -151,17 +151,17 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
- $geometryCollectionFromWkt = GeometryCollection::fromWkt('GEOMETRYCOLLECTION(POLYGON((0 180, 1 179, 2 178, 3 177, 0 180)), POINT(0 180))');
+ $geometryCollectionFromWkt = GeometryCollection::fromWkt('GEOMETRYCOLLECTION(POLYGON((180 0, 179 1, 178 2, 177 3, 180 0)), POINT(180 0))');
expect($geometryCollectionFromWkt)->toEqual($geometryCollection);
});
@@ -170,17 +170,17 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
- $geometryCollectionFromWkt = GeometryCollection::fromWkt('GEOMETRYCOLLECTION(POLYGON((0 180, 1 179, 2 178, 3 177, 0 180)), POINT(0 180))', 4326);
+ $geometryCollectionFromWkt = GeometryCollection::fromWkt('GEOMETRYCOLLECTION(POLYGON((180 0, 179 1, 178 2, 177 3, 180 0)), POINT(180 0))', 4326);
expect($geometryCollectionFromWkt)->toEqual($geometryCollection);
});
@@ -189,19 +189,19 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
$wkt = $geometryCollection->toWkt();
- $expectedWkt = 'GEOMETRYCOLLECTION(POLYGON((0 180, 1 179, 2 178, 3 177, 0 180)), POINT(0 180))';
+ $expectedWkt = 'GEOMETRYCOLLECTION(POLYGON((180 0, 179 1, 178 2, 177 3, 180 0)), POINT(180 0))';
expect($wkt)->toBe($expectedWkt);
});
@@ -209,14 +209,14 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
$geometryCollectionFromWkb = GeometryCollection::fromWkb($geometryCollection->toWkb());
@@ -228,14 +228,14 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
$geometryCollectionFromWkb = GeometryCollection::fromWkb($geometryCollection->toWkb());
@@ -250,15 +250,15 @@
});
it('unsets geometry collection item', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
$point,
@@ -273,11 +273,11 @@
it('throws exception when unsetting geometry collection item below minimum', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
@@ -290,14 +290,14 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
$firstItemExists = isset($geometryCollection[0]);
@@ -313,18 +313,18 @@
$geometryCollection = new GeometryCollection([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
- new Point(180, 0),
+ new Point(0, 180),
]);
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
$geometryCollection[2] = $lineString;
@@ -335,16 +335,16 @@
it('throws exception when setting invalid item to geometry collection', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
expect(function () use ($polygon): void {
// @phpstan-ignore-next-line
- $polygon[1] = new Point(180, 0);
+ $polygon[1] = new Point(0, 180);
})->toThrow(InvalidArgumentException::class);
});
diff --git a/tests/Objects/GeometryTest.php b/tests/Objects/GeometryTest.php
index 47179d8..18366e6 100644
--- a/tests/Objects/GeometryTest.php
+++ b/tests/Objects/GeometryTest.php
@@ -1,7 +1,9 @@
toThrow(InvalidArgumentException::class);
});
+it('throws exception when generating geometry with invalid latitude', function (): void {
+ expect(function (): void {
+ $point = (new Point(91, 0, 4326));
+ TestPlace::factory()->create(['point' => $point]);
+ })->toThrow(QueryException::class);
+});
+
+it('throws exception when generating geometry with invalid longitude', function (): void {
+ expect(function (): void {
+ $point = (new Point(0, 181, 4326));
+ TestPlace::factory()->create(['point' => $point]);
+ })->toThrow(QueryException::class);
+});
+
it('throws exception when generating geometry from other geometry WKT', function (): void {
expect(function (): void {
- $pointWkt = 'POINT(0 180)';
+ $pointWkt = 'POINT(180 0)';
LineString::fromWkt($pointWkt);
})->toThrow(InvalidArgumentException::class);
diff --git a/tests/Objects/LineStringTest.php b/tests/Objects/LineStringTest.php
index 9fa3c02..55c67fb 100644
--- a/tests/Objects/LineStringTest.php
+++ b/tests/Objects/LineStringTest.php
@@ -10,8 +10,8 @@
it('creates a model record with line string', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
/** @var TestPlace $testPlace */
@@ -23,8 +23,8 @@
it('creates a model record with line string with SRID', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
], 4326);
/** @var TestPlace $testPlace */
@@ -35,88 +35,88 @@
it('creates line string from JSON', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
- $lineStringFromJson = LineString::fromJson('{"type":"LineString","coordinates":[[0,180],[1,179]]}');
+ $lineStringFromJson = LineString::fromJson('{"type":"LineString","coordinates":[[180,0],[179,1]]}');
expect($lineStringFromJson)->toEqual($lineString);
});
it('creates line string with SRID from JSON', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
], 4326);
- $lineStringFromJson = LineString::fromJson('{"type":"LineString","coordinates":[[0,180],[1,179]]}', 4326);
+ $lineStringFromJson = LineString::fromJson('{"type":"LineString","coordinates":[[180,0],[179,1]]}', 4326);
expect($lineStringFromJson)->toEqual($lineString);
});
it('generates line string JSON', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
$json = $lineString->toJson();
- $expectedJson = '{"type":"LineString","coordinates":[[0,180],[1,179]]}';
+ $expectedJson = '{"type":"LineString","coordinates":[[180,0],[179,1]]}';
expect($json)->toBe($expectedJson);
});
it('generates line string feature collection JSON', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
$featureCollectionJson = $lineString->toFeatureCollectionJson();
- $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"LineString","coordinates":[[0,180],[1,179]]}}]}';
+ $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"LineString","coordinates":[[180,0],[179,1]]}}]}';
expect($featureCollectionJson)->toBe($expectedFeatureCollectionJson);
});
it('creates line string from WKT', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
- $lineStringFromWkt = LineString::fromWkt('LINESTRING(0 180, 1 179)');
+ $lineStringFromWkt = LineString::fromWkt('LINESTRING(180 0, 179 1)');
expect($lineStringFromWkt)->toEqual($lineString);
});
it('creates line string with SRID from WKT', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
], 4326);
- $lineStringFromWkt = LineString::fromWkt('LINESTRING(0 180, 1 179)', 4326);
+ $lineStringFromWkt = LineString::fromWkt('LINESTRING(180 0, 179 1)', 4326);
expect($lineStringFromWkt)->toEqual($lineString);
});
it('generates line string WKT', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
$wkt = $lineString->toWkt();
- $expectedWkt = 'LINESTRING(0 180, 1 179)';
+ $expectedWkt = 'LINESTRING(180 0, 179 1)';
expect($wkt)->toBe($expectedWkt);
});
it('creates line string from WKB', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]);
$lineStringFromWkb = LineString::fromWkb($lineString->toWkb());
@@ -126,8 +126,8 @@
it('creates line string with SRID from WKB', function (): void {
$lineString = new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
], 4326);
$lineStringFromWkb = LineString::fromWkb($lineString->toWkb());
@@ -138,7 +138,7 @@
it('throws exception when line string has less than two points', function (): void {
expect(function (): void {
new LineString([
- new Point(180, 0),
+ new Point(0, 180),
]);
})->toThrow(InvalidArgumentException::class);
});
@@ -147,7 +147,7 @@
expect(function (): void {
// @phpstan-ignore-next-line
new LineString([
- Polygon::fromJson('{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}'),
+ Polygon::fromJson('{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}'),
]);
})->toThrow(InvalidArgumentException::class);
});
diff --git a/tests/Objects/MultiLineStringTest.php b/tests/Objects/MultiLineStringTest.php
index 6887279..b3fa551 100644
--- a/tests/Objects/MultiLineStringTest.php
+++ b/tests/Objects/MultiLineStringTest.php
@@ -11,8 +11,8 @@
it('creates a model record with multi line string', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
@@ -26,8 +26,8 @@
it('creates a model record with multi line string with SRID', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
], 4326);
@@ -40,12 +40,12 @@
it('creates multi line string from JSON', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
- $multiLineStringFromJson = MultiLineString::fromJson('{"type":"MultiLineString","coordinates":[[[0,180],[1,179]]]}');
+ $multiLineStringFromJson = MultiLineString::fromJson('{"type":"MultiLineString","coordinates":[[[180,0],[179,1]]]}');
expect($multiLineStringFromJson)->toEqual($multiLineString);
});
@@ -53,12 +53,12 @@
it('creates multi line string with SRID from JSON', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
], 4326);
- $multiLineStringFromJson = MultiLineString::fromJson('{"type":"MultiLineString","coordinates":[[[0,180],[1,179]]]}', 4326);
+ $multiLineStringFromJson = MultiLineString::fromJson('{"type":"MultiLineString","coordinates":[[[180,0],[179,1]]]}', 4326);
expect($multiLineStringFromJson)->toEqual($multiLineString);
});
@@ -66,40 +66,40 @@
it('generates multi line string JSON', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
$json = $multiLineString->toJson();
- $expectedJson = '{"type":"MultiLineString","coordinates":[[[0,180],[1,179]]]}';
+ $expectedJson = '{"type":"MultiLineString","coordinates":[[[180,0],[179,1]]]}';
expect($json)->toBe($expectedJson);
});
it('generates multi line string feature collection JSON', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
$featureCollectionJson = $multiLineString->toFeatureCollectionJson();
- $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"MultiLineString","coordinates":[[[0,180],[1,179]]]}}]}';
+ $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"MultiLineString","coordinates":[[[180,0],[179,1]]]}}]}';
expect($featureCollectionJson)->toBe($expectedFeatureCollectionJson);
});
it('creates multi line string from WKT', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
- $multiLineStringFromWkt = MultiLineString::fromWkt('MULTILINESTRING((0 180, 1 179))', );
+ $multiLineStringFromWkt = MultiLineString::fromWkt('MULTILINESTRING((180 0, 179 1))', );
expect($multiLineStringFromWkt)->toEqual($multiLineString);
});
@@ -107,12 +107,12 @@
it('creates multi line string with SRID from WKT', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
], 4326);
- $multiLineStringFromWkt = MultiLineString::fromWkt('MULTILINESTRING((0 180, 1 179))', 4326);
+ $multiLineStringFromWkt = MultiLineString::fromWkt('MULTILINESTRING((180 0, 179 1))', 4326);
expect($multiLineStringFromWkt)->toEqual($multiLineString);
});
@@ -120,22 +120,22 @@
it('generates multi line string WKT', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
$wkt = $multiLineString->toWkt();
- $expectedWkt = 'MULTILINESTRING((0 180, 1 179))';
+ $expectedWkt = 'MULTILINESTRING((180 0, 179 1))';
expect($wkt)->toBe($expectedWkt);
});
it('creates multi line string from WKB', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
]);
@@ -147,8 +147,8 @@
it('creates multi line string with SRID from WKB', function (): void {
$multiLineString = new MultiLineString([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
+ new Point(0, 180),
+ new Point(1, 179),
]),
], 4326);
diff --git a/tests/Objects/MultiPointTest.php b/tests/Objects/MultiPointTest.php
index 2498b23..874fcc1 100644
--- a/tests/Objects/MultiPointTest.php
+++ b/tests/Objects/MultiPointTest.php
@@ -10,7 +10,7 @@
it('creates a model record with multi point', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
]);
/** @var TestPlace $testPlace */
@@ -22,7 +22,7 @@
it('creates a model record with multi point with SRID', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
/** @var TestPlace $testPlace */
@@ -33,80 +33,80 @@
it('creates multi point from JSON', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
]);
- $multiPointFromJson = MultiPoint::fromJson('{"type":"MultiPoint","coordinates":[[0,180]]}');
+ $multiPointFromJson = MultiPoint::fromJson('{"type":"MultiPoint","coordinates":[[180,0]]}');
expect($multiPointFromJson)->toEqual($multiPoint);
});
it('creates multi point with SRID from JSON', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
- $multiPointFromJson = MultiPoint::fromJson('{"type":"MultiPoint","coordinates":[[0,180]]}', 4326);
+ $multiPointFromJson = MultiPoint::fromJson('{"type":"MultiPoint","coordinates":[[180,0]]}', 4326);
expect($multiPointFromJson)->toEqual($multiPoint);
});
it('generates multi point JSON', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
]);
$json = $multiPoint->toJson();
- $expectedJson = '{"type":"MultiPoint","coordinates":[[0,180]]}';
+ $expectedJson = '{"type":"MultiPoint","coordinates":[[180,0]]}';
expect($json)->toBe($expectedJson);
});
it('generates multi point feature collection JSON', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
]);
$multiPointFeatureCollectionJson = $multiPoint->toFeatureCollectionJson();
- $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"MultiPoint","coordinates":[[0,180]]}}]}';
+ $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"MultiPoint","coordinates":[[180,0]]}}]}';
expect($multiPointFeatureCollectionJson)->toBe($expectedFeatureCollectionJson);
});
it('creates multi point from WKT', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
]);
- $multiPointFromWkt = MultiPoint::fromWkt('MULTIPOINT(0 180)');
+ $multiPointFromWkt = MultiPoint::fromWkt('MULTIPOINT(180 0)');
expect($multiPointFromWkt)->toEqual($multiPoint);
});
it('creates multi point with SRID from WKT', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
- $multiPointFromWkt = MultiPoint::fromWkt('MULTIPOINT(0 180)', 4326);
+ $multiPointFromWkt = MultiPoint::fromWkt('MULTIPOINT(180 0)', 4326);
expect($multiPointFromWkt)->toEqual($multiPoint);
});
it('generates multi point WKT', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
]);
$wkt = $multiPoint->toWkt();
- $expectedWkt = 'MULTIPOINT(0 180)';
+ $expectedWkt = 'MULTIPOINT(180 0)';
expect($wkt)->toBe($expectedWkt);
});
it('creates multi point from WKB', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
]);
$multiPointFromWkb = MultiPoint::fromWkb($multiPoint->toWkb());
@@ -116,7 +116,7 @@
it('creates multi point with SRID from WKB', function (): void {
$multiPoint = new MultiPoint([
- new Point(180, 0),
+ new Point(0, 180),
], 4326);
$multiPointFromWkb = MultiPoint::fromWkb($multiPoint->toWkb());
@@ -134,7 +134,7 @@
expect(function (): void {
// @phpstan-ignore-next-line
new MultiPoint([
- Polygon::fromJson('{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}'),
+ Polygon::fromJson('{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}'),
]);
})->toThrow(InvalidArgumentException::class);
});
diff --git a/tests/Objects/MultiPolygonTest.php b/tests/Objects/MultiPolygonTest.php
index 01a8bfb..75ace77 100644
--- a/tests/Objects/MultiPolygonTest.php
+++ b/tests/Objects/MultiPolygonTest.php
@@ -13,11 +13,11 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
]);
@@ -33,11 +33,11 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
], 4326);
@@ -52,16 +52,16 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
]);
- $multiPolygonFromJson = MultiPolygon::fromJson('{"type":"MultiPolygon","coordinates":[[[[0,180],[1,179],[2,178],[3,177],[0,180]]]]}');
+ $multiPolygonFromJson = MultiPolygon::fromJson('{"type":"MultiPolygon","coordinates":[[[[180,0],[179,1],[178,2],[177,3],[180,0]]]]}');
expect($multiPolygonFromJson)->toEqual($multiPolygon);
});
@@ -70,16 +70,16 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
], 4326);
- $multiPolygonFromJson = MultiPolygon::fromJson('{"type":"MultiPolygon","coordinates":[[[[0,180],[1,179],[2,178],[3,177],[0,180]]]]}', 4326);
+ $multiPolygonFromJson = MultiPolygon::fromJson('{"type":"MultiPolygon","coordinates":[[[[180,0],[179,1],[178,2],[177,3],[180,0]]]]}', 4326);
expect($multiPolygonFromJson)->toEqual($multiPolygon);
});
@@ -88,18 +88,18 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
]);
$json = $multiPolygon->toJson();
- $expectedJson = '{"type":"MultiPolygon","coordinates":[[[[0,180],[1,179],[2,178],[3,177],[0,180]]]]}';
+ $expectedJson = '{"type":"MultiPolygon","coordinates":[[[[180,0],[179,1],[178,2],[177,3],[180,0]]]]}';
expect($json)->toBe($expectedJson);
});
@@ -107,18 +107,18 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
]);
$featureCollectionJson = $multiPolygon->toFeatureCollectionJson();
- $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"MultiPolygon","coordinates":[[[[0,180],[1,179],[2,178],[3,177],[0,180]]]]}}]}';
+ $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"MultiPolygon","coordinates":[[[[180,0],[179,1],[178,2],[177,3],[180,0]]]]}}]}';
expect($featureCollectionJson)->toBe($expectedFeatureCollectionJson);
});
@@ -126,16 +126,16 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
]);
- $multiPolygonFromWkt = MultiPolygon::fromWkt('MULTIPOLYGON(((0 180, 1 179, 2 178, 3 177, 0 180)))');
+ $multiPolygonFromWkt = MultiPolygon::fromWkt('MULTIPOLYGON(((180 0, 179 1, 178 2, 177 3, 180 0)))');
expect($multiPolygonFromWkt)->toEqual($multiPolygon);
});
@@ -144,16 +144,16 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
], 4326);
- $multiPolygonFromWkt = MultiPolygon::fromWkt('MULTIPOLYGON(((0 180, 1 179, 2 178, 3 177, 0 180)))', 4326);
+ $multiPolygonFromWkt = MultiPolygon::fromWkt('MULTIPOLYGON(((180 0, 179 1, 178 2, 177 3, 180 0)))', 4326);
expect($multiPolygonFromWkt)->toEqual($multiPolygon);
});
@@ -162,18 +162,18 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
]);
$wkt = $multiPolygon->toWkt();
- $expectedWkt = 'MULTIPOLYGON(((0 180, 1 179, 2 178, 3 177, 0 180)))';
+ $expectedWkt = 'MULTIPOLYGON(((180 0, 179 1, 178 2, 177 3, 180 0)))';
expect($wkt)->toBe($expectedWkt);
});
@@ -181,11 +181,11 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
]);
@@ -199,11 +199,11 @@
$multiPolygon = new MultiPolygon([
new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]),
], 4326);
diff --git a/tests/Objects/PointTest.php b/tests/Objects/PointTest.php
index 786adaa..dafb57f 100644
--- a/tests/Objects/PointTest.php
+++ b/tests/Objects/PointTest.php
@@ -7,7 +7,7 @@
uses(DatabaseMigrations::class);
it('creates a model record with point', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
@@ -17,7 +17,7 @@
});
it('creates a model record with point with SRID', function (): void {
- $point = new Point(180, 0, 4326);
+ $point = new Point(0, 180, 4326);
/** @var TestPlace $testPlace */
$testPlace = TestPlace::factory()->create(['point' => $point]);
@@ -26,27 +26,27 @@
});
it('creates point from JSON', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
- $pointFromJson = Point::fromJson('{"type":"Point","coordinates":[0,180]}');
+ $pointFromJson = Point::fromJson('{"type":"Point","coordinates":[180,0]}');
expect($pointFromJson)->toEqual($point);
});
it('creates point with SRID from JSON', function (): void {
- $point = new Point(180, 0, 4326);
+ $point = new Point(0, 180, 4326);
- $pointFromJson = Point::fromJson('{"type":"Point","coordinates":[0,180]}', 4326);
+ $pointFromJson = Point::fromJson('{"type":"Point","coordinates":[180,0]}', 4326);
expect($pointFromJson)->toEqual($point);
});
it('generates point JSON', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
$json = $point->toJson();
- $expectedJson = '{"type":"Point","coordinates":[0,180]}';
+ $expectedJson = '{"type":"Point","coordinates":[180,0]}';
expect($json)->toBe($expectedJson);
});
@@ -57,32 +57,32 @@
});
it('creates point from WKT', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
- $pointFromWkt = Point::fromWkt('POINT(0 180)');
+ $pointFromWkt = Point::fromWkt('POINT(180 0)');
expect($pointFromWkt)->toEqual($point);
});
it('creates point with SRID from WKT', function (): void {
- $point = new Point(180, 0, 4326);
+ $point = new Point(0, 180, 4326);
- $pointFromWkt = Point::fromWkt('POINT(0 180)', 4326);
+ $pointFromWkt = Point::fromWkt('POINT(180 0)', 4326);
expect($pointFromWkt)->toEqual($point);
});
it('generates point WKT', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
$wkt = $point->toWkt();
- $expectedWkt = 'POINT(0 180)';
+ $expectedWkt = 'POINT(180 0)';
expect($wkt)->toBe($expectedWkt);
});
it('creates point from WKB', function (): void {
- $point = new Point(180, 0);
+ $point = new Point(0, 180);
$pointFromWkb = Point::fromWkb($point->toWkb());
@@ -90,7 +90,7 @@
});
it('creates point with SRID from WKB', function (): void {
- $point = new Point(180, 0, 4326);
+ $point = new Point(0, 180, 4326);
$pointFromWkb = Point::fromWkb($point->toWkb());
diff --git a/tests/Objects/PolygonTest.php b/tests/Objects/PolygonTest.php
index 95821f6..1acda30 100644
--- a/tests/Objects/PolygonTest.php
+++ b/tests/Objects/PolygonTest.php
@@ -11,11 +11,11 @@
it('creates a model record with polygon', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
@@ -29,11 +29,11 @@
it('creates a model record with polygon with SRID', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
], 4326);
@@ -46,15 +46,15 @@
it('creates polygon from JSON', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
- $polygonFromJson = Polygon::fromJson('{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}');
+ $polygonFromJson = Polygon::fromJson('{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}');
expect($polygonFromJson)->toEqual($polygon);
});
@@ -62,15 +62,15 @@
it('creates polygon with SRID from JSON', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
], 4326);
- $polygonFromJson = Polygon::fromJson('{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}', 4326);
+ $polygonFromJson = Polygon::fromJson('{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}', 4326);
expect($polygonFromJson)->toEqual($polygon);
});
@@ -78,49 +78,49 @@
it('generates polygon JSON', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
$json = $polygon->toJson();
- $expectedJson = '{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}';
+ $expectedJson = '{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}';
expect($json)->toBe($expectedJson);
});
it('generates polygon feature collection JSON', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
$featureCollectionJson = $polygon->toFeatureCollectionJson();
- $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[0,180],[1,179],[2,178],[3,177],[0,180]]]}}]}';
+ $expectedFeatureCollectionJson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":[],"geometry":{"type":"Polygon","coordinates":[[[180,0],[179,1],[178,2],[177,3],[180,0]]]}}]}';
expect($featureCollectionJson)->toBe($expectedFeatureCollectionJson);
});
it('creates polygon from WKT', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
- $polygonFromWkt = Polygon::fromWkt('POLYGON((0 180, 1 179, 2 178, 3 177, 0 180))');
+ $polygonFromWkt = Polygon::fromWkt('POLYGON((180 0, 179 1, 178 2, 177 3, 180 0))');
expect($polygonFromWkt)->toEqual($polygon);
});
@@ -128,15 +128,15 @@
it('creates polygon with SRID from WKT', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
], 4326);
- $polygonFromWkt = Polygon::fromWkt('POLYGON((0 180, 1 179, 2 178, 3 177, 0 180))', 4326);
+ $polygonFromWkt = Polygon::fromWkt('POLYGON((180 0, 179 1, 178 2, 177 3, 180 0))', 4326);
expect($polygonFromWkt)->toEqual($polygon);
});
@@ -144,28 +144,28 @@
it('generates polygon WKT', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
$wkt = $polygon->toWkt();
- $expectedWkt = 'POLYGON((0 180, 1 179, 2 178, 3 177, 0 180))';
+ $expectedWkt = 'POLYGON((180 0, 179 1, 178 2, 177 3, 180 0))';
expect($wkt)->toBe($expectedWkt);
});
it('creates polygon from WKB', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
]);
@@ -177,11 +177,11 @@
it('creates polygon with SRID from WKB', function (): void {
$polygon = new Polygon([
new LineString([
- new Point(180, 0),
- new Point(179, 1),
- new Point(178, 2),
- new Point(177, 3),
- new Point(180, 0),
+ new Point(0, 180),
+ new Point(1, 179),
+ new Point(2, 178),
+ new Point(3, 177),
+ new Point(0, 180),
]),
], 4326);
diff --git a/tests/SpatialBuilderTest.php b/tests/SpatialBuilderTest.php
index 214b5f7..05a361b 100644
--- a/tests/SpatialBuilderTest.php
+++ b/tests/SpatialBuilderTest.php
@@ -9,7 +9,7 @@
uses(DatabaseMigrations::class);
it('calculates distance between column and column', function (): void {
- TestPlace::factory()->create(['point' => new Point(0, 0)]);
+ TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
/** @var TestPlace $testPlaceWithDistance */
$testPlaceWithDistance = TestPlace::query()
@@ -20,62 +20,62 @@
});
it('calculates distance between column and geometry', function (): void {
- TestPlace::factory()->create(['point' => new Point(0, 0)]);
+ TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
/** @var TestPlace $testPlaceWithDistance */
$testPlaceWithDistance = TestPlace::query()
- ->withDistance('point', new Point(1, 1))
+ ->withDistance('point', new Point(1, 1, 4326))
->firstOrFail();
- expect($testPlaceWithDistance->distance)->toBe(1.4142135623730951);
+ expect($testPlaceWithDistance->distance)->toBe(156897.79947260793);
});
it('calculates distance with alias', function (): void {
- TestPlace::factory()->create(['point' => new Point(0, 0)]);
+ TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
/** @var TestPlace $testPlaceWithDistance */
$testPlaceWithDistance = TestPlace::query()
- ->withDistance('point', new Point(1, 1), 'distance_in_meters')
+ ->withDistance('point', new Point(1, 1, 4326), 'distance_in_meters')
->firstOrFail();
- expect($testPlaceWithDistance->distance_in_meters)->toBe(1.4142135623730951);
+ expect($testPlaceWithDistance->distance_in_meters)->toBe(156897.79947260793);
});
it('filters by distance', function (): void {
- $pointWithinDistance = new Point(0, 0);
- $pointNotWithinDistance = new Point(50, 50);
+ $pointWithinDistance = new Point(0, 0, 4326);
+ $pointNotWithinDistance = new Point(50, 50, 4326);
TestPlace::factory()->create(['point' => $pointWithinDistance]);
TestPlace::factory()->create(['point' => $pointNotWithinDistance]);
/** @var TestPlace[] $testPlacesWithinDistance */
$testPlacesWithinDistance = TestPlace::query()
- ->whereDistance('point', new Point(1, 1), '<', 10)
+ ->whereDistance('point', new Point(1, 1, 4326), '<', 200_000)
->get();
expect($testPlacesWithinDistance)->toHaveCount(1);
expect($testPlacesWithinDistance[0]->point)->toEqual($pointWithinDistance);
});
-it('orders by distance', function (): void {
- $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1)]);
- $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2)]);
+it('orders by distance ASC', function (): void {
+ $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1, 4326)]);
+ $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2, 4326)]);
/** @var TestPlace[] $testPlacesOrderedByDistance */
$testPlacesOrderedByDistance = TestPlace::query()
- ->orderByDistance('point', new Point(0, 0))
+ ->orderByDistance('point', new Point(0, 0, 4326))
->get();
expect($testPlacesOrderedByDistance[0]->id)->toBe($closerTestPlace->id);
expect($testPlacesOrderedByDistance[1]->id)->toBe($fartherTestPlace->id);
});
-it('desc orders by distance', function (): void {
- $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1)]);
- $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2)]);
+it('orders by distance DESC', function (): void {
+ $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1, 4326)]);
+ $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2, 4326)]);
/** @var TestPlace[] $testPlacesOrderedByDistance */
$testPlacesOrderedByDistance = TestPlace::query()
- ->orderByDistance('point', new Point(0, 0), 'desc')
+ ->orderByDistance('point', new Point(0, 0, 4326), 'desc')
->get();
expect($testPlacesOrderedByDistance[1]->id)->toBe($closerTestPlace->id);
@@ -83,7 +83,7 @@
});
it('calculates distance sphere column and column', function (): void {
- TestPlace::factory()->create(['point' => new Point(0, 0)]);
+ TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
/** @var TestPlace $testPlaceWithDistance */
$testPlaceWithDistance = TestPlace::query()
@@ -94,62 +94,62 @@
});
it('calculates distance sphere column and geometry', function (): void {
- TestPlace::factory()->create(['point' => new Point(0, 0)]);
+ TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
/** @var TestPlace $testPlaceWithDistance */
$testPlaceWithDistance = TestPlace::query()
- ->withDistanceSphere('point', new Point(1, 1))
+ ->withDistanceSphere('point', new Point(1, 1, 4326))
->firstOrFail();
- expect($testPlaceWithDistance->distance)->toBe(157249.0357231545);
+ expect($testPlaceWithDistance->distance)->toBe(157249.59776850493);
});
it('calculates distance sphere with alias', function (): void {
- TestPlace::factory()->create(['point' => new Point(0, 0)]);
+ TestPlace::factory()->create(['point' => new Point(0, 0, 4326)]);
/** @var TestPlace $testPlaceWithDistance */
$testPlaceWithDistance = TestPlace::query()
- ->withDistanceSphere('point', new Point(1, 1), 'distance_in_meters')
+ ->withDistanceSphere('point', new Point(1, 1, 4326), 'distance_in_meters')
->firstOrFail();
- expect($testPlaceWithDistance->distance_in_meters)->toBe(157249.0357231545);
+ expect($testPlaceWithDistance->distance_in_meters)->toBe(157249.59776850493);
});
it('filters distance sphere', function (): void {
- $pointWithinDistance = new Point(0, 0);
- $pointNotWithinDistance = new Point(50, 50);
+ $pointWithinDistance = new Point(0, 0, 4326);
+ $pointNotWithinDistance = new Point(50, 50, 4326);
TestPlace::factory()->create(['point' => $pointWithinDistance]);
TestPlace::factory()->create(['point' => $pointNotWithinDistance]);
/** @var TestPlace[] $testPlacesWithinDistance */
$testPlacesWithinDistance = TestPlace::query()
- ->whereDistanceSphere('point', new Point(1, 1), '<', 200000)
+ ->whereDistanceSphere('point', new Point(1, 1, 4326), '<', 200000)
->get();
expect($testPlacesWithinDistance)->toHaveCount(1);
expect($testPlacesWithinDistance[0]->point)->toEqual($pointWithinDistance);
});
-it('orders by distance sphere', function (): void {
- $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1)]);
- $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2)]);
+it('orders by distance sphere ASC', function (): void {
+ $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1, 4326)]);
+ $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2, 4326)]);
/** @var TestPlace[] $testPlacesOrderedByDistance */
$testPlacesOrderedByDistance = TestPlace::query()
- ->orderByDistanceSphere('point', new Point(0, 0))
+ ->orderByDistanceSphere('point', new Point(0, 0, 4326))
->get();
expect($testPlacesOrderedByDistance[0]->id)->toBe($closerTestPlace->id);
expect($testPlacesOrderedByDistance[1]->id)->toBe($fartherTestPlace->id);
});
-it('desc orders by distance sphere', function (): void {
- $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1)]);
- $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2)]);
+it('orders by distance sphere DESC', function (): void {
+ $closerTestPlace = TestPlace::factory()->create(['point' => new Point(1, 1, 4326)]);
+ $fartherTestPlace = TestPlace::factory()->create(['point' => new Point(2, 2, 4326)]);
/** @var TestPlace[] $testPlacesOrderedByDistance */
$testPlacesOrderedByDistance = TestPlace::query()
- ->orderByDistanceSphere('point', new Point(0, 0), 'desc')
+ ->orderByDistanceSphere('point', new Point(0, 0, 4326), 'desc')
->get();
expect($testPlacesOrderedByDistance[1]->id)->toBe($closerTestPlace->id);
@@ -157,9 +157,9 @@
});
it('filters by within', function (): void {
- $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}');
- $pointWithinPolygon = new Point(0, 0);
- $pointOutsidePolygon = new Point(50, 50);
+ $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}', 4326);
+ $pointWithinPolygon = new Point(0, 0, 4326);
+ $pointOutsidePolygon = new Point(50, 50, 4326);
TestPlace::factory()->create(['point' => $pointWithinPolygon]);
TestPlace::factory()->create(['point' => $pointOutsidePolygon]);
@@ -173,9 +173,9 @@
});
it('filters by contains', function (): void {
- $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}');
- $pointWithinPolygon = new Point(0, 0);
- $pointOutsidePolygon = new Point(50, 50);
+ $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}', 4326);
+ $pointWithinPolygon = new Point(0, 0, 4326);
+ $pointOutsidePolygon = new Point(50, 50, 4326);
TestPlace::factory()->create(['polygon' => $polygon]);
$testPlace = TestPlace::query()
@@ -190,9 +190,9 @@
});
it('filters by touches', function (): void {
- $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[0,-1],[0,0],[-1,0],[-1,-1]]]}');
- $pointTouchesPolygon = new Point(0, 0);
- $pointNotTouchesPolygon = new Point(50, 50);
+ $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[0,-1],[0,0],[-1,0],[-1,-1]]]}', 4326);
+ $pointTouchesPolygon = new Point(0, 0, 4326);
+ $pointNotTouchesPolygon = new Point(50, 50, 4326);
TestPlace::factory()->create(['point' => $pointTouchesPolygon]);
TestPlace::factory()->create(['point' => $pointNotTouchesPolygon]);
@@ -206,9 +206,9 @@
});
it('filters by intersects', function (): void {
- $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}');
- $pointIntersectsPolygon = new Point(0, 0);
- $pointNotIntersectsPolygon = new Point(50, 50);
+ $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}', 4326);
+ $pointIntersectsPolygon = new Point(0, 0, 4326);
+ $pointNotIntersectsPolygon = new Point(50, 50, 4326);
TestPlace::factory()->create(['point' => $pointIntersectsPolygon]);
TestPlace::factory()->create(['point' => $pointNotIntersectsPolygon]);
@@ -222,9 +222,9 @@
});
it('filters by crosses', function (): void {
- $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}');
- $lineStringCrossesPolygon = LineString::fromJson('{"type":"LineString","coordinates":[[0,0],[2,0]]}');
- $lineStringNotCrossesPolygon = LineString::fromJson('{"type":"LineString","coordinates":[[50,50],[52,50]]}');
+ $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}', 4326);
+ $lineStringCrossesPolygon = LineString::fromJson('{"type":"LineString","coordinates":[[0,0],[2,0]]}', 4326);
+ $lineStringNotCrossesPolygon = LineString::fromJson('{"type":"LineString","coordinates":[[50,50],[52,50]]}', 4326);
TestPlace::factory()->create(['line_string' => $lineStringCrossesPolygon]);
TestPlace::factory()->create(['line_string' => $lineStringNotCrossesPolygon]);
@@ -238,9 +238,9 @@
});
it('filters by disjoint', function (): void {
- $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[-0.5,-1],[-0.5,-0.5],[-1,-0.5],[-1,-1]]]}');
- $pointDisjointsPolygon = new Point(0, 0);
- $pointNotDisjointsPolygon = new Point(-1, -1);
+ $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[-0.5,-1],[-0.5,-0.5],[-1,-0.5],[-1,-1]]]}', 4326);
+ $pointDisjointsPolygon = new Point(0, 0, 4326);
+ $pointNotDisjointsPolygon = new Point(-1, -1, 4326);
TestPlace::factory()->create(['point' => $pointDisjointsPolygon]);
TestPlace::factory()->create(['point' => $pointNotDisjointsPolygon]);
@@ -254,9 +254,9 @@
});
it('filters by overlaps', function (): void {
- $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-0.75,-0.75],[1,-1],[1,1],[-1,1],[-0.75,-0.75]]]}');
- $overlappingPolygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[-0.5,-1],[-0.5,-0.5],[-1,-0.5],[-1,-1]]]}');
- $notOverlappingPolygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-10,-10],[-5,-10],[-5,-5],[-10,-5],[-10,-10]]]}');
+ $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-0.75,-0.75],[1,-1],[1,1],[-1,1],[-0.75,-0.75]]]}', 4326);
+ $overlappingPolygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[-0.5,-1],[-0.5,-0.5],[-1,-0.5],[-1,-1]]]}', 4326);
+ $notOverlappingPolygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-10,-10],[-5,-10],[-5,-5],[-10,-5],[-10,-10]]]}', 4326);
TestPlace::factory()->create(['polygon' => $overlappingPolygon]);
TestPlace::factory()->create(['polygon' => $notOverlappingPolygon]);
@@ -270,8 +270,8 @@
});
it('filters by equals', function (): void {
- $point1 = new Point(0, 0);
- $point2 = new Point(50, 50);
+ $point1 = new Point(0, 0, 4326);
+ $point2 = new Point(50, 50, 4326);
TestPlace::factory()->create(['point' => $point1]);
TestPlace::factory()->create(['point' => $point2]);