HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/elite/coordParser/nextGisParse.php
<?php

use coordParser\CommimAddress;
use coordParser\CommimAddressModel;
use coordParser\NextGisParser;

ini_set('max_execution_time', '-1');
ini_set('display_errors', '1');

require __DIR__ . '/../vendor/autoload.php';

try {
    $commimAddress = new CommimAddress();
} catch (Throwable $exception) {
    print_r($exception->getMessage() . PHP_EOL);
    die;
}

$filter = [
    'type' => CommimAddressModel::TYPE_PLOT,
    'minArea' => 500,
];
$addresses = $commimAddress->findWithOutPolygon($filter);
if (empty($addresses)) {
    print_r('Для всех адресов получены координаты' . PHP_EOL);

    return;
}

print_r('Найдено адресов без координат: ' . count($addresses) . PHP_EOL);

$nextGisParser = new NextGisParser();

$success = 0;
foreach ($addresses as $address) {
    if ($nextGisParser->getLimitRemain() <= 0) {
        print_r('На текущий час всё' . PHP_EOL);

        break;
    }

    print_r('Проверяем ' . $address->obj_kd_nmb . PHP_EOL);

    $result = $nextGisParser->getById($address->obj_kd_nmb);

    if (empty($result->features)) {
        print_r('Ничего не найдено' . PHP_EOL);
        $commimAddress->updateNextGisCoordinates($address->obj_id, '[]', 0, 0);
        $nextGisParser->adviceError();

        continue;
    }
    $features = $result->features;

    if (empty($features[0]->geometry->coordinates)) {
        print_r('Координаты не найдены' . PHP_EOL);
        $commimAddress->updateNextGisCoordinates($address->obj_id, '[]', 0, 0);
        $nextGisParser->adviceError();

        continue;
    }

    $coordinates = $features[0]->geometry->coordinates;

    $center = [0, 0, 0];
    foreach ($coordinates as &$polygons) {
        foreach ($polygons as &$polygon) {
            foreach ($polygon as &$coordinate) {
                $center[0] += $coordinate[0];
                $center[1] += $coordinate[1];
                $center[2]++;
                [$coordinate[0], $coordinate[1]] = [$coordinate[1], $coordinate[0]];
            }
        }
    }

    $center[0] = $center[0] / $center[2];
    $center[1] = $center[1] / $center[2];
    unset($center[2]);
    $success++;
    $commimAddress->updateNextGisCoordinates($address->obj_id, json_encode($coordinates), $center[0], $center[1]);
}
print_r('Успешно обновлено: ' . $success . PHP_EOL);