Esempio n. 1
0
function reprojectPoint(&$nX, &$nY, $szFrom, $szTo)
{
    //echo "reproject $nX,$nY from $szFrom to $szTo\n";
    //check to see if reprojection is necessary
    if ($szFrom == '' || $szTo == '') {
        return;
    }
    if (stristr($szFrom, "epsg") !== false && stristr($szFrom, "init=") == false) {
        $szFrom = "init=" . strtolower($szFrom);
    }
    if (stristr($szTo, "epsg") !== false && stristr($szTo, "init=") == false) {
        $szTo = "init=" . strtolower($szTo);
    }
    if ($szFrom == $szTo) {
        return;
    }
    $oPoint = ms_newPointObj();
    $oPoint->setXY($nX, $nY);
    $oPoint->project(ms_newProjectionObj($szFrom), ms_newProjectionObj($szTo));
    $nX = $oPoint->x;
    $nY = $oPoint->y;
    //echo " :".$nX." ,".$nY."<br>";
}
Esempio n. 2
0
function getMercatorExtent($x, $y, $z)
{
    $grid_count = pow(2, $z);
    $block_size = 360.0 / $grid_count;
    $temp_x = -180.0 + $block_size * $x;
    $temp_y = 180.0 - $block_size * $y;
    $temp_x2 = $temp_x + $block_size;
    $temp_y2 = $temp_y - $block_size;
    $lon = $temp_x;
    $lat = (2.0 * atan(exp($temp_y / 180.0 * pi())) - pi() / 2.0) * 180.0 / pi();
    $lon2 = $temp_x2;
    $lat2 = (2.0 * atan(exp($temp_y2 / 180.0 * pi())) - pi() / 2.0) * 180.0 / pi();
    $projIn = ms_newProjectionObj("proj=latlong");
    $projOut = ms_newProjectionObj("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null");
    $sw = ms_newPointObj();
    $ne = ms_newPointObj();
    $sw->setXY($lon, $lat2);
    $ne->setXY($lon2, $lat);
    $sw->project($projIn, $projOut);
    $ne->project($projIn, $projOut);
    $array = array();
    $array[0] = $sw->x;
    $array[1] = $sw->y;
    $array[2] = $ne->x;
    $array[3] = $ne->y;
    return $array;
}
Esempio n. 3
0
 /**
  * Run the server and sends data
  * @return string or void
  */
 function run()
 {
     // Check cache
     if (ENABLE_CACHE) {
         $cache_file = $this->get_cache_file_name();
         if (file_exists($cache_file)) {
             $this->send_header();
             readfile($cache_file);
             exit;
         }
     }
     // If not layer are requested, send all as networklinks
     if (!$this->typename) {
         $this->_networklink = true;
         $this->typename = $this->get_layer_list();
     } else {
         $this->_networklink = false;
     }
     if ($this->_networklink == false) {
         //desliga todos os layers
         for ($i = 0; $i < $this->map_object->numlayers; $i++) {
             $l = $this->map_object->getLayer($i);
             $l->set("status", MS_OFF);
         }
         //ajusta a legenda
         $nomesl = explode(',', $this->typename);
         foreach ($nomesl as $nomel) {
             $layer = $this->map_object->getlayerbyname($nomel);
             if ($layer) {
                 $layer->set("status", MS_DEFAULT);
                 if ($layer->numclasses > 0) {
                     $classe = $layer->getclass(0);
                     if ($classe->name == "" || $classe->name == " ") {
                         $classe->set("name", $layer->getmetadata("tema"));
                     }
                     //corrige o titulo da legenda
                     $nclass = $layer->numclasses;
                     for ($j = 0; $j < $nclass; $j++) {
                         $classe = $layer->getclass($j);
                         if ($classe->title === "") {
                             $classe->title = $classe->name;
                         }
                     }
                 }
             }
         }
     }
     $imageObj = $this->map_object->drawlegend();
     $url = $imageObj->saveWebImage();
     $protocolo = explode("/", $_SERVER['SERVER_PROTOCOL']);
     $url = strtolower($protocolo[0] . "://" . $_SERVER['HTTP_HOST']) . $url;
     $legenda = "    <ScreenOverlay>" . PHP_EOL . "      <name>Legenda</name>" . PHP_EOL . "      <Icon>" . PHP_EOL . "        <href>" . $url . "</href>" . PHP_EOL . "      </Icon>" . PHP_EOL . "      <overlayXY x='0.01' y='0.14' xunits='fraction' yunits='fraction'/>" . PHP_EOL . "      <screenXY x='0.01' y='0.14' xunits='fraction' yunits='fraction'/>" . PHP_EOL . "      <size x='-1' y='-1' xunits='pixels' yunits='pixels'/>" . PHP_EOL . "    </ScreenOverlay>" . PHP_EOL;
     if ($this->_networklink == false) {
         $this->_xml = new SimpleXMLElement('<kml xmlns="http://earth.google.com/kml/2.0"><Document >' . $legenda . '</Document></kml>');
     } else {
         $this->_xml = new SimpleXMLElement('<kml xmlns="http://earth.google.com/kml/2.0"><Document ></Document></kml>');
     }
     // Prepare projection
     $this->in_proj = ms_newProjectionObj($this->map_object->getProjection());
     // Set projection to GOOGLE earth's projection
     $this->out_proj = ms_newProjectionObj("init=epsg:4326");
     // Set endpoint
     //die($_SERVER['REQUEST_URI']);
     $protocolo = explode("/", $_SERVER['SERVER_PROTOCOL']);
     $protocolo = strtolower($protocolo[0]);
     $this->endpoint = $protocolo . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'];
     // Process request
     if (!$this->has_error()) {
         $this->process_request();
     }
     if ($this->has_error()) {
         $this->add_errors();
     }
     return $this->send_stream($this->get_kml());
 }
