gpt4 book ai didi

symfony - 学说 2 空间数据

转载 作者:行者123 更新时间:2023-12-02 10:43:58 24 4
gpt4 key购买 nike

我很难让这个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"

这是我收到的实际错误。我尝试创建点,因为显然它不喜欢 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 个整数?!

最佳答案

我将发布我找到的解决方案。基本上你需要像这样创建多边形

$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));

基本上祝大家好运,该库很有用,但文档很糟糕!昨天花了一整天的时间!!

关于symfony - 学说 2 空间数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29461857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com