/**
  * @Route("/receiver")
  * @Method({"POST"})
  */
 public function receiverAction(Request $request)
 {
     $db = $this->get('doctrine')->getConnection();
     $maxSpeed = $this->container->getParameter('vdv.import.max_speed');
     $dbSrid = $this->container->getParameter('vdv.srid');
     $dataSrid = $this->container->getParameter('vdv.import.srid');
     $this->get('logger')->debug(__METHOD__ . ": dbSrid={$dbSrid}, dataSrid={$dataSrid}");
     // check
     try {
         if (true) {
             $cacheDir = $this->container->getParameter("kernel.cache_dir");
             $debugOutDir = $cacheDir . '/' . date('Y-m-d');
             if (!file_exists($debugOutDir)) {
                 if (false === mkdir($debugOutDir)) {
                     throw new Exception("Could not create {$debugOutDir}");
                 }
             } else {
                 if (is_dir($debugOutDir)) {
                     $debugFile = $debugOutDir . '/' . date('His') . '.geojson';
                 } else {
                     throw new Exception("{$debugOutDir} is not a directory");
                 }
             }
         }
         $featureList = FeatureList::createFromGeoJSON($request->getContent());
         $dataWriter = new DataWriter($db, $this->get('logger'));
         // $dataWriter->addFilter(new DataFilterSpikes($db, $maxSpeed));
         $dataWriter->addFilter(new DataFilterFrtExists($db, $this->get('logger')));
         $dataWriter->addTask(new ActualPositionUpdater($db));
         $dataWriter->addTask(new ActualPositionLineReference($db));
         $dataWriter->write($featureList->getFeatures(), $dataSrid, $dbSrid);
         return new Response("Data written");
     } catch (Exception $e) {
         $this->get('logger')->warning(__METHOD__ . ", " . $e->getMessage() . PHP_EOL . $e->getTraceAsString());
         $response = new Response();
         $response->setStatus(450, "Upload problems: " . $e->getMessage());
         return $response;
     }
 }
Example #2
0
    public function getStops()
    {
        $selectStops = <<<EOQ
SELECT rec_ort.onr_typ_nr,
    rec_ort.ort_nr,
    rec_ort.ort_name,
    rec_ort.ort_ref_ort_name,
    ST_AsGeoJSON(rec_ort.the_geom) as json_geom
FROM  vdv.rec_ort
EOQ;
        $featureList = new FeatureList();
        if (!is_null($this->lines)) {
            // $lines was set explicitely, otherwise everthing is accepted
            if (count($this->lines) == 0) {
                return $featureList;
            } else {
                // some lines where selected, otherwise return empty FeatureCollection
                $selectStops .= <<<EOQ

INNER JOIN vdv.lid_verlauf
    ON lid_verlauf.ort_nr=rec_ort.ort_nr
    AND lid_verlauf.onr_typ_nr=rec_ort.onr_typ_nr
WHERE             
EOQ;
                $selectStops .= LinesUtils::whereLines('lid_verlauf.li_nr', 'lid_verlauf.str_li_var', $this->lines);
            }
        }
        $res = $this->connection->query($selectStops);
        while ($row = $res->fetch(\PDO::FETCH_ASSOC)) {
            $geometry = json_decode($row['json_geom'], true);
            unset($row['json_geom']);
            $featureList->add($row, $geometry);
        }
        return $featureList->getFeatureCollection();
    }
Example #3
0
    public function positions()
    {
        $whereLines = '';
        if (!is_null($this->lines)) {
            // $lines was set explicitely, otherwise everthing is accepted
            if (count($this->lines) == 0) {
                // 0 lines set
                return array();
            }
            $whereLines = "    AND (" . LinesUtils::whereLines('rec_frt.li_nr', 'rec_frt.str_li_var', $this->lines) . ")";
        }
        $selectActPositions = <<<EOQ
SELECT
    rec_frt.frt_fid,
    gps_date,
    delay_sec,
    rec_frt.li_nr,
    rec_frt.str_li_var,
    lidname,
    insert_date,
    li_r,
    li_g,
    li_b,
    next_rec_ort.ort_nr AS ort_nr,
    next_rec_ort.onr_typ_nr AS onr_typ_nr,
    next_rec_ort.ort_name AS ort_name,
    next_rec_ort.ort_ref_ort_name AS ort_ref_ort_name,    
    ST_AsGeoJSON(ST_Transform(vehicle_position_act.the_geom, {$this->srid})) AS json_geom,
    ST_AsGeoJSON(ST_Transform(vehicle_position_act.extrapolation_geom, {$this->srid})) AS json_extrapolation_geom
FROM vdv.vehicle_position_act
INNER JOIN vdv.rec_frt
    ON vehicle_position_act.frt_fid=rec_frt.teq_nummer
INNER JOIN vdv.rec_lid
    ON rec_frt.li_nr=rec_lid.li_nr
    AND rec_frt.str_li_var=rec_lid.str_li_var
LEFT JOIN vdv.lid_verlauf lid_verlauf_next
    ON rec_frt.li_nr=lid_verlauf_next.li_nr
    AND rec_frt.str_li_var=lid_verlauf_next.str_li_var
    AND vehicle_position_act.li_lfd_nr + 1 = lid_verlauf_next.li_lfd_nr
LEFT JOIN vdv.rec_ort next_rec_ort
    ON lid_verlauf_next.onr_typ_nr=next_rec_ort.onr_typ_nr
    AND lid_verlauf_next.ort_nr=next_rec_ort.ort_nr
LEFT JOIN vdv.line_attributes
    ON rec_frt.li_nr=line_attributes.li_nr
WHERE gps_date > NOW() - interval '10 minute'
    -- AND vehicle_position_act.status='r'
{$whereLines}
EOQ;
        $res = $this->connection->query($selectActPositions);
        $featureList = new FeatureList();
        while ($row = $res->fetch(\PDO::FETCH_ASSOC)) {
            if (!is_null($row['json_extrapolation_geom'])) {
                $geometry = json_decode($row['json_extrapolation_geom'], true);
            } else {
                $geometry = json_decode($row['json_geom'], true);
            }
            unset($row['json_geom']);
            unset($row['json_extrapolation_geom']);
            $hex = str_pad(dechex($row['li_r']), 2, "0", STR_PAD_LEFT);
            $hex .= str_pad(dechex($row['li_g']), 2, "0", STR_PAD_LEFT);
            $hex .= str_pad(dechex($row['li_b']), 2, "0", STR_PAD_LEFT);
            $row['hexcolor'] = '#' . $hex;
            $row['hexcolor2'] = strtoupper($hex);
            $featureList->add($row, $geometry);
        }
        return $featureList->getFeatureCollection();
    }