grimzy/laravel-mysql-spatial

Polygon not inserted into MariaDB Polygon field

digitalhuman opened this issue · 0 comments

Server version: 10.3.27-MariaDB MariaDB Server

Laravel 5.8

When inserting a polygon into MariaDB I have multiple issues. The GeoSpacial trait does not handle MariaDB correctly. So, I had to tweak a bit. For Geometery collection and location (point) it is working. However, I need Polygon to work.

For GeometeryCollection I am using this;
`
/**
* Get Points string for SQL
* @param $points
* @return false|string
*/
private function getPointsString($points)
{
$sql = "";
foreach($points as $point){
$sql .= "Point({$point["lat"]} {$point["lng"]}), ";
}
return substr($sql, 0, -2);
}

/**
 * Set field to GEOspacial logic for MariaDB
 * @param $value
 */
public function setGeoFenceAttribute($value)
{
	if(!empty($value)) {
		$sql = "GeomFromText('GEOMETRYCOLLECTION(".$this->getPointsString($value).")')";
		$this->attributes["geo_fence"] = $sql;
	}
}

`
However, the setGeoFence should be Polygon. When changing the method to Polygon I get multiple issues. The field type in MariaDB is POLYGON.