Exemplo n.º 1
0
 static function moveWaypoint($conn, $wpid, $lon, $lat)
 {
     $sphmerc = ll_to_sphmerc($lon, $lat);
     // At some point the x,y columns will go and we'll just have xy
     $stmt = $conn->prepare("UPDATE wr_waypoints SET xy=" . "GeomFromText(?,900913) WHERE id=?");
     $geom = "POINT({$sphmerc['e']} {$sphmerc['n']})";
     $stmt->bindParam(1, $geom);
     $stmt->bindParam(2, $wpid);
     $stmt->execute();
 }
Exemplo n.º 2
0
            $ids = json_decode($cpost["ids"], true);
            foreach ($ids as $id) {
                // 20/11/16 if $id is of type int, ctype_digit returns false.
                if (ctype_digit("{$id}")) {
                    $stmt = $conn->prepare("DELETE FROM annotations WHERE id=?");
                    $stmt->bindParam(1, $id);
                    $stmt->execute();
                }
            }
        } else {
            header("HTTP/1.1 401 Unauthorized");
        }
        break;
    case "move":
        if ($userid > 0) {
            if (ctype_digit($cpost["id"]) && preg_match("/^-?[\\d\\.]+\$/", $cpost["lon"]) && preg_match("/^-?[\\d\\.]+\$/", $cpost["lat"])) {
                $goog = ll_to_sphmerc($cpost['lon'], $cpost['lat']);
                $stmt = $conn->prepare("UPDATE annotations SET xy=" . "ST_PointFromText('POINT({$goog['e']} {$goog['n']})',3857) " . "WHERE id=?");
                $stmt->bindParam(1, $cpost["id"]);
                $stmt->execute();
                if ($stmt->rowCount() == 0) {
                    header("HTTP/1.1 404 Not Found");
                }
            } else {
                header("HTTP/1.1 400 Bad Request");
            }
        } else {
            header("HTTP/1.1 401 Unauthorized");
        }
        break;
}
Exemplo n.º 3
0
function mkgeom(&$coords, $lonidx, $latidx, $geomtype)
{
    $first = true;
    $txt = $geomtype == "MULTILINESTRING" ? "MULTILINESTRING((" : "LINESTRING(";
    foreach ($coords as $c) {
        if (!$first) {
            $txt .= ",";
        } else {
            $first = false;
        }
        $sphmerc = ll_to_sphmerc($c[$lonidx], $c[$latidx]);
        $txt .= "{$sphmerc['e']} {$sphmerc['n']}";
    }
    $txt .= $geomtype == "MULTILINESTRING" ? "))" : ")";
    return $txt;
}
Exemplo 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);
}