Symfony 第2条原则空间数据

Symfony 第2条原则空间数据,symfony,doctrine-orm,mysql-spatial,Symfony,Doctrine Orm,Mysql Spatial,我很难让这个doctrine2扩展工作。 是的,关于如何创建多边形的文档并不多。我让配置文件正常工作,但我正在努力创建实际的多边形 array:564 [ 0 => array:2 [ 0 => -73.698313 1 => 45.546876 ] 1 => array:2 [ 0 => -73.69813 1 => 45.546916 ] 2 => array:2 [ 0 =

我很难让这个doctrine2扩展工作。 是的,关于如何创建多边形的文档并不多。我让配置文件正常工作,但我正在努力创建实际的多边形

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" 
在那之后,我想好了,让我们创建一个LineString对象并传递它

$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));
基本上是幸运的家伙,该库是有用的,但文件是坏的!
昨天花了一整天的时间

您可以通过在构造函数中传递数据来创建它。 但问题是您应该拥有有效的多边形数据:

$p=新多边形([[[lat1,lng1],[lat2,lng2],[lat3,lng3],[lat1,lng2]])

确保在多边形中

  • 有三个数组-线数组,其中线是点数组,每个点都是数组
  • 路径是闭合的-最后一个点等于第一个点
  • 多多边形的情况也是如此,但多了一个数组。F.e。
    。我想用它从JSON文件中取消序列化,但找不到任何关于它的信息。