I am having extreme difficulty making this doctrine2 extension works. It is https://github.com/djlambert/doctrine2-spatial and theres not a lot of doc on how to create a polygon. I got the config file working and all but I am struggling with creating the actual polygon.
array:564 [
0 => array:2 [
0 => -73.698313
1 => 45.546876
]
1 => array:2 [
0 => -73.69813
1 => 45.546916
]
2 => array:2 [
0 => -73.697656
1 => 45.546899
]
3 => array:2 [
0 => -73.697413
1 => 45.546899
]
$poly = new Polygon($array);
[CrEOF\Spatial\Exception\InvalidValueException]
Invalid Polygon Point value of type "double"
This is the actual error Im getting. I tried creating points instead because apparently it doesn't like doubles.
$p = new Point($coord);
$temp[] = $p;
$poly = new Polygon($temp);
[CrEOF\Spatial\Exception\InvalidValueException]
Invalid Polygon LineString value of type "CrEOF\Spatial\PHP\Types\Geometry\Point"
After that, I was like ok, lets create a line string object and pass it.
$line = new LineString($points);
$poly - new Polygon($line);
[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 1 passed to CrEOF\Spatial\PHP\Types\AbstractPolygon::__construct() must be of the type array, object given, called in /Library/Web Server/Documents/mg/src/Momoa/ImmobilierBundle/Entity/geography/Quartier.php on line 131 and defined
Im just lost right now, the only thing I wanted was to store polygons in the database and call spatial functions such as CONTAINS. Do you have any recommendation or such other things to make all of this work.
After digging through the source code I found this validate function which seems to be the problem
case (is_array($point) && count($point) == 2 && is_numeric($point[0]) && is_numeric($point[1])):
return array_values($point);
break;
default:
throw InvalidValueException::invalidType($this, GeometryInterface::POINT, $point);
}
The way I'm understanding this is that the extension do not accept points that have decimal values ?! Huh, Does that mean I need to convert my coordinates to 2 integers ?!