コード例 #1
0
function addMissingStops($missingStops)
{
    global $file_stops;
    $addedStops = array();
    for ($i = 0; $i < count($missingStops); $i++) {
        $missing_stop_id = $missingStops[$i];
        // Parent stop_id is without last part (platform)
        $pos1 = strpos($missing_stop_id, ':');
        $pos2 = strpos($missing_stop_id, ':', $pos1 + 1);
        $parent_stop_id = substr($missing_stop_id, 0, $pos2);
        $missing_stop_platform = substr($missing_stop_id, $pos2 + 1);
        // Search parent station and add platform info
        if (($handleRead = fopen($file_stops, 'r')) !== false) {
            // get the first row, which contains the column-titles (if necessary)
            fgetcsv($handleRead);
            // loop through the file line-by-line
            while (($line = fgetcsv($handleRead)) !== false) {
                $id = $line[0];
                // $line is an array of the csv elements
                if (isStopAdded($addedStops, $missing_stop_id) == false && $id == $parent_stop_id) {
                    // Add stop with data from parent station
                    $parent_stop_name = $line[1];
                    $stop_name = $parent_stop_name;
                    $stop_lat = $line[2];
                    $stop_lon = $line[3];
                    $stop_platform = $missing_stop_platform;
                    $stop_station_type = 0;
                    addStop($missing_stop_id, $stop_name, $stop_lat, $stop_lon, $stop_platform, $parent_stop_id, $stop_station_type);
                    array_push($addedStops, $missing_stop_id);
                }
                // I don't know if this is really necessary, but it couldn't harm;
                // see also: http://php.net/manual/en/features.gc.php
                unset($line);
            }
            fclose($handleRead);
        }
    }
}
コード例 #2
0
ファイル: 1-stops.txt.php プロジェクト: Tjoosten/brail2gtfs
    addStop($parent_stop_id . ':0', $parent_name, $parent_lat, $parent_lon, '', $parent_stop_id, 0);
    // Search highest platformnumber of station
    // Add different platforms: stop_id of station + # + number of platform
    $nrAndLetter = getNumberAndLetterPairOfPlatforms($stationId);
    $nr = $nrAndLetter[0];
    $letter = $nrAndLetter[1];
    // Add stop for every platform with a number
    if ($nr != null) {
        $j = 1;
        while ($j <= $nr) {
            $stop_id = $parent_stop_id . ':' . $j;
            $stop_name = $parent_name;
            $stop_type = 0;
            // Todo: get latitude and longitude of every platform
            addStop($stop_id, $stop_name, $parent_lat, $parent_lon, $j, $parent_stop_id, $stop_type);
            $j++;
        }
    }
    // Add stop for every platform with a letter
    if ($letter != null) {
        $j = 'A';
        while ($j <= $letter) {
            $stop_id = $parent_stop_id . ':' . $j;
            $stop_name = $parent_name;
            $stop_type = 0;
            // Todo: get latitude and longitude of every platform
            addStop($stop_id, $stop_name, $parent_lat, $parent_lon, $j, $parent_stop_id, $stop_type);
            $j++;
        }
    }
}