当前使用的是Grimzy Laravel MySQL Spatial,但这基本上只是将其转换为正确的SQL查询。
我需要搜索一个区域是与存储在DB中的多边形相交,重叠还是在内部或相等或包含。
public function __construct($areaPerimeterCoordinates = null)
{
$this->area = Polygon::fromJson($areaPerimeterCoordinates);
}
public function handle()
{
//this is the first query - it is working and returning result
//need to refine it to check contains/same
//$query = Property::intersects('area_perimeter', $this->area);
//working on this query - this returns empty
$query = Property::where(function($qry) {
$qry->intersects('area_perimeter', $this->area);
})->orWhere(function($qry) {
$qry->overlaps('area_perimeter', $this->area);
})->orWhere(function($qry) {
$qry->within('area_perimeter', $this->area);
})->orWhere(function($qry) {
$qry->equals('area_one_perimeter', $this->area);
})->orWhere(function($qry) {
$qry->contains('area_perimeter', $this->area);
});
$properties = $query->get();
if(!$properties->isEmpty()) {
throw new PropertyExistsException(null, $properties);
}
}
注意:按照检查第一个查询并通过添加闭包将其编辑为使用分组的方式,它也会返回空。奇怪吗?
$query = Property::where(function($qry) {
$qry->intersects('area_perimeter', $this->area);
});
$properties = $query->get();//empty
附加说明:现在,此ST_intersect有时有效,有时不起作用...
真的很感谢任何建议。谢谢。