Пример #1
0
 public function pointInPolygon($polygons, Point $point)
 {
     $jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($polygons, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($jsonIterator as $key => $val) {
         $region = null;
         if ($key == 'features') {
             if (is_array($val)) {
                 foreach ($val as $key => $val) {
                     $val = (object) $val;
                     if (property_exists($val, 'properties')) {
                         $per = (object) $val->properties;
                         $region = $per->Region;
                     }
                     if (property_exists($val, 'geometry')) {
                         $multipoint = geoPHP::load(json_encode($val->geometry), 'json');
                         $multipoint_points = $multipoint->getComponents();
                         $json = $multipoint_points[0]->out('json');
                         $json = json_decode($json);
                         $polygon = new \League\Geotools\Polygon\Polygon($json->coordinates);
                         if ($polygon->pointInPolygon(new \League\Geotools\Coordinate\Coordinate([$point->getLangtiude(), $point->getLattitude()]))) {
                             return array("region" => $region);
                         }
                     } else {
                         throw new \Exception("point not found !!!!!");
                     }
                 }
             }
         }
     }
 }
Пример #2
0
}
foreach ($otherOther as $odd) {
    $address = explode('،', $odd->address, 3);
    $query = "insert into `location` (`location_type`, `name`,`location_trace`,`latitude`,`longitude`)\n                                  values ('RESTAURANT','{$odd->name}' ,'<city>{$address['0']}</city><region></region><section>{$address['1']}</section><additional>{$address['2']}</additional>',{$odd->latitude},{$odd->longitude})";
    $model = new \geo\src\model\location();
    try {
        $model->hydrateRaw($query);
    } catch (Exception $ex) {
    }
}
$polygons = \Illuminate\Database\Capsule\Manager::select("SELECT *, AsText(polygon) AS poly FROM geoLocation WHERE geoLocation.detail = '' ");
foreach ($polygons as $pol) {
    $geo = geoPHP::load($pol->poly);
    $multipoint_points = $geo->getComponents();
    $geoJson = json_decode($multipoint_points[0]->out('json'));
    $polygon = new \League\Geotools\Polygon\Polygon($geoJson->coordinates);
    foreach ($tehranOther as $json) {
        if ($json->latitude != '') {
            $point = new \geo\src\model\Point();
            $json = (object) $json;
            $point->setLattitude($json->latitude);
            $point->setLangtiude($json->longitude);
            $address = explode('،', $odd->address, 2);
            $result = $polygon->pointInPolygon(new \League\Geotools\Coordinate\Coordinate([$point->getLangtiude(), $point->getLattitude()]));
            if ($result) {
                $existIn[] = $json;
                $query = "insert into `location` (`location_type`, `name`,`location_trace`,`latitude`,`longitude`)\n                                values ('RESTAURANT','{$json->name}' ,'<city>تهران</city><region>منطقه {$pol->region_id}<section>{$address['0']}</section></region><additional>{$address['1']}</additional>',{$json->latitude},{$json->longitude})";
                $model = new \geo\src\model\location();
                try {
                    $model->hydrateRaw($query);
                } catch (Exception $ex) {