예제 #1
0
function getElevation($lat, $lng, $source)
{
    $msg = "";
    switch ($source) {
        case "gmaps":
            $url = "http://maps.google.com/maps/api/elevation/xml?locations=" . $lat . "," . $lng . "&sensor=false";
            if (!($dom = @domxml_open_file($url))) {
                die("Error opening xml file");
            }
            $xpath = @xpath_new_context($dom);
            if ($_lat = @xpath_eval_expression($xpath, '//location/lat/text()')) {
                $_lat = $_lat->nodeset[0]->node_value();
            }
            if ($_lng = @xpath_eval_expression($xpath, '//location/lng/text()')) {
                $_lng = $_lng->nodeset[0]->node_value();
            }
            if ($alt = @xpath_eval_expression($xpath, '//elevation/text()')) {
                $alt = $alt->nodeset[0]->node_value();
                $msg = "";
            } else {
                if ($msg = @xpath_eval_expression($xpath, '//status/text()')) {
                    $msg = $msg->nodeset[0]->node_value();
                }
            }
            $ds = '';
            break;
        case "usgs":
            $url = "http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx/getElevation?X_Value=" . $lng . "&Y_Value=" . $lat . "&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=-1";
            //$dom = @domxml_open_file($url);
            if (!($dom = @domxml_open_file($url))) {
                die("Error opening xml file");
            }
            $xpath = @xpath_new_context($dom);
            if ($_lat = @xpath_eval_expression($xpath, '//Y_Value/text()')) {
                $_lat = $_lat->nodeset[0]->node_value();
            }
            if ($_lng = @xpath_eval_expression($xpath, '//X_Value/text()')) {
                $_lng = $_lng->nodeset[0]->node_value();
            }
            //if ($alt = @xpath_eval_expression($xpath, '//Elevation/text()')) {
            if ($alt = @xpath_eval_expression($xpath, '//Elevation_Only/text()')) {
                $alt = $alt->nodeset[0]->node_value();
                $msg = "";
            } else {
                if ($msg = @xpath_eval_expression($xpath, '//Elevation_Query/text()')) {
                    $msg = $msg->nodeset[0]->node_value();
                }
            }
            //if ($ds = @xpath_eval($xpath, '//Data_Source/text()')) {
            if ($ds = @xpath_eval_expression($xpath, '//Source_Layer/text()')) {
                $ds = $ds->nodeset[0]->node_value();
            }
            break;
        case "geonames":
            $url = "http://ws.geonames.org/srtm3?lat=" . $lat . "&lng=" . $lng . "&style=full&type=XML";
            //$dom = @domxml_open_file($url);
            if (!($dom = @domxml_open_file($url))) {
                die("Error opening xml file");
            }
            $xpath = @xpath_new_context($dom);
            if ($_lat = @xpath_eval_expression($xpath, '//lat/text()')) {
                $_lat = $_lat->nodeset[0]->node_value();
            }
            if ($_lng = @xpath_eval_expression($xpath, '//lng/text()')) {
                $_lng = $_lng->nodeset[0]->node_value();
            }
            if ($alt = @xpath_eval_expression($xpath, '//srtm3/text()')) {
                $alt = $alt->nodeset[0]->node_value();
                $alt = $alt == '-32768' ? 0 : $alt;
                $msg = "";
            }
            /* else {
            				if ($msg = @xpath_eval_expression($xpath, '//Elevation_Query/text()')) {
            					$msg = $msg->nodeset[0]->node_value();
            				}
            			}*/
            $ds = 'SRTM3';
            break;
        default:
            exit;
    }
    return array("lat" => $_lat, "lng" => $_lng, "alt" => $alt, "src" => $ds, "msg" => $msg, "url" => $url);
}
예제 #2
0
 function SelectNodes($query)
 {
     if (EWRPT_IS_PHP5) {
         $xpath = new DOMXPath($this->XmlDoc);
         return $xpath->query($query);
     } else {
         $xpath = xpath_new_context($this->XmlDoc);
         $xpathobj = xpath_eval_expression($xpath, $query);
         return $xpathobj->nodeset;
     }
 }