From 97e5f0257cdfbe06552b4a24057130ce127f68d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Talip=20Durmu=C5=9F?= Date: Tue, 15 Sep 2020 13:18:52 +0300 Subject: [PATCH 1/7] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8dfecb78..e6362e95 100644 --- a/composer.json +++ b/composer.json @@ -18,14 +18,14 @@ "php": ">=5.5.9", "ext-pdo": "*", "ext-json": "*", - "illuminate/database": "^5.2|^6.0|^7.0", + "illuminate/database": "^8.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0" }, "require-dev": { "phpunit/phpunit": "~4.8|~5.7", "mockery/mockery": "^0.9.9", - "laravel/laravel": "^5.2|^6.0|^7.0", + "laravel/laravel": "^5.2|^6.0|^7.0|^8.0", "doctrine/dbal": "^2.5", "laravel/browser-kit-testing": "^2.0", "php-coveralls/php-coveralls": "^2.0" From 791a23b521e716117df773354ba47a43c143a6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Talip=20Durmu=C5=9F?= Date: Tue, 15 Sep 2020 13:19:19 +0300 Subject: [PATCH 2/7] Update BaseBuilder.php --- src/Eloquent/BaseBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Eloquent/BaseBuilder.php b/src/Eloquent/BaseBuilder.php index 549e3f98..a2130840 100644 --- a/src/Eloquent/BaseBuilder.php +++ b/src/Eloquent/BaseBuilder.php @@ -6,7 +6,7 @@ class BaseBuilder extends QueryBuilder { - protected function cleanBindings(array $bindings) + public function cleanBindings(array $bindings) { $spatialBindings = []; foreach ($bindings as &$binding) { From 1924be2b2379134d80a451ebca1a170a2e083126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Talip=20Durmu=C5=9F?= Date: Tue, 15 Sep 2020 13:20:06 +0300 Subject: [PATCH 3/7] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e6362e95..eb5aa9cf 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "grimzy/laravel-mysql-spatial", + "name": "taliptako/laravel-mysql-spatial", "description": "MySQL spatial data types extension for Laravel.", "scripts": { "test": "phpunit -c phpunit.xml.dist", From 501553600a25ecb97ac2c4a204cc88bb91c2f833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Talip=20Durmu=C5=9F?= Date: Wed, 16 Sep 2020 16:45:51 +0300 Subject: [PATCH 4/7] Update README.md --- README.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/README.md b/README.md index 88c2a5ac..e021fcc8 100644 --- a/README.md +++ b/README.md @@ -23,19 +23,7 @@ This package also works with MariaDB. Please refer to the [MySQL/MariaDB Spatial Add the package using composer: ```sh -$ composer require grimzy/laravel-mysql-spatial -``` - -For MySQL 5.7: - -```shell -$ composer require grimzy/laravel-mysql-spatial:^2.0 -``` - -For MySQL 5.6 and 5.5: - -```shell -$ composer require grimzy/laravel-mysql-spatial:^1.0 +$ composer require taliptako/laravel-mysql-spatial ``` For Laravel versions before 5.5 or if not using auto-discovery, register the service provider in `config/app.php`: From 51a9f467b315a46d1fd51db0e9ec7df98ddf6b5b Mon Sep 17 00:00:00 2001 From: Karl Valentin Date: Wed, 7 Oct 2020 21:46:10 +0200 Subject: [PATCH 5/7] removes srid --- composer.json | 6 +++++- src/Eloquent/SpatialExpression.php | 2 +- src/Eloquent/SpatialTrait.php | 24 ++++++++---------------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index eb5aa9cf..fe7a0456 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "taliptako/laravel-mysql-spatial", + "name": "karlvalentin/laravel-mysql-spatial", "description": "MySQL spatial data types extension for Laravel.", "scripts": { "test": "phpunit -c phpunit.xml.dist", @@ -12,6 +12,10 @@ { "name": "Joseph Estefane", "email": "estefanejoe@gmail.com" + }, + { + "name": "Karl Valentin", + "email": "karl.valentin@kvis.de" } ], "require": { diff --git a/src/Eloquent/SpatialExpression.php b/src/Eloquent/SpatialExpression.php index 9224af0f..c18c6934 100644 --- a/src/Eloquent/SpatialExpression.php +++ b/src/Eloquent/SpatialExpression.php @@ -8,7 +8,7 @@ class SpatialExpression extends Expression { public function getValue() { - return "ST_GeomFromText(?, ?, 'axis-order=long-lat')"; + return "ST_GeomFromText(?)"; } public function getSpatialValue() diff --git a/src/Eloquent/SpatialTrait.php b/src/Eloquent/SpatialTrait.php index 5cc3f4b1..e3e24cb7 100755 --- a/src/Eloquent/SpatialTrait.php +++ b/src/Eloquent/SpatialTrait.php @@ -134,9 +134,8 @@ public function scopeDistance($query, $geometryColumn, $geometry, $distance) { $this->isColumnAllowed($geometryColumn); - $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat')) <= ?", [ + $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?) <= ?", [ $geometry->toWkt(), - $geometry->getSrid(), $distance, ]); @@ -149,9 +148,8 @@ public function scopeDistanceExcludingSelf($query, $geometryColumn, $geometry, $ $query = $this->scopeDistance($query, $geometryColumn, $geometry, $distance); - $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat')) != 0", [ + $query->whereRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?)) != 0", [ $geometry->toWkt(), - $geometry->getSrid(), ]); return $query; @@ -167,9 +165,8 @@ public function scopeDistanceValue($query, $geometryColumn, $geometry) $query->select('*'); } - $query->selectRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat')) as distance", [ + $query->selectRaw("st_distance(`$geometryColumn`, ST_GeomFromText(?)) as distance", [ $geometry->toWkt(), - $geometry->getSrid(), ]); } @@ -177,9 +174,8 @@ public function scopeDistanceSphere($query, $geometryColumn, $geometry, $distanc { $this->isColumnAllowed($geometryColumn); - $query->whereRaw("st_distance_sphere(`$geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat')) <= ?", [ + $query->whereRaw("st_distance_sphere(`$geometryColumn`, ST_GeomFromText(?)) <= ?", [ $geometry->toWkt(), - $geometry->getSrid(), $distance, ]); @@ -192,9 +188,8 @@ public function scopeDistanceSphereExcludingSelf($query, $geometryColumn, $geome $query = $this->scopeDistanceSphere($query, $geometryColumn, $geometry, $distance); - $query->whereRaw("st_distance_sphere($geometryColumn, ST_GeomFromText(?, ?, 'axis-order=long-lat')) != 0", [ + $query->whereRaw("st_distance_sphere($geometryColumn, ST_GeomFromText(?)) != 0", [ $geometry->toWkt(), - $geometry->getSrid(), ]); return $query; @@ -209,9 +204,8 @@ public function scopeDistanceSphereValue($query, $geometryColumn, $geometry) if (!$columns) { $query->select('*'); } - $query->selectRaw("st_distance_sphere(`$geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat')) as distance", [ + $query->selectRaw("st_distance_sphere(`$geometryColumn`, ST_GeomFromText(?)) as distance", [ $geometry->toWkt(), - $geometry->getSrid(), ]); } @@ -223,9 +217,8 @@ public function scopeComparison($query, $geometryColumn, $geometry, $relationshi throw new UnknownSpatialRelationFunction($relationship); } - $query->whereRaw("st_{$relationship}(`$geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat'))", [ + $query->whereRaw("st_{$relationship}(`$geometryColumn`, ST_GeomFromText(?))", [ $geometry->toWkt(), - $geometry->getSrid(), ]); return $query; @@ -279,9 +272,8 @@ public function scopeOrderBySpatial($query, $geometryColumn, $geometry, $orderFu throw new UnknownSpatialFunctionException($orderFunction); } - $query->orderByRaw("st_{$orderFunction}(`$geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat')) {$direction}", [ + $query->orderByRaw("st_{$orderFunction}(`$geometryColumn`, ST_GeomFromText(?)) {$direction}", [ $geometry->toWkt(), - $geometry->getSrid(), ]); return $query; From b780c0cfd523eb023da00628c96e7fa08dc06e59 Mon Sep 17 00:00:00 2001 From: Karl Valentin Date: Wed, 7 Oct 2020 23:54:47 +0200 Subject: [PATCH 6/7] removes srid --- src/Eloquent/BaseBuilder.php | 1 - src/Eloquent/SpatialExpression.php | 5 ---- src/Schema/Blueprint.php | 39 ++++++++++++---------------- src/Schema/Grammars/MySqlGrammar.php | 25 ------------------ src/Types/Factory.php | 16 ++++++------ src/Types/Geometry.php | 23 +--------------- src/Types/GeometryInterface.php | 2 +- src/Types/Point.php | 12 ++++----- 8 files changed, 31 insertions(+), 92 deletions(-) diff --git a/src/Eloquent/BaseBuilder.php b/src/Eloquent/BaseBuilder.php index a2130840..0e564ecc 100644 --- a/src/Eloquent/BaseBuilder.php +++ b/src/Eloquent/BaseBuilder.php @@ -12,7 +12,6 @@ public function cleanBindings(array $bindings) foreach ($bindings as &$binding) { if ($binding instanceof SpatialExpression) { $spatialBindings[] = $binding->getSpatialValue(); - $spatialBindings[] = $binding->getSrid(); } else { $spatialBindings[] = $binding; } diff --git a/src/Eloquent/SpatialExpression.php b/src/Eloquent/SpatialExpression.php index c18c6934..b9324186 100644 --- a/src/Eloquent/SpatialExpression.php +++ b/src/Eloquent/SpatialExpression.php @@ -15,9 +15,4 @@ public function getSpatialValue() { return $this->value->toWkt(); } - - public function getSrid() - { - return $this->value->getSrid(); - } } diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 0a333f06..5f48845c 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -10,26 +10,24 @@ class Blueprint extends IlluminateBlueprint * Add a geometry column on the table. * * @param string $column - * @param null|int $srid * * @return \Illuminate\Support\Fluent */ - public function geometry($column, $srid = null) + public function geometry($column) { - return $this->addColumn('geometry', $column, compact('srid')); + return $this->addColumn('geometry', $column); } /** * Add a point column on the table. * * @param string $column - * @param null|int $srid * * @return \Illuminate\Support\Fluent */ - public function point($column, $srid = null) + public function point($column) { - return $this->addColumn('point', $column, compact('srid')); + return $this->addColumn('point', $column); } /** @@ -40,74 +38,69 @@ public function point($column, $srid = null) * * @return \Illuminate\Support\Fluent */ - public function lineString($column, $srid = null) + public function lineString($column) { - return $this->addColumn('linestring', $column, compact('srid')); + return $this->addColumn('linestring', $column); } /** * Add a polygon column on the table. * * @param string $column - * @param null|int $srid * * @return \Illuminate\Support\Fluent */ - public function polygon($column, $srid = null) + public function polygon($column) { - return $this->addColumn('polygon', $column, compact('srid')); + return $this->addColumn('polygon', $column); } /** * Add a multipoint column on the table. * * @param string $column - * @param null|int $srid * * @return \Illuminate\Support\Fluent */ - public function multiPoint($column, $srid = null) + public function multiPoint($column) { - return $this->addColumn('multipoint', $column, compact('srid')); + return $this->addColumn('multipoint', $column); } /** * Add a multilinestring column on the table. * * @param string $column - * @param null|int $srid * * @return \Illuminate\Support\Fluent */ - public function multiLineString($column, $srid = null) + public function multiLineString($column) { - return $this->addColumn('multilinestring', $column, compact('srid')); + return $this->addColumn('multilinestring', $column); } /** * Add a multipolygon column on the table. * * @param string $column - * @param null|int $srid * * @return \Illuminate\Support\Fluent */ - public function multiPolygon($column, $srid = null) + public function multiPolygon($column) { - return $this->addColumn('multipolygon', $column, compact('srid')); + return $this->addColumn('multipolygon', $column); } /** * Add a geometrycollection column on the table. * * @param string $column - * @param null|int $srid * * @return \Illuminate\Support\Fluent */ - public function geometryCollection($column, $srid = null) + public function geometryCollection($column) { - return $this->addColumn('geometrycollection', $column, compact('srid')); + return $this->addColumn('geometrycollection', $column); } /** diff --git a/src/Schema/Grammars/MySqlGrammar.php b/src/Schema/Grammars/MySqlGrammar.php index 9afe4513..6e886de0 100644 --- a/src/Schema/Grammars/MySqlGrammar.php +++ b/src/Schema/Grammars/MySqlGrammar.php @@ -8,16 +8,6 @@ class MySqlGrammar extends IlluminateMySqlGrammar { - const COLUMN_MODIFIER_SRID = 'Srid'; - - public function __construct() - { - // Enable SRID as a column modifier - if (!in_array(self::COLUMN_MODIFIER_SRID, $this->modifiers)) { - $this->modifiers[] = self::COLUMN_MODIFIER_SRID; - } - } - /** * Adds a statement to add a geometry column. * @@ -126,19 +116,4 @@ public function compileSpatial(Blueprint $blueprint, Fluent $command) { return $this->compileKey($blueprint, $command, 'spatial'); } - - /** - * Get the SQL for a SRID column modifier. - * - * @param \Illuminate\Database\Schema\Blueprint $blueprint - * @param Fluent $column - * - * @return string|null - */ - protected function modifySrid(\Illuminate\Database\Schema\Blueprint $blueprint, Fluent $column) - { - if (!is_null($column->srid) && is_int($column->srid) && $column->srid > 0) { - return ' srid '.$column->srid; - } - } } diff --git a/src/Types/Factory.php b/src/Types/Factory.php index ed04ac2d..087348fa 100755 --- a/src/Types/Factory.php +++ b/src/Types/Factory.php @@ -6,41 +6,41 @@ class Factory implements \GeoIO\Factory { public function createPoint($dimension, array $coordinates, $srid = null) { - return new Point($coordinates['y'], $coordinates['x'], $srid); + return new Point($coordinates['y'], $coordinates['x']); } public function createLineString($dimension, array $points, $srid = null) { - return new LineString($points, $srid); + return new LineString($points); } public function createLinearRing($dimension, array $points, $srid = null) { - return new LineString($points, $srid); + return new LineString($points); } public function createPolygon($dimension, array $lineStrings, $srid = null) { - return new Polygon($lineStrings, $srid); + return new Polygon($lineStrings); } public function createMultiPoint($dimension, array $points, $srid = null) { - return new MultiPoint($points, $srid); + return new MultiPoint($points); } public function createMultiLineString($dimension, array $lineStrings, $srid = null) { - return new MultiLineString($lineStrings, $srid); + return new MultiLineString($lineStrings); } public function createMultiPolygon($dimension, array $polygons, $srid = null) { - return new MultiPolygon($polygons, $srid); + return new MultiPolygon($polygons); } public function createGeometryCollection($dimension, array $geometries, $srid = null) { - return new GeometryCollection($geometries, $srid); + return new GeometryCollection($geometries); } } diff --git a/src/Types/Geometry.php b/src/Types/Geometry.php index f840874c..f5f87afc 100644 --- a/src/Types/Geometry.php +++ b/src/Types/Geometry.php @@ -19,23 +19,6 @@ abstract class Geometry implements GeometryInterface, Jsonable, \JsonSerializabl 7 => GeometryCollection::class, ]; - protected $srid; - - public function __construct($srid = 0) - { - $this->srid = (int) $srid; - } - - public function getSrid() - { - return $this->srid; - } - - public function setSrid($srid) - { - $this->srid = (int) $srid; - } - public static function getWKTArgument($value) { $left = strpos($value, '('); @@ -80,10 +63,6 @@ public static function fromWKB($wkb) /** @var Geometry $parsed */ $parsed = $parser->parse($wkb); - if ($srid > 0) { - $parsed->setSrid($srid); - } - return $parsed; } @@ -91,7 +70,7 @@ public static function fromWKT($wkt, $srid = null) { $wktArgument = static::getWKTArgument($wkt); - return static::fromString($wktArgument, $srid); + return static::fromString($wktArgument); } public static function fromJson($geoJson) diff --git a/src/Types/GeometryInterface.php b/src/Types/GeometryInterface.php index 4f0dd1ef..bd3a2690 100644 --- a/src/Types/GeometryInterface.php +++ b/src/Types/GeometryInterface.php @@ -10,7 +10,7 @@ public static function fromWKT($wkt, $srid = 0); public function __toString(); - public static function fromString($wktArgument, $srid = 0); + public static function fromString($wktArgument); public static function fromJson($geoJson); } diff --git a/src/Types/Point.php b/src/Types/Point.php index d424ec5e..40719af4 100644 --- a/src/Types/Point.php +++ b/src/Types/Point.php @@ -12,10 +12,8 @@ class Point extends Geometry protected $lng; - public function __construct($lat, $lng, $srid = 0) + public function __construct($lat, $lng) { - parent::__construct($srid); - $this->lat = (float) $lat; $this->lng = (float) $lng; } @@ -45,11 +43,11 @@ public function toPair() return $this->getLng().' '.$this->getLat(); } - public static function fromPair($pair, $srid = 0) + public static function fromPair($pair) { list($lng, $lat) = explode(' ', trim($pair, "\t\n\r \x0B()")); - return new static((float) $lat, (float) $lng, (int) $srid); + return new static((float) $lat, (float) $lng); } public function toWKT() @@ -57,9 +55,9 @@ public function toWKT() return sprintf('POINT(%s)', (string) $this); } - public static function fromString($wktArgument, $srid = 0) + public static function fromString($wktArgument) { - return static::fromPair($wktArgument, $srid); + return static::fromPair($wktArgument); } public function __toString() From 2311bb74eb52e1fa77f36c48754d4690dbe8f56e Mon Sep 17 00:00:00 2001 From: Karl Valentin Date: Mon, 12 Oct 2020 01:00:05 +0200 Subject: [PATCH 7/7] readds srid --- src/Schema/Blueprint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 5f48845c..0bca0b78 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -25,7 +25,7 @@ public function geometry($column) * * @return \Illuminate\Support\Fluent */ - public function point($column) + public function point($column, $srid = null) { return $this->addColumn('point', $column); }