示例#1
0
function make_kml($mid)
{
    $map = map_get_single($mid);
    if ($map === false) {
        return array(false, "no such map");
    }
    // 把地圖拿出來換成 kml
    $gpx = str_replace(".tag.png", ".gpx", $map['filename']);
    // test kml happyman add test path
    $cachefile = sprintf("/srv/www/htdocs/map/gpxtmp/test/%06d/%d/%s", $map['uid'], $map['mid'], basename(str_replace(".gpx", ".kml", $gpx)));
    if (file_exists($gpx)) {
        if (0 && file_exists($cachefile) && filemtime($cachefile) >= filemtime($gpx)) {
            return array(true, $cachefile);
        }
        @mkdir(dirname($cachefile), 0755, true);
        //$cmds_args[10]  = "-x nuketypes,tracks,routes -x simplify,count=10 -x position,distance=20k";
        //	$cmds_args[11]  = "-x nuketypes,tracks,routes -x position,distance=10k";
        //	$cmds_args[12]  = "-x nuketypes,tracks,routes -x position,distance=5k";
        //$cmds_args[13]  = "-x nuketypes,tracks,routes -x position,distance=2k";
        //$cmds_args[14]  = "-x nuketypes,tracks,routes -x position,distance=1k";
        //$cmds_args[15]  = "-x nuketypes,tracks,routes -x position,distance=500m";
        //$cmds_args[16]  = "-x nuketypes,tracks,routes -x position,distance=200m";
        //$cmds_args[17]  = "-x nuketypes,tracks,routes -x position,distance=100m";
        //$cmds_args[18]  = "-x nuketypes,tracks,routes -x position,distance=1m";
        $cmd = sprintf("gpsbabel -i gpx -f %s -x nuketypes,points -o kml,lines=1,points=0,line_color=%s,line_width=3 -F %s", $gpx, pick_color($mid), $cachefile);
        exec($cmd);
        return array(true, $cachefile);
    } else {
        return array(false, "no gpx");
    }
}
示例#2
0
$number = round(2.4);
printf("2.4 rounds to the float %s", $number);
print "<br> \n";
$number = floor(2.4);
printf("2.4 rounds down to the float %s", $number);
print "<br> \n";
print "<h3> random </h3>";
function pick_color()
{
    $colors = array('red', 'orange', 'yellow', 'blue', 'green', 'indigo', 'violet');
    $i = mt_rand(0, count($colors) - 1);
    return $colors[$i];
}
mt_srand(5555);
$first = pick_color();
$second = pick_color();
// Так как mt_srand() передается конкретное значение, каждый раз
// будут выбираться одни и те же цвета: красный (red) и желтый (yellow)
print "{$first} is red and {$second} is yellow. <br>";
// Функция возвращает случайно выбранный ключ из взвешенного набора
function rand_weighted($numbers)
{
    $total = 0;
    foreach ($numbers as $number => $weight) {
        $total += $weight;
        $distribution[$number] = $total;
    }
    $rand = mt_rand(0, $total - 1);
    foreach ($distribution as $number => $weights) {
        if ($rand < $weights) {
            return $number;
示例#3
0
<?php

/*
	Printing numbers with Rand
*/
$lower = 65;
$upper = 97;
$random_number = mt_rand($lower, $upper);
echo $random_number;
echo "<hr>";
function pick_color()
{
    $colores = array('red', 'azul', 'verde', 'amarillo');
    $i = mt_rand(0, count($colores) - 1);
    return $colores[$i];
}
mt_rand(24913);
$first = pick_color();
$segundo = pick_color();
print "{$first} es rojo y {$segundo} es verde";