Ejemplo n.º 1
0
 public function toSummaryGPX()
 {
     $ll = sphmerc_to_ll($this->points[0][0], $this->points[0][1]);
     return "<wpt lat='{$ll['lat']}' lon='{$ll['lon']}'><name>{$this->title}</name>" . "<desc>{$this->description}</desc>" . "<extensions><distance>{$this->distance}</distance></extensions>" . "<cmt>{$this->id}</cmt></wpt>";
 }
Ejemplo n.º 2
0
function reproject($x, $y, $inProj, $outProj)
{
    // Project to wgs84 latlon
    $inProj = strtoupper($inProj);
    $outProj = strtoupper($outProj);
    switch ($inProj) {
        case 'GOOGLE':
        case 'EPSG:900913':
        case '900913':
        case '3785':
        case 'EPSG:3785':
        case '3857':
        case 'EPSG:3857':
            $ll = sphmerc_to_ll($x, $y);
            break;
        case 'OSGB':
        case '27700':
        case 'EPSG:27700':
            /*
            $ll = gr_to_wgs84_ll($x,$y);
            $ref = new OSRef($x,$y);
            $latlng = OSRefToLatLng($ref);
            $ll = array("lon"=>$latlng->lng,"lat"=>$latlng->lat);
            */
            // 17/4/13 now use Barry Hunter's geograph code, seems to be
            // most accurate of these
            $c = new ConversionsLatLong();
            $ll0 = $c->osgb36_to_wgs84($x, $y);
            $ll = array("lon" => $ll0[1], "lat" => $ll0[0]);
            break;
        default:
            $ll = array("lon" => $x, "lat" => $y);
    }
    // Project from wgs84 latlon to output format
    switch ($outProj) {
        case 'GOOGLE':
        case 'EPSG:900913':
        case '900913':
        case '3785':
        case 'EPSG:3785':
        case '3857':
        case 'EPSG:3857':
            $sm = ll_to_sphmerc($ll['lon'], $ll['lat']);
            $x = $sm['e'];
            $y = $sm['n'];
            break;
        case 'OSGB':
        case '27700':
        case 'EPSG:27700':
            /*
            $gr = wgs84_ll_to_gr($ll['lon'],$ll['lat']);
            $x = $gr['e'];
            $y = $gr['n'];
            $ll = new LatLng($ll['lat'],$ll['lon']);
            $gr = LatLngToOSRef($ll);
            $x = $gr->easting;
            $y = $gr->northing;
            */
            // 17/4/13 now use Barry Hunter's geograph code, seems to be
            // most accurate of these
            $c = new ConversionsLatLong();
            $gr = $c->wgs84_to_osgb36($ll['lat'], $ll['lon']);
            $x = $gr[0];
            $y = $gr[1];
            break;
        default:
            $x = $ll['lon'];
            $y = $ll['lat'];
            break;
    }
    return array($x, $y);
}
Ejemplo n.º 3
0
$z = $cleaned["z"];
$tbl_prefix = isset($cleaned["tbl_prefix"]) ? $cleaned["tbl_prefix"] : "planet_osm";
$ext = isset($cleaned["ext"]) ? $cleaned["ext"] : 0;
$mftest = isset($cleaned["mftest"]) ? $cleaned["mftest"] : 0;
$outProj = isset($cleaned['outProj']) ? $cleaned['outProj'] : '3857';
adjustProj($outProj);
$kg = isset($cleaned["kg"]) ? $cleaned["kg"] : 1000;
if (!ctype_digit($x) || !ctype_digit($y) || !ctype_digit($z) || !ctype_alnum($outProj) || !preg_match("/^\\w+\$/", $tbl_prefix) || !ctype_digit($kg) || isset($cleaned["poi"]) && !preg_match("/^(\\w+,)*\\w+\$/", $cleaned["poi"]) || isset($cleaned["way"]) && !preg_match("/^(\\w+,)*\\w+\$/", $cleaned["way"]) || isset($cleaned["kothic"]) && !ctype_digit($cleaned["kothic"]) || isset($cleaned["contour"]) && !ctype_digit($cleaned["contour"]) || isset($cleaned["coastline"]) && !ctype_digit($cleaned["coastline"])) {
    header("HTTP/1.1 400 Bad Request");
    echo "Invalid format for input data";
    exit;
}
$bbox = get_sphmerc_bbox($x, $y, $z);
if (isset($cleaned["kothic"]) && $cleaned["kothic"]) {
    $sw = sphmerc_to_ll($bbox[0], $bbox[1]);
    $ne = sphmerc_to_ll($bbox[2], $bbox[3]);
    if (!file_exists(CONTOUR_CACHE . "/{$kg}/{$z}/{$x}")) {
        mkdir(CONTOUR_CACHE . "/{$kg}/{$z}/{$x}", 0755, true);
    }
    if (!file_exists(CACHE . "/{$kg}/{$z}/{$x}")) {
        mkdir(CACHE . "/{$kg}/{$z}/{$x}", 0755, true);
    }
    $bg = new BboxGetter($bbox, "3857", "3857", $ext, $kg, $tbl_prefix);
    if ($z <= 7) {
        $bg->addWayFilter("highway", "motorway,trunk,primary," . "motorway_link,primary_link,trunk_link");
        $bg->addWayFilter("railway", "rail,preserved");
        $bg->addWayFilter("waterway", "river");
        $bg->addPOIFilter("place", "city");
        $bg->includePolygons(false);
        unset($cleaned["contour"]);
    } elseif ($z <= 9) {
Ejemplo n.º 4
0
function getData($w, $s, $e, $n, $options)
{
    $conn = pg_connect("dbname=gis user=gis");
    $sw = ll_to_sphmerc($s, $w);
    $ne = ll_to_sphmerc($n, $e);
    $ctype = "Content-type: " . ($options["format"] == "json" ? "application/json" : "text/xml");
    header($ctype);
    $plyrs = explode(",", $options["poi"]);
    $wlyrs = explode(",", $options["way"]);
    $first = true;
    echo $options["format"] == "json" ? "{\"poi\":[" : "<rdata>";
    if (isset($options["poi"])) {
        $pqry = "SELECT *,(way).x,(way).y" . " FROM planet_osm_point " . "WHERE (way).x BETWEEN {$sw['e']} AND {$ne['e']} AND " . "(way).y BETWEEN {$sw['n']} AND {$ne['n']} ";
        if ($options["poi"] != "all") {
            $pqry .= criteria($plyrs);
        }
        $presult = pg_query($pqry);
        while ($prow = pg_fetch_array($presult, null, PGSQL_ASSOC)) {
            if ($options["format"] != "json") {
                $ll = sphmerc_to_ll($prow['x'], $prow['y']);
                echo "<poi lat='{$ll['lat']}' lon='{$ll['lon']}'>";
                foreach ($prow as $k => $v) {
                    if ($v != '' && $k != "x" && $k != "y" && $k != "way") {
                        echo "<tag k='{$k}' v=\"" . addslashes(htmlentities($v)) . "\" />";
                    }
                }
                echo "</poi>";
            } else {
                if ($first == true) {
                    $first = false;
                } else {
                    echo ",";
                }
                $ll = sphmerc_to_ll($prow['x'], $prow['y']);
                $prow['x'] = $ll['lon'];
                $prow['y'] = $ll['lat'];
                echo assocToJSON($prow);
            }
        }
        pg_free_result($presult);
    }
    if ($options["format"] == "json") {
        echo "], \"ways\":[";
    }
    if (isset($options["way"])) {
        $wqry = "SELECT *,astext(way)" . " FROM planet_osm_line " . "WHERE (Centroid(way)).x BETWEEN {$sw['e']} AND {$ne['e']} AND " . "(Centroid(way)).y BETWEEN {$sw['n']} AND {$ne['n']} ";
        if ($options["way"] != "all") {
            $wqry .= criteria($wlyrs);
        }
        //echo "QUERY is $wqry <br/>";
        $wresult = pg_query($wqry);
        $first = true;
        while ($wrow = pg_fetch_array($wresult, null, PGSQL_ASSOC)) {
            $m = array();
            preg_match("/LINESTRING\\((.+)\\)/", $wrow['astext'], $m);
            $poi = explode(",", $m[1]);
            if ($options["format"] != "json") {
                echo "<way>";
                foreach ($poi as $point) {
                    list($easting, $northing) = explode(" ", $point);
                    $ll = sphmerc_to_ll($easting, $northing);
                    echo "<point lat='{$ll['lat']}' lon='{$ll['lon']}' />";
                }
                foreach ($wrow as $k => $v) {
                    if ($v != '' && $k != "way" && $k != "astext") {
                        echo "<tag k='{$k}' v=\"" . addslashes(htmlentities($v)) . "\"/>";
                    }
                }
                echo "</way>";
            } else {
                if ($first == true) {
                    $first = false;
                } else {
                    echo ",";
                }
                // next way
                echo "{ \"points\" :[";
                // start the way and its points
                for ($i = 0; $i < count($poi); $i++) {
                    if ($i != 0) {
                        echo ",";
                    }
                    list($easting, $northing) = explode(" ", $poi[$i]);
                    $ll = sphmerc_to_ll($easting, $northing);
                    echo " [ {$ll['lon']}, {$ll['lat']} ]";
                }
                echo "],";
                // end its points
                echo "\"tags\":";
                // start its tags
                echo assocToJSON($wrow);
                echo "}";
                // end the way
            }
        }
        pg_free_result($wresult);
    }
    if ($options["format"] == "json") {
        echo "] }";
    } else {
        echo "</rdata>";
    }
    pg_close($conn);
}