del*_*lki 3 symfony doctrine-orm mysql-spatial
我在使这个doctrine2扩展工作时遇到了极大的困难。它是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"
Run Code Online (Sandbox Code Playgroud)
这是我得到的实际错误。我尝试创建积分,因为显然它不喜欢双打。
$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"
Run Code Online (Sandbox Code Playgroud)
之后,我就好了,让我们创建一个线串对象并传递它。
$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
Run Code Online (Sandbox Code Playgroud)
我只是失去了现在,我想的唯一的事情就是存储在数据库中的多边形和调用空间功能,如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);
}
Run Code Online (Sandbox Code Playgroud)
我理解这一点的方式是扩展不接受具有十进制值的点?!嗯,这是否意味着我需要将我的坐标转换为 2 个整数?!
我会发布我找到的解决方案。基本上你需要像这样创建你的多边形
$line = new LineString($coords);
$poly = new Polygon(array($line));
//Or you can do it like this
$coords[0] = $coords;
$poly = new Polygon($coords);
//Following if you wanna use MBRContains or Contains
$dql = "SELECT p FROM polygon p WHERE MBRContains(p.geometry, GeomFromText('Point($lat $lng)'))=1";
//Dont use GeomFromText(:point), and then $point = new Point(array($lat,$lng));
Run Code Online (Sandbox Code Playgroud)
基本上祝大家好运,该库很有用,但文档很糟糕!昨天花了一整天!!
| 归档时间: |
|
| 查看次数: |
3250 次 |
| 最近记录: |