private function checkPathAlarm($device, $location, $rule) { // Log::write("" . // "\ncheckPathAlarm\n" . // "\nRule:\n".print_r($rule, true)."" . // "\nDevice\n".print_r($device, true)."" . // "\nLocation\n".print_r($location, true) . // "", Log::INFO); $polyline = $this->getPathAreaPoints($rule['path_area_id']); $rule['speed'] += 0; $location['speed'] += 0; $rule['long'] += 0; $rule['distance'] += 0; $speedMsg = $this->getSpeedLimitAlarmMsg($location['speed'], $rule['speed']); $distance = round(Geometry::geoPointDistancePolyline($location['baidu_lat'], $location['baidu_lng'], $polyline)); if ($distance >= $rule['distance']) { if (empty($rule['long'])) { // 时长限制为0 $msg = '按照规则[' . $rule['label'] . '],' . $device['target_type'] . '[' . $device['target_name'] . '],' . '不允许在此时[' . date('Y-m-d H:i:s') . ']离开路径[' . $rule['path_area_label'] . ']' . $rule['distance'] . '米,' . "而现在检测到目标在路径外(坐标:{$location['baidu_lat']}, {$location['baidu_lng']}),距离路径" . $distance . '米'; $msg .= empty($speedMsg) ? '' : ',并且' . $speedMsg; return $this->startAlarm($device, $location, $rule, $msg); } else { //允许离开一段时间 $longInSeconds = $rule['long'] * 60; $curLocationId = $location['id']; while ($previousLocation = $this->getPreviousLocation($device['id'], $curLocationId)) { $historyDist = Geometry::geoPointDistancePolyline($previousLocation['baidu_lat'], $previousLocation['baidu_lng'], $polyline); if ($historyDist < $rule['distance']) { //历史轨迹点离开距离不够 return empty($speedMsg) || $distance < $rule['distance'] ? null : $this->startSpeedAlarm($device, $location, $rule); } $timeDiff = $this->getTimeDifference('now', $previousLocation['time']); if ($timeDiff >= $longInSeconds) { $msg = '按照规则[' . $rule['label'] . '],' . $device['target_type'] . '[' . $device['target_name'] . '],' . '不允许在此时[' . date('Y-m-d H:i:s') . ']离开路径[' . $rule['path_area_label'] . ']' . $rule['distance'] . '米,' . '超过' . $rule['long'] . '分钟,' . "而现在检测到目标在路径外(坐标:{$location['baidu_lat']}, {$location['baidu_lng']})," . "并且离开路径至少" . $rule['distance'] . '米' . "已经超过" . floor($timeDiff / 60) . "分钟"; $msg .= empty($speedMsg) ? '' : ',并且' . $speedMsg; return $this->startAlarm($device, $location, $rule, $msg); } $curLocationId = $previousLocation['id']; } return empty($speedMsg) || $distance < $rule['distance'] ? null : $this->startSpeedAlarm($device, $location, $rule); //已经 没有上一个定位了(时间仍不够长),不用报警 } } return null; //轨迹点在区域里面,不用报警 }
public function test7() { $point = array('latitude' => 39.915, 'longitude' => 116.404); $polyline = array(array('latitude' => 21.827688, 'longitude' => 90.279838), array('latitude' => 49.004931, 'longitude' => 114.269914), array('latitude' => 36.251841, 'longitude' => 126.780075), array('latitude' => 9.739644, 'longitude' => 128.546216)); echo "<pre>"; print_r(Geometry::geoPointPedalPolyline(39.915, 116.404, $polyline)); print_r(Geometry::geoPointDistancePolyline(39.915, 116.404, $polyline)); echo "</pre>"; }