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`: diff --git a/composer.json b/composer.json index 8dfecb78..fe7a0456 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "grimzy/laravel-mysql-spatial", + "name": "karlvalentin/laravel-mysql-spatial", "description": "MySQL spatial data types extension for Laravel.", "scripts": { "test": "phpunit -c phpunit.xml.dist", @@ -12,20 +12,24 @@ { "name": "Joseph Estefane", "email": "estefanejoe@gmail.com" + }, + { + "name": "Karl Valentin", + "email": "karl.valentin@kvis.de" } ], "require": { "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" diff --git a/src/Eloquent/BaseBuilder.php b/src/Eloquent/BaseBuilder.php index 549e3f98..0e564ecc 100644 --- a/src/Eloquent/BaseBuilder.php +++ b/src/Eloquent/BaseBuilder.php @@ -6,13 +6,12 @@ class BaseBuilder extends QueryBuilder { - protected function cleanBindings(array $bindings) + public function cleanBindings(array $bindings) { $spatialBindings = []; 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 9224af0f..b9324186 100644 --- a/src/Eloquent/SpatialExpression.php +++ b/src/Eloquent/SpatialExpression.php @@ -8,16 +8,11 @@ class SpatialExpression extends Expression { public function getValue() { - return "ST_GeomFromText(?, ?, 'axis-order=long-lat')"; + return "ST_GeomFromText(?)"; } public function getSpatialValue() { return $this->value->toWkt(); } - - public function getSrid() - { - return $this->value->getSrid(); - } } 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; diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 0a333f06..0bca0b78 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) { - 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()