Exemplo n.º 1
0
//*****************************************************************************
$query = "\n\tSELECT\n\t\theight,\n\t\tASTEXT(footprint) AS footprint\n\tFROM\n\t\tbuildings\n\tWHERE\n\t\tMBRINTERSECTS(GEOMFROMTEXT('%s'), footprint)\n    ORDER BY\n        height\n";
$args = array($boxPolygon);
$res = mysql_query(vsprintf($query, array_map("mysql_escape_string", $args)), $db);
if (mysql_error()) {
    header("HTTP/1.0 404 Not Found");
    exit;
}
if (!mysql_num_rows($res)) {
    header("HTTP/1.0 204 No Content");
    exit;
}
//*****************************************************************************
$json = array("meta" => array("n" => round($_GET["n"] * 100000) / 100000, "w" => round($_GET["w"] * 100000) / 100000, "s" => round($_GET["s"] * 100000) / 100000, "e" => round($_GET["e"] * 100000) / 100000, "x" => $XY["x"], "y" => $XY["y"], "z" => $Z), "data" => array());
//*****************************************************************************
header("Content-Type: application/json; charset=utf-8");
while ($row = mysql_fetch_object($res)) {
    $h = ($row->height ? $row->height : 5) * SCALE_Z >> $z;
    if ($h <= 1) {
        continue;
    }
    $f = strToPoly($row->footprint);
    $fp = array();
    for ($i = 0; $i < count($f) - 1; $i += 2) {
        $px = geoToPixel($f[$i], $f[$i + 1], $Z);
        $fp[$i] = $px["x"] - $XY["x"];
        $fp[$i + 1] = $px["y"] - $XY["y"];
    }
    $json["data"][] = array($h, $fp);
}
echo json_encode($json);
Exemplo n.º 2
0
    $source->query(createBBox($n, $w, $s, $e));
} catch (Exception $e) {
    header('HTTP/1.0 404 Not Found');
    exit;
}
if (!$source->count()) {
    header('HTTP/1.0 204 No Content');
    exit;
}
//*****************************************************************************
$json = array('meta' => array('n' => crop($_GET['n']), 'w' => crop($_GET['w']), 's' => crop($_GET['s']), 'e' => crop($_GET['e']), 'x' => $XY['x'], 'y' => $XY['y'], 'z' => $Z), 'data' => array());
//*****************************************************************************
header('Content-Type: application/json; charset=utf-8');
while ($row = $source->fetch()) {
    $h = ($row->height ? $row->height : 5) * $heightScale >> $z;
    if ($h <= 1) {
        continue;
    }
    $f = strToPoly($row->footprint);
    $fp = array();
    for ($i = 0; $i < count($f) - 1; $i += 2) {
        $px = preg_match('/^lat/i', $coordsOrder) ? geoToPixel($f[$i], $f[$i + 1], $Z) : geoToPixel($f[$i + 1], $f[$i], $Z);
        $fp[$i] = $px['x'] - $XY['x'] + $offsetX;
        $fp[$i + 1] = $px['y'] - $XY['y'] + $offsetY;
    }
    // Make polygon winding clockwise. This is needed for proper backface culling on client side.
    // TODO: do this during data import
    $fp = makeClockwiseWinding($fp);
    $json['data'][] = array($h, $fp);
}
echo json_encode($json);