我在使这个教义2扩展工作时遇到了极大的困难。它是https://github.com/djlambert/doctrine2-spatial,关于如何创建多边形的文档并不多。我得到了配置文件,但我正在努力创建实际的多边形。
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"
这是我得到的实际错误。我尝试创建积分,因为显然它不喜欢双打。
$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"
之后,我就好了,让我们创建一个线串对象并传递它。
$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
我现在只是迷路了,我唯一想要的就是将多边形存储在数据库中并调用空间函数,例如CONTAINS
. 您是否有任何建议或其他类似的事情来完成所有这些工作。
挖掘源代码后,我发现这个验证函数似乎是问题所在
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);
}
我理解这一点的方式是扩展不接受具有十进制值的点?!嗯,这是否意味着我需要将坐标转换为 2 个整数?!