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

Help performing mass insert with Eloquent

Open dbarrow opened this issue 5 years ago • 1 comments

I would like to do a mass insert, using eloquent, of thousands of points. I have tried the following with out success.

$points is an array of [n, e] coordinates.

      $piles_array = array();
      foreach($points as $point)
      {
         $pile = new Pile();
         $pile->location = new Point($point[0], $point[1]);
         $pile->elevation = $point[2];
         $pile->desc = 'desc';
         $pile->name = 'name';
         array_push($piles_array, $pile->toArray());
       }
       Pile::insert($piles_array);

The code gives an error:

SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field (SQL: insert into piles (desc, elevation, location, name) values (desc, 32.64733630635054, 411649.09109895 1797113.9031335, name))

Any help would be appreciated.

Thanks

dbarrow avatar Feb 28 '20 11:02 dbarrow

I believe you're getting this error because your database schema/table and laravel-mysql-spatial don't understand the coordinates you're trying to insert.

What version of MySQL are you using?

You might need to use MySQL 8 and unfortunately wait a bit until we get this out: https://github.com/grimzy/laravel-mysql-spatial/pull/119

grimzy avatar Mar 06 '20 19:03 grimzy