laravel-mysql-spatial icon indicating copy to clipboard operation
laravel-mysql-spatial copied to clipboard

Allow setting WKT options or disabling WKT options entirely.

Open Persaeus opened this issue 4 years ago • 11 comments

Unlike MySQL, the WKT-input spatial analysis functions in MariaDB like ST_GeomFromText and ST_DISTANCE do not take an options parameter: https://mariadb.com/kb/en/st_geomfromtext/

If I understand correctly, we need to pass "axis-order=long-lat" because otherwise some versions of MySQL will interpret coordinate pairs as lat-long. For MariaDB, this is not necessary because MariaDB reads WKT values as long-lat by default.

In its current state, using this package with MariaDB will throw the following exception when trying to insert or update values for a spatial column, because we force the third options parameter in ST_GeomFromText:

Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'ST_GeomFromText'

This is because the MariaDB function expects at most two arguments: https://github.com/MariaDB/server/blob/cf87f3e08c10dd7a944447ddee93fbc3827e6570/sql/item_geofunc.cc#L2993

This PR adds the option to set a $wktOptions property on the model that will overwrite the default options "axis-order=long-lat". It can be set to false to remove the options parameter entirely, which fixes the errors when using MariaDB.

Additionally, it adds flexibility for users that may want or need to change the WKT options for whichever reason.

This is completely backwards-compatible, because if $wktOptions is not set, it will default to "axis-order=long-lat".

Persaeus avatar Oct 02 '20 22:10 Persaeus

Fixes #153

Persaeus avatar Oct 03 '20 21:10 Persaeus

Testing now (MariaDB 15.1) and working as expected. Thank you!

madbob avatar Oct 04 '20 18:10 madbob

@grimzy, will this request be merged?

Install package and got this error with parameters count, don't know what to do

polyskalov avatar Nov 14 '20 15:11 polyskalov

I'm waiting a merge of this pull request too

ccantet avatar Nov 22 '20 22:11 ccantet

This would be really helpful!

Wulfheart avatar Dec 14 '20 19:12 Wulfheart

This would be nice indeed. Any plans of looking this over and perhaps merging @grimzy?

carestad avatar Sep 15 '21 10:09 carestad

same, merge is strongly needed

vdomah avatar Dec 07 '21 07:12 vdomah

please add this

a-hardin avatar Dec 16 '21 15:12 a-hardin

please add this :(

bernhardh avatar Feb 21 '22 13:02 bernhardh

No activity on the master branch since Oct 2020. Looks like @grimzy might have abandoned the project.

Persaeus avatar Feb 21 '22 13:02 Persaeus

My problem is related to two Issues at once (this one, about wktOptions with MariaDB, and another one, with Laravel 9.x Compatibility).

So the solution is to make it work with Laravel 9.x + MariaDB 10.x

  1. Add repo https://github.com/Surzhikov/laravel-mysql-spatial to your composer.json:
    "repositories": [
       {
            "type": "vcs",
            "url": "https://github.com/Surzhikov/laravel-mysql-spatial"
       }
    ],
  1. composer require grimzy/laravel-mysql-spatial:master

  2. In your model add $wktOptions = '' line, like this:

<?php
namespace App\Models;
use \Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;

class MyModel extends Model
{
	use SpatialTrait;
	protected $wktOptions = '';
...

You can use this solution, while we hope that the @grimzy will have some time to build version for Laravel 9 with wktOptions ;)

Surzhikov avatar Sep 01 '22 20:09 Surzhikov