Esempio n. 4
0
 fwrite($debug, '$_REQUEST = ' . print_r($_REQUEST, true));
 $jsonPoly = str_replace('\\', '', $_REQUEST['ROIRENDERER']);
 fwrite($debug, '$jsonPoly = ' . print_r($jsonPoly, true) . "\n");
 $_REQUEST['ROIRENDERER'] = json_decode($jsonPoly, true);
 $jsonFormats = str_replace('\\', '', $_REQUEST['formats']);
 $formats = json_decode($jsonFormats, true);
 fwrite($debug, '$_REQUEST = ' . print_r($_REQUEST, true));
 fwrite($debug, '$_REQUEST[ROIRENDERER] = ' . print_r($_REQUEST['ROIRENDERER'], true));
 fwrite($debug, '$formats = ' . print_r($formats, true));
 fwrite($debug, '$mapfile = ' . $_REQUEST['mapfile'] . "\n");
 //Obtener el mapa y la proyección de éste
 $oMap = ms_newMapObj($_REQUEST['mapfile']);
 //    fwrite($debug, '$oMap = '.print_r($oMap, true)."\n");
 $mapProj = ms_newProjectionObj($oMap->getProjection());
 //Proyección geográfica para gml y kml
 $geoProj = ms_newProjectionObj("proj=latlong");
 $nROI = count($_REQUEST['ROIRENDERER']);
 $szFileNamePol = getUniqueName('Poligonos_usuario');
 $szFileNameLin = getUniqueName('Lineas_usuario');
 $szFileNamePto = getUniqueName('Puntos_usuario');
 for ($i = 0; $i < $nROI; $i++) {
     $aROI = $_REQUEST['ROIRENDERER'][$i];
     fwrite($debug, '$aRoi = $_REQUEST[ROIRENDERER][' . i . '] = ' . print_r($aROI, true) . "\n");
     switch ($aROI['type']) {
         //            case 'rectangle':
         //                $szHayPol=true;
         //                break;
         case 'polygon':
             $szHayPol = true;
             break;
         case 'line':