2015-04-05 47 views
2

我很難使這個doctrine2擴展工作。 這是https://github.com/djlambert/doctrine2-spatial和theres沒有很多doc如何創建一個多邊形。我得到了配置文件的工作和所有,但我掙扎着創建實際的多邊形。主義2空間數據

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個整數?!

回答

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

基本上好運氣的傢伙,該庫是有用的,但該文件是壞的! 昨天花了整整一天!