Ejemplo n.º 1
0
 function Projection($inX, $inY, $fromPrj, $toPrj)
 {
     $poPoint = ms_newpointobj();
     $poPoint->setXY($inX, $inY);
     if ($fromPrj && $toPrj && $fromPrj != $toPrj) {
         if ($_SESSION['MS_VERSION'] >= 6) {
             $fromPrjObj = new projectionObj($fromPrj);
             $toPrjObj = new projectionObj($toPrj);
         } else {
             $fromPrjObj = ms_newprojectionobj($fromPrj);
             $toPrjObj = ms_newprojectionobj($toPrj);
         }
         $poPoint->project($fromPrjObj, $toPrjObj);
     }
     $this->x = $poPoint->x;
     $this->y = $poPoint->y;
 }
Ejemplo n.º 2
0
     $cortePixels = $layer0->getmetadata("cortepixels");
 }
 if ($cache == true) {
     carregaCacheImagem($cachedir, $nomeMapfileTmp, "/googlemaps/{$layer0->name}/{$z}/{$x}/{$y}");
 }
 $n = pow(2, $z);
 $lon1 = $x / $n * 360.0 - 180.0;
 $lat2 = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n))));
 $x++;
 $y++;
 $lon2 = $x / $n * 360.0 - 180.0;
 $lat1 = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n))));
 $x--;
 $y--;
 $projInObj = ms_newprojectionobj($projDefault["proj4"]);
 $projOutObj = ms_newprojectionobj("proj=merc,a=6378137,b=6378137,lat_ts=0.0,lon_0=0.0,x_0=0.0,y_0=0,k=1.0,units=m");
 $poPoint1 = ms_newpointobj();
 $poPoint1->setXY($lon1, $lat1);
 $poPoint1->project($projInObj, $projOutObj);
 $poPoint2 = ms_newpointobj();
 $poPoint2->setXY($lon2, $lat2);
 $poPoint2->project($projInObj, $projOutObj);
 $oMap->setsize(256, 256);
 $oMap->setExtent($poPoint1->x, $poPoint1->y, $poPoint2->x, $poPoint2->y);
 $oMap->getlayer(0)->set("status", MS_DEFAULT);
 $oMap->setProjection("proj=merc,a=6378137,b=6378137,lat_ts=0.0,lon_0=0.0,x_0=0.0,y_0=0,k=1.0,units=m");
 $layer0->setProjection($projDefault["proj4"]);
 //
 //se o layer foi marcado para corte altera os parametros para ampliar o mapa
 //antes de gerar a imagem
 //
Ejemplo n.º 3
0
 function projetaDistancia($shape, $distancia)
 {
     error_reporting(0);
     $pt = $shape->getCentroid();
     $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs");
     $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=0,lon_0=" . $pt->x . ",x_0=5000000,y_0=10000000");
     $poPoint = ms_newpointobj();
     $poPoint->setXY($pt->x, $pt->y);
     $poPoint->project($projInObj, $projOutObj);
     $dd2 = ms_newpointobj();
     $dd2->setXY($poPoint->x + $distancia, $poPoint->y);
     $dd2->project($projOutObj, $projInObj);
     $d = $pt->distanceToPoint($dd2);
     if ($d < 0) {
         $d = $d * -1;
     }
     return $d;
 }
Ejemplo n.º 4
0
 /**
  * FUNCTION TO RETURN URL FOR MAPFRAME
  * used for starting application with pre-defined extent
  * extent read from shape features
  */
 function getMapInitURL($map, $zoomLayer, $zoomQuery)
 {
     $qLayer = $this->map->getLayerByName($zoomLayer);
     // Query parameters
     $queryList = preg_split('/@/', $zoomQuery);
     $queryField = $queryList[0];
     $queryFieldType = $queryList[1];
     //$queryValue = "/^" . $queryList[2] ."$/";
     $queryValue = $queryList[2];
     $highlFeature = $queryList[3];
     $setMaxExtent = $queryList[4];
     // Modify filter for PostGIS & Oracle layers
     if ($qLayer->connectiontype == 6 || $qLayer->connectiontype == 8) {
         $q = $queryFieldType == 1 ? "'" : "";
         $queryValue = "{$queryField} = {$q}{$queryValue}{$q}";
         //error_log($queryValue);
     }
     // Query layer
     @$qLayer->queryByAttributes($queryField, $queryValue, MS_MULTIPLE);
     $numResults = $qLayer->getNumResults();
     $qLayer->open();
     // Return query results (SINGLE FEATURE): shape index and feature extent
     /*
     $qRes = $qLayer->getResult(0);
     $qShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $qLayer, $qRes);
     $qShpIdx = $qShape->index;
     $qShpBounds = $qShape->bounds;
     */
     // Check if layer has different projection than map
     // if yes, re-project extent from layer to map projection
     $mapProjStr = $this->map->getProjection();
     $qLayerProjStr = $qLayer->getProjection();
     if ($mapProjStr && $qLayerProjStr && $mapProjStr != $qLayerProjStr) {
         if ($_SESSION['MS_VERSION'] < 6) {
             $mapProjObj = ms_newprojectionobj($mapProjStr);
             $qLayerProjObj = ms_newprojectionobj($qLayerProjStr);
         } else {
             $mapProjObj = new projectionObj($mapProjStr);
             $qLayerProjObj = new projectionObj($qLayerProjStr);
         }
         //$qShpBounds->project($this->qLayerProjObj, $this->mapProjObj);
         $reprojectShape = 1;
     }
     // initial max/min values
     $mExtMinx = 999999999;
     $mExtMiny = 999999999;
     $mExtMaxx = -999999999;
     $mExtMaxy = -999999999;
     // ABP: Store all shape indexes
     $qShpIdxArray = array();
     // Return query results: shape index and feature extent
     for ($iRes = 0; $iRes < $numResults; $iRes++) {
         $qRes = $qLayer->getResult($iRes);
         $qShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $qLayer, $qRes);
         $qShpIdx = $qShape->index;
         $qShpIdxArray[] = $qShpIdx;
         $qShpBounds = $qShape->bounds;
         if ($reprojectShape) {
             $qShpBounds->project($qLayerProjObj, $mapProjObj);
         }
         $shpMinx = $qShpBounds->minx;
         $shpMiny = $qShpBounds->miny;
         $shpMaxx = $qShpBounds->maxx;
         $shpMaxy = $qShpBounds->maxy;
         // Get max/min values of ALL features
         $mExtMinx = min($mExtMinx, $shpMinx);
         $mExtMiny = min($mExtMiny, $shpMiny);
         $mExtMaxx = max($mExtMaxx, $shpMaxx);
         $mExtMaxy = max($mExtMaxy, $shpMaxy);
     }
     // Apply buffer (in units of features)
     if ($qLayer->type == 0) {
         $buffer = $_SESSION["pointBuffer"];
     } else {
         $buffer = $_SESSION["shapeQueryBuffer"] * (($mExtMaxx - $mExtMinx + ($mExtMaxy - $mExtMiny)) / 2);
     }
     $mExtMinx -= $buffer;
     $mExtMiny -= $buffer;
     $mExtMaxx += $buffer;
     $mExtMaxy += $buffer;
     $roundFact = $map->units != 5 ? 0 : 6;
     $shpMinx = round($mExtMinx, $roundFact);
     $shpMiny = round($mExtMiny, $roundFact);
     $shpMaxx = round($mExtMaxx, $roundFact);
     $shpMaxy = round($mExtMaxy, $roundFact);
     // no object found --> extent = mapExtent
     if (!$qShpIdxArray) {
         $mapExtent = $this->map->extent;
         $shpMinx = $mapExtent->minx;
         $shpMiny = $mapExtent->miny;
         $shpMaxx = $mapExtent->maxx;
         $shpMaxy = $mapExtent->maxy;
         $highlFeature = false;
         $setMaxExtent = false;
     }
     $ext = array($shpMinx, $shpMiny, $shpMaxx, $shpMaxy);
     $_SESSION['zoom_extparams'] = $ext;
     // Set Max Extent for map
     if ($setMaxExtent) {
         $mapMaxExt['minx'] = $shpMinx;
         $mapMaxExt['miny'] = $shpMiny;
         $mapMaxExt['maxx'] = $shpMaxx;
         $mapMaxExt['maxy'] = $shpMaxy;
         $_SESSION['mapMaxExt'] = $mapMaxExt;
     }
     // Add highlight feature if defined in URL parameters
     if ($highlFeature) {
         $resultlayers[$zoomLayer] = $qShpIdxArray;
         $_SESSION["resultlayers"] = $resultlayers;
     }
     // Return URL
     $searchString = "&mode=map&zoom_type=zoomextent&extent=" . $shpMinx . "+" . $shpMiny . "+" . $shpMaxx . "+" . $shpMaxy . ($highlFeature ? "&resultlayer={$zoomLayer}+{$qShpIdx}" : "");
     $mapInitURL = "map.phtml?{$searchString}";
     return $mapInitURL;
 }
Ejemplo n.º 5
0
}
$myStations = array();
$formStr = "";
$cgiStr = "";
if (!isset($str)) {
    $str = array();
}
foreach ($Scities as $key => $value) {
    $myStations[$key] = "hi";
}
$var = isset($_GET["var"]) ? $_GET["var"] : "tmpf";
$height = 350;
$width = 450;
$proj = "init=epsg:26915";
$projInObj = ms_newprojectionobj("init=epsg:4326");
$projOutObj = ms_newprojectionobj($proj);
$varDef = array("tmpf" => "Current Temperatures", "dwpf" => "Current Dew Points", "sped" => "Current Wind Speed [MPH]", "sknt" => "Current Wind Speed [knts]", "barb" => "Current Wind Barbs [knts]", "gbarb" => "Today Wind Gust Barbs [knts]", "max_sped" => "Today's Wind Gust [MPH]", "max_sknt" => "Today's Wind Gust [knts]", "feel" => "Currently Feels Like", "tmpf_max" => "Today's High Temperature", "tmpf_min" => "Today's Low Temperature", "pmonth" => "This Month's Precip", "pday" => "Today's Precip");
$rnd = array("tmpf" => 0, "dwpf" => 0, "sknt" => 0, "max_sknt" => 0, "feel" => 0, "pmonth" => 2, "pday" => 2);
$height = 480;
$width = 640;
$map = ms_newMapObj("../../../../data/gis/base26915.map");
$map->setSize($width, $height);
$map->setprojection($proj);
if (isset($_GET["zoom"])) {
    $map->setextent(375000, 4575000, 475000, 4675000);
} else {
    if ($network == "KIMT") {
        $map->setextent(420000, 4740000, 600000, 4900000);
    } else {
        if ($network == "KELO") {
            $map->setextent(-400000, 4600000, 320000, 5200000);
Ejemplo n.º 6
0
 function zoomSel()
 {
     if (!$this->layer) {
         return "erro";
     }
     if ($this->mapa->getmetadata("interface") == "googlemaps") {
         $projO = $this->mapa->getProjection();
         $projecao = pegaProjecaoDefault("epsg");
         $this->mapa->setProjection("init=epsg:" . $projecao);
     }
     $extatual = $this->mapa->extent;
     $prjMapa = $this->mapa->getProjection();
     $prjTema = $this->layer->getProjection();
     $shapes = retornaShapesSelecionados($this->layer, $this->arquivo, $this->mapa);
     $xmin = array();
     $xmax = array();
     $ymin = array();
     $ymax = array();
     foreach ($shapes as $shape) {
         $bound = $shape->bounds;
         $xmin[] = $bound->minx;
         $xmax[] = $bound->maxx;
         $ymin[] = $bound->miny;
         $ymax[] = $bound->maxy;
     }
     $ret = ms_newRectObj();
     $ret->set("minx", min($xmin));
     $ret->set("miny", min($ymin));
     $ret->set("maxx", max($xmax));
     $ret->set("maxy", max($ymax));
     if ($prjTema != "" && $prjMapa != $prjTema) {
         $projInObj = ms_newprojectionobj($prjTema);
         $projOutObj = ms_newprojectionobj($prjMapa);
         $ret->project($projInObj, $projOutObj);
     }
     $extatual->setextent($ret->minx, $ret->miny, $ret->maxx, $ret->maxy);
     if ($this->mapa->getmetadata("interface") == "googlemaps") {
         $this->mapa->setProjection($projO);
     }
     return "ok";
 }
Ejemplo n.º 7
0
Archivo: map.php Proyecto: sukma279/GIS
 /**
  * FOR ZOOM TO SELECTED.
  * Adds a new layer to the map for highlighting feature
  */
 private function pmap_addResultLayer($reslayer, $shpindexes)
 {
     if (isset($_SESSION["resulttilelayers"])) {
         $resulttilelayers = $_SESSION["resulttilelayers"];
         $resulttilelayer = $resulttilelayers[$reslayer];
     } else {
         $resulttilelayers = null;
         $resulttilelayer = null;
     }
     $qLayer = $this->map->getLayerByName($reslayer);
     $qlayType = $qLayer->type;
     $layNum = count($this->map->getAllLayerNames());
     // Test if layer has the same projection as map
     $mapProjStr = $this->map->getProjection();
     $qLayerProjStr = $qLayer->getProjection();
     $changeLayProj = false;
     if ($mapProjStr && $qLayerProjStr && $mapProjStr != $qLayerProjStr) {
         $changeLayProj = true;
         if ($_SESSION['MS_VERSION'] < 6) {
             $mapProjObj = ms_newprojectionobj($mapProjStr);
             $qLayerProjObj = ms_newprojectionobj($qLayerProjStr);
         } else {
             $mapProjObj = new projectionObj($mapProjStr);
             $qLayerProjObj = new projectionObj($qLayerProjStr);
         }
     }
     // New result layer
     if ($_SESSION['PM_TPL_MAP_FILE']) {
         // load from template map file
         $hlDynLayer = 0;
         $hlMap = ms_newMapObj($_SESSION['PM_TPL_MAP_FILE']);
         $hlMapLayer = $hlMap->getLayerByName("highlight_{$qlayType}");
         $hlMapLayer->set("name", "pmapper_reslayer");
         $newResLayer = ms_newLayerObj($this->map, $hlMapLayer);
     } else {
         // create dynamically
         $hlDynLayer = 1;
         $newResLayer = ms_newLayerObj($this->map);
         $newResLayer->set("name", "pmapper_reslayer");
         if ($qlayType == 0) {
             $newResLayer->set("type", 0);
             // Point for point layer
         } elseif ($qlayType == 1 || $qlayType == 2) {
             $newResLayer->set("type", 1);
             // Line for line && polygon layers
         }
         //##$newResLayer->set("type", $qlayType);  // Take always same layer type as layer itself
     }
     // Add selected shape to new layer
     //# when layer is an event theme
     if ($qLayer->getMetaData("XYLAYER_PROPERTIES") != "") {
         foreach ($shpindexes as $cStr) {
             $cList = preg_split('/@/', $cStr);
             $xcoord = $cList[0];
             $ycoord = $cList[1];
             $resLine = ms_newLineObj();
             // needed to use a line because only a line can be added to a shapeObj
             $resLine->addXY($xcoord, $ycoord);
             $resShape = ms_newShapeObj(1);
             $resShape->add($resLine);
             $newResLayer->addFeature($resShape);
         }
         //# specific for PG layers  <==== required for MS >= 5.6 !!!
     } elseif ($qLayer->connectiontype == 6) {
         $newResLayer->set("connection", $qLayer->connection);
         if (method_exists($newResLayer, "setConnectionType")) {
             $newResLayer->setConnectionType($qLayer->connectiontype);
         } else {
             $newResLayer->set("connectiontype", $qLayer->connectiontype);
         }
         $data = $qLayer->data;
         // use layers with complex queries that are too long to select results
         // cause maxscaledenom is not used...
         if ($qLayer->getMetaData("PM_RESULT_DATASUBSTITION") != "") {
             $data = $qLayer->getMetaData("PM_RESULT_DATASUBSTITION");
         }
         $newResLayer->set("data", $data);
         if ($qLayerProjStr) {
             $newResLayer->setProjection($qLayerProjStr);
         }
         $glList = PMCommon::returnGroupGlayer($reslayer);
         $glayer = $glList[1];
         $layerDbProperties = $glayer->getLayerDbProperties();
         $uniqueField = $layerDbProperties['unique_field'];
         $indexesStr = implode(",", $shpindexes);
         $idFilter = "({$uniqueField} IN ({$indexesStr}))";
         $newResLayer->setFilter($idFilter);
         //# 'normal' layers
     } else {
         // Add selected shape to new layer
         // Modified by Thomas RAFFIN (SIRAP)
         // use layers with complex queries that are too long to select results
         // cause maxscaledenom is not used...
         $olddata = false;
         if ($qLayer->getMetaData("PM_RESULT_DATASUBSTITION") != "") {
             $olddata = $qLayer->data;
             $qLayer->set("data", $qLayer->getMetaData("PM_RESULT_DATASUBSTITION"));
         }
         $qLayer->open();
         foreach ($shpindexes as $resShpIdx) {
             if (preg_match("/@/", $resShpIdx)) {
                 $idxList = explode("@", $resShpIdx);
                 $resTileShpIdx = $idxList[0];
                 $resShpIdx = $idxList[1];
             } else {
                 $resTileShpIdx = $resulttilelayer[$resShpIdx];
             }
             $resShape = PMCommon::resultGetShape($this->msVersion, $qLayer, null, $resShpIdx, $resTileShpIdx);
             // changed for compatibility with PG layers and MS >= 5.6
             // Change projection to map projection if necessary
             if ($changeLayProj) {
                 // If error appears here for Postgis layers, then DATA is not defined properly as:
                 // "the_geom from (select the_geom, oid, xyz from layer) AS new USING UNIQUE oid USING SRID=4258"
                 if ($resShape) {
                     $resShape->project($qLayerProjObj, $mapProjObj);
                 }
             }
             if ($resShape) {
                 $newResLayer->addFeature($resShape);
             }
         }
         $qLayer->close();
         // Modified by Thomas RAFFIN (SIRAP)
         // use layers with complex queries that are too long to select results
         // cause maxscaledenom is not used...
         // reset data tag
         if ($olddata) {
             $qLayer->set("data", $olddata);
         }
     }
     $newResLayer->set("status", MS_ON);
     $newResLayerIdx = $newResLayer->index;
     if ($hlDynLayer) {
         // SELECTION COLOR
         $iniClrStr = trim($_SESSION["highlightColor"]);
         $iniClrList = preg_split('/[\\s,]+/', $iniClrStr);
         $iniClr0 = $iniClrList[0];
         $iniClr1 = $iniClrList[1];
         $iniClr2 = $iniClrList[2];
         // CREATE NEW CLASS
         $resClass = ms_newClassObj($newResLayer);
         $clStyle = ms_newStyleObj($resClass);
         $clStyle->color->setRGB($iniClr0, $iniClr1, $iniClr2);
         $clStyle->set("symbolname", "circle");
         $symSize = $qlayType < 1 ? 10 : 5;
         $clStyle->set("size", $symSize);
     }
     // Move layer to top (is it working???)
     while ($newResLayerIdx < $layNum - 1) {
         $this->map->moveLayerUp($newResLayerIdx);
     }
 }
Ejemplo n.º 8
0
 /**
  * Return map extent in projected coordinates
  * @return array $mePrj
  */
 protected function getMapExtent($dataSpecs)
 {
     $extBuffer = isset($_SESSION['pluginsConfig']['dynlayercat']['mapExtentBuffer']) ? $_SESSION['pluginsConfig']['dynlayercat']['mapExtentBuffer'] : 0;
     $layerProjStr = "init=" . $dataSpecs['epsg'];
     $layerPrj = ms_newprojectionobj($layerProjStr);
     $latlonPrj = ms_newprojectionobj("init=epsg:4326");
     //$le = $dataSpecs['bbox'];
     $le = array();
     foreach ($dataSpecs['bbox'] as $k => $v) {
         $buffer = $v < 0 ? $extBuffer * -1 : $extBuffer;
         $le[$k] = $v + $buffer;
     }
     $mapExt = ms_newRectObj();
     $mapExt->setExtent($le['westLon'], $le['southLat'], $le['eastLon'], $le['northLat']);
     $mapExt->project($latlonPrj, $layerPrj);
     //error_log($mapExtLatLon->minx . ", " . $mapExtLatLon->miny . ", " . $mapExtLatLon->maxx . ", " . $mapExtLatLon->maxy  );
     $mePrj = array("minx" => $mapExt->minx, "miny" => $mapExt->miny, "maxx" => $mapExt->maxx, "maxy" => $mapExt->maxy);
     return $mePrj;
 }
Ejemplo n.º 9
0
 function shpPT2shp($locaplic, $para)
 {
     if (!$this->layer) {
         return "erro";
     }
     $this->layer->set("template", "none.htm");
     $diretorio = dirname($this->arquivo);
     $tipol = MS_SHP_ARC;
     $tipos = MS_SHAPE_LINE;
     if ($para == "poligono") {
         $tipol = MS_SHP_POLYGON;
         $tipos = MS_SHAPE_POLYGON;
     }
     $novonomelayer = nomeRandomico();
     $nomeshp = $diretorio . "/" . $novonomelayer;
     $items = pegaItens($this->layer);
     // cria o dbf
     $def = array();
     foreach ($items as $ni) {
         $temp = strtoupper($ni);
         $def[] = array($temp, "C", "254");
     }
     //para manipular dbf
     if ($this->dbaseExiste == false) {
         include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
         $db = xbase_create($nomeshp . ".dbf", $def);
     } else {
         $db = dbase_create($nomeshp . ".dbf", $def);
     }
     $dbname = $nomeshp . ".dbf";
     $reg = array();
     $novoshpf = ms_newShapefileObj($nomeshp . ".shp", $tipol);
     $this->layer->open();
     $prjMapa = $this->mapa->getProjection();
     $prjTema = $this->layer->getProjection();
     $ret = $this->mapa->extent;
     if ($prjTema != "" && $prjMapa != $prjTema) {
         $projOutObj = ms_newprojectionobj($prjTema);
         $projInObj = ms_newprojectionobj($prjMapa);
         $ret->project($projInObj, $projOutObj);
     }
     $this->layer->whichShapes($ret);
     $linha = ms_newLineObj();
     $pponto = "";
     $pontos = array();
     while ($shape = $this->layer->nextShape()) {
         $lin = $shape->line(0);
         $pt = $lin->point(0);
         if ($pponto == "") {
             $pponto = $pt;
         }
         if ($prjTema != "" && $prjMapa != $prjTema) {
             $pt->project($projInObj, $projOutObj);
         }
         $pontos[] = $pt->x;
         $pontos[] = $pt->y;
     }
     $pontos = implode(" ", $pontos);
     $pontos = xy2wkt($pontos);
     if ($para == "poligono") {
         $shape = ms_shapeObjFromWkt($pontos["poligono"]);
     } else {
         $shape = ms_shapeObjFromWkt($pontos["linha"]);
     }
     foreach ($items as $ni) {
         $reg[] = "-";
     }
     $novoshpf->addShape($shape);
     if ($this->dbaseExiste == false) {
         xbase_add_record($db, $reg);
         xbase_close($db);
     } else {
         dbase_add_record($db, $reg);
         dbase_close($db);
     }
     $this->layer->close();
     //cria o novo layer
     $layer = criaLayer($this->mapa, MS_LAYER_LINE, MS_DEFAULT, "", $metaClasse = "SIM");
     $layer->set("data", $nomeshp);
     $layer->setmetadata("tema", $novonomelayer . " (linear)");
     $layer->setmetadata("download", "sim");
     $layer->setmetadata("temalocal", "sim");
     $classe = $layer->getclass(0);
     $estilo = $classe->getstyle(0);
     $estilo->set("symbolname", "linha");
     if ($para == "poligono") {
         $layer->set("type", MS_LAYER_POLYGON);
         $layer->set("opacity", "50");
         $layer->setmetadata("tema", $novonomelayer . " (poligonal)");
     }
     return "ok";
 }
Ejemplo n.º 10
0
 public function generate($idp, $nama_kolom, $nama_menurut, $nama_di, $tipe_data, $nama_kabupaten, $pilihwarna, $kelasLegend, $idpulau, $modelegendcanggih, $datalegendcanggih)
 {
     $connection = Yii::$app->db;
     //$idp ="data_timese_prov";
     // $nama_kolom="2011";
     //$nama_menurut="Provinsi";
     //$nama_di="Indonesia";
     //$tipe_data="3";
     $namaprovkabkec = "nama_prov";
     $datam[][] = array();
     $i = 0;
     $jumlahdata = 0;
     $layer = 'id_prov';
     $layerdatabase = 's00prov';
     $query = '';
     $where = "";
     if ($nama_menurut == "Kabupaten") {
         $namaprovkabkec = "nama_kab";
         $layer = 'id_kab';
         $layerdatabase = 's00kab';
         $where = "WHERE {$nama_di} = {$idp}.id_prov";
     }
     if ($nama_menurut == "Kecamatan") {
         $namaprovkabkec = "nama_kec";
         $layer = 'id_kec';
         $layerdatabase = 's33kec';
         if ($nama_kabupaten == "seluruhKabupaten") {
             $where = "WHERE {$nama_di} = {$idp}.id_prov";
         } else {
             $where = "WHERE {$nama_kabupaten} = {$idp}.id_kab";
         }
     }
     $wherepulau = '';
     if ($idpulau != 0) {
         $wherepulau = "WHERE {$idp}.{$layer}::varchar LIKE '" . $idpulau . "%'";
     }
     $kelas = $kelasLegend;
     $json_provinsi = array("status" => "OK", "jumlah" => $kelas, "jumlah2" => 0, "results" => array(), "results2" => array());
     if ($tipe_data == "1" | $tipe_data == "3") {
         if ($nama_di == "Indonesia" | $idpulau != 0) {
             $query = "SELECT {$idp}.{$layer}, {$namaprovkabkec}, SUM(" . $nama_kolom . ") FROM " . $idp . " INNER JOIN   {$layerdatabase}\nON {$idp}.{$layer}::varchar={$layerdatabase}.{$layer}::varchar  " . $wherepulau . "GROUP BY {$idp}.{$layer} ,{$namaprovkabkec}  ORDER BY {$idp}.{$layer} ";
             //$query = "SELECT s00kab.id_prov, s00kab.nama_prov FROM s00kab INNER JOIN   $namaTabel
             //ON $namaTabel.id_kab::varchar=s00kab.id_kab::varchar GROUP BY s00kab.id_prov,s00kab.nama_prov ORDER BY s00kab.nama_prov DESC;";
         } else {
             $query = "SELECT {$idp}.{$layer}, SUM(" . $nama_kolom . "), {$namaprovkabkec} FROM " . $idp . " INNER JOIN   {$layerdatabase} ON {$idp}.{$layer}::varchar={$layerdatabase}.{$layer}::varchar " . $where . "  GROUP BY {$idp}.{$layer}, " . $namaprovkabkec;
         }
         $command = $connection->createCommand($query);
         $dataReader = $command->query();
         $rows = $dataReader->readAll();
         $json_provinsi["jumlah2"] = $dataReader->rowCount;
         foreach ($rows as $myrow) {
             //echo"hjj";
             $json_provinsi["results2"][] = array("nama" => $myrow[$namaprovkabkec], "jumlah" => $myrow["sum"]);
             $datam[$i][$layer] = $myrow[$layer];
             $datam[$i][$nama_kolom] = $myrow["sum"];
             $i++;
         }
         if ($modelegendcanggih == "tidak") {
             $nilaimaks = 0;
             for ($x = 0; $x < $i; $x++) {
                 if ($nilaimaks < $datam[$x][$nama_kolom]) {
                     $nilaimaks = $datam[$x][$nama_kolom];
                 }
             }
             $batasbawah = $nilaimaks / $kelas;
             $warnalgnd = array();
             $warnalgnd = self::_warnaLegenda($pilihwarna);
             for ($x = 0; $x < $i; $x++) {
                 for ($k = 0; $k < $kelas; $k++) {
                     if ($batasbawah * (1 + $k) >= $datam[$x][$nama_kolom]) {
                         $datam[$x]['R'] = $warnalgnd[$k]["R"];
                         $datam[$x]['G'] = $warnalgnd[$k]["G"];
                         $datam[$x]['B'] = $warnalgnd[$k]["B"];
                         break;
                         //echo"atas Sendiri".$datam[$x][$layer]."".$datam[$x][$nama_kolom]. "knp <br/>";
                     }
                 }
             }
             for ($k = $kelas; $k > 0; $k--) {
                 $json_provinsi["results"][] = array("batas_bawah" => $batasbawah * (x + ($k - 1)) . " - " . $batasbawah * (x + $k), "R" => $warnalgnd[$k - 1]["R"], "G" => $warnalgnd[$k - 1]["G"], "B" => $warnalgnd[$k - 1]["B"]);
             }
         } else {
             if ($modelegendcanggih == "ya") {
                 $datalegendcanggiharray = [];
                 $firstDimension = explode('|', $datalegendcanggih);
                 // Divide by | symbol
                 foreach ($firstDimension as $temp) {
                     // Take each result of division and explode it by , symbol and save to result
                     $datalegendcanggiharray[] = explode(',', $temp);
                 }
                 $warnalgnd = array();
                 $warnalgnd = self::_warnaLegenda($pilihwarna);
                 for ($x = 0; $x < $i; $x++) {
                     for ($k = 0; $k < $kelas; $k++) {
                         if ($datalegendcanggiharray[$k][0] <= $datam[$x][$nama_kolom] & $datalegendcanggiharray[$k][1] >= $datam[$x][$nama_kolom]) {
                             $datam[$x]['R'] = $warnalgnd[$k]["R"];
                             $datam[$x]['G'] = $warnalgnd[$k]["G"];
                             $datam[$x]['B'] = $warnalgnd[$k]["B"];
                             break;
                             //echo"atas Sendiri".$datam[$x][$layer]."".$datam[$x][$nama_kolom]. "knp <br/>";
                         } else {
                             if ($datalegendcanggiharray[$kelas - 1][2] != "kosong") {
                                 $datam[$x]['R'] = $warnalgnd[$kelas - 1]["R"];
                                 $datam[$x]['G'] = $warnalgnd[$kelas - 1]["G"];
                                 $datam[$x]['B'] = $warnalgnd[$kelas - 1]["B"];
                             }
                         }
                     }
                 }
                 for ($k = 0; $k < $kelas - 1; $k++) {
                     $json_provinsi["results"][] = array("batas_bawah" => $datalegendcanggiharray[$k][2], "R" => $warnalgnd[$k]["R"], "G" => $warnalgnd[$k]["G"], "B" => $warnalgnd[$k]["B"]);
                 }
                 if ($datalegendcanggiharray[$kelas - 1][2] != "kosong") {
                     $json_provinsi["results"][] = array("batas_bawah" => $datalegendcanggiharray[$kelas - 1][2], "R" => $warnalgnd[$kelas - 1]["R"], "G" => $warnalgnd[$kelas - 1]["G"], "B" => $warnalgnd[$kelas - 1]["B"]);
                 } else {
                     $json_provinsi["jumlah"] = $kelas - 1;
                 }
             }
         }
         echo json_encode($json_provinsi, JSON_PRETTY_PRINT);
     }
     if ($tipe_data == "2") {
         $query = "SELECT {$nama_kolom} FROM " . $idp . " {$wherepulau} GROUP BY " . $nama_kolom;
         $command = $connection->createCommand($query);
         $dataReader = $command->query();
         $rows = $dataReader->readAll();
         $num_rows = $dataReader->rowCount;
         $json_provinsi = array("status" => "OK", "jumlah" => $num_rows, "jumlah2" => 0, "results" => array(), "results2" => array());
         //  $query = "SELECT $layer, $nama_kolom FROM ".$idp;
         // $command=$connection->createCommand($query);
         //    $dataReader=$command->query();
         // $rows=$dataReader->readAll();
         $i = 0;
         foreach ($rows as $myrow) {
             //$datam[$i][$layer] =$myrow[$layer];
             $json_provinsi["results"][] = array("batas_bawah" => $myrow[$nama_kolom], "R" => 255 - ($i + 1) * 70, "G" => 141 - ($i + 1) * 20, "B" => 100 - ($i + 1) * 25);
             $i++;
         }
         $sama = 0;
         $query = "SELECT {$namaprovkabkec},{$idp}.{$layer}, {$nama_kolom} FROM " . $idp . " INNER JOIN   {$layerdatabase} ON {$idp}.{$layer}::varchar={$layerdatabase}.{$layer}::varchar {$wherepulau} GROUP BY {$nama_kolom} ,{$namaprovkabkec},{$idp}.{$layer} ORDER BY {$idp}.{$layer}";
         $command = $connection->createCommand($query);
         $dataReader = $command->query();
         $rows = $dataReader->readAll();
         $json_provinsi["jumlah2"] = $dataReader->rowCount;
         $i = 0;
         $w = array();
         foreach ($rows as $myrow) {
             //$datam[$i][$layer] =$myrow[$layer];
             $w[$i] = $myrow[$nama_kolom];
             $json_provinsi["results2"][] = array("nama" => $myrow[$namaprovkabkec], "jumlah" => $myrow[$nama_kolom]);
             for ($x = 0; $x < $num_rows; $x++) {
                 if ($w[$i] == $json_provinsi["results"][$x]["batas_bawah"]) {
                     $datam[$i][$layer] = $myrow[$layer];
                     $datam[$i]['R'] = $json_provinsi["results"][$x]["R"];
                     $datam[$i]['G'] = $json_provinsi["results"][$x]["G"];
                     $datam[$i]['B'] = $json_provinsi["results"][$x]["B"];
                 }
             }
             $i++;
         }
         echo json_encode($json_provinsi, JSON_PRETTY_PRINT);
         //$datam[$i]['R']=$json_provinsi["results"][$x]["R"];
         // $datam[$i]['G']=$json_provinsi["results"][$x]["G"];
         //$datam[$i]['B']=$json_provinsi["results"][$x]["B"];
     }
     $objMap = ms_NewMapObj("");
     $objMap->Set("name", "Kab");
     $objMap->setSize(384, 204);
     $objMap->setExtent(92.59, -19.443566666, 142.88, 14.1298);
     $objMap->Set("units", MS_DD);
     // derajat
     $objMap->imagecolor->SetRGB(210, 233, 255);
     //$objMap->SetSymbolSet ("C:\ms4w\apps\latihan\simbol\simbol.sym");
     $objMap->SetFontSet("C:/ms4w/apps/latihan/mapsederhana/font/font.dat");
     //$objMap->outputformat->set("transparent",1);
     //  $objMap->outputformat->set("imagemode", MS_GD_ALPHA);
     $objMap->setProjection("init=epsg:4326");
     $projInObj = ms_newprojectionobj("init=epsg:4326");
     // objek web di mapfile
     $objMap->web->set("imagepath", "C:/ms4w/Apache/htdocs/temp/");
     $objMap->web->set("imageurl", "/temp/");
     $objMap->web->set("template", "C:/ms4w/apps/latihan/html/tmplb.html");
     $objMap->setMetaData("ows_title", "Peta wilayah Indonesia");
     $objMap->setMetaData("ows_onlineresource", "http://localhost/wms?");
     $objMap->setMetaData("wms_srs", "EPSG:4326 EPSG:3857");
     $objMap->setMetaData("wms_abstract", "WMS");
     $objMap->setMetaData("wms_enable_request", "*");
     $objMap->setMetaData("wms_encoding", "utf-8");
     $objMap->setMetaData("wfs_getfeature_formatlist", "json");
     //
     // objek layer
     $objLayerJbr = ms_newLayerObj($objMap);
     $objLayerJbr->set("name", "provinsi");
     $objLayerJbr->setConnectionType(MS_POSTGIS);
     $dbpgsql = Yii::$app->message->dbpgsql();
     $objLayerJbr->set('connection', $dbpgsql);
     $objLayerJbr->set('data', "geom from (select geom ,gid," . $layer . "," . $namaprovkabkec . " from " . $layerdatabase . " ) as subquery using unique gid using srid=43266");
     $objLayerJbr->set("classitem", $layer);
     $objLayerJbr->set("type", MS_LAYER_POLYGON);
     $objLayerJbr->set("status", MS_ON);
     $objLayerJbr->set("opacity", 85);
     // $objLayerJbr->set ("labelitem",$namaprovkabkec); // label layer
     //$objLayerJbr->set("labelcache",MS_ON);// field kelas
     //$objLayerJbr->setprocessing("LABEL_NO_CLIP=on");
     //
     // objek class & style jabar
     for ($x = 0; $x < $i; $x++) {
         $objClassJbr[] = ms_newClassObj($objLayerJbr);
         // echo "<br/>".$datam[$x][$layer]."    >>".$datam[$x]['R']." ".$datam[$x]['G']." ".$datam[$x]['B'];
         $objClassJbr[$x]->SetExpression($datam[$x][$layer]);
         $objClassJbr[$x]->Set("name", "batas_prov");
         // kodeprop=1
         $objStyleJbr[] = ms_newStyleObj($objClassJbr[$x]);
         //echo $datam[$x]['R']." ".$datam[$x]['G']." ".$datam[$x]['B']."<br/>";
         $objStyleJbr[$x]->color->setRGB($datam[$x]['R'], $datam[$x]['G'], $datam[$x]['B']);
         //echo "warna : ".$datam[$x][$layer]." ".$datam[$x]['R']." ".$datam[$x]['G']." ".$datam[$x]['B']."<br/>";
         $objStyleJbr[$x]->outlinecolor->SetRGB(0, 0, 0);
         $objClassJbr[$x]->label->Set("font", "arialbold");
         $objClassJbr[$x]->label->Set("type", MS_TRUETYPE);
         $objClassJbr[$x]->label->Set("encoding", "utf-8");
         $objClassJbr[$x]->label->Set("size", 8);
         $objClassJbr[$x]->label->Set("buffer", 7);
         $objClassJbr[$x]->label->Set("partials", TRUE);
         $objClassJbr[$x]->label->Set("align", center);
         $objClassJbr[$x]->label->Set("position", MS_CC);
         $objClassJbr[$x]->label->color->SetRGB(3, 3, 3);
         $objClassJbr[$x]->label->outlinecolor->SetRGB(242, 236, 230);
         //
     }
     $objLayerJbr->setProjection("init=epsg:4326");
     //
     $clonefullpath = Yii::$app->message->clonefullpath();
     $objMap->save($clonefullpath);
     //
 }
Ejemplo n.º 11
0
function calculaarea($geo)
{
    global $postgis_con;
    $v = versao();
    if ($v["principal"] < 5 && $postgis_con == "") {
        return "erro. &Eacute; necess&aacute;ria uma vers&atilde;o maior que 5.0 do Mapserver.";
    }
    $g = $geo->towkt();
    $shape = ms_shapeObjFromWkt($g);
    $rect = $shape->bounds;
    $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs");
    $projOutObj = ms_newprojectionobj("proj=laea,lat_0=" . $rect->miny . ",lon_0=" . $rect->minx . ",x_0=500000,y_0=10000000,ellps=GRS67,units=m,no_defs");
    $shape->project($projInObj, $projOutObj);
    $s = $shape->towkt();
    $shape = ms_shapeObjFromWkt($s);
    $area = $shape->getArea();
    return $area / 10000;
}
Ejemplo n.º 12
0
function pegaValoresM($mapa, $layer, $itens, $exclui = "nulo", $selecionados = "nao", $chaves = false, $centroide = false)
{
    $versao = versao();
    $versao = $versao["principal"];
    $prjMapa = $mapa->getProjection();
    $prjTema = $layer->getProjection();
    $layer->set("template", "none.htm");
    $layer->setfilter("");
    $indicesel = array();
    //pega os valores dos indices dos elementos selecionados para comparacao posterior
    if ($selecionados == "sim") {
        $sopen = $layer->open();
        if ($sopen == MS_FAILURE) {
            return "erro";
        }
        $res_count = $layer->getNumresults();
        for ($i = 0; $i < $res_count; ++$i) {
            $result = $layer->getResult($i);
            $indicesel[] = $result->shapeindex;
        }
        $layer->close();
    }
    $valores = array();
    $nclasses = $layer->numclasses;
    if (@$layer->queryByrect($mapa->extent) == MS_SUCCESS) {
        //$layer->draw();
        $sopen = $layer->open();
        if ($sopen == MS_FAILURE) {
            return "erro";
        }
        $res_count = $layer->getNumresults();
        //echo $res_count;echo "\n";
        for ($i = 0; $i < $res_count; ++$i) {
            if ($versao >= 6) {
                $shape = $layer->getShape($layer->getResult($i));
                $shp_index = $shape->index;
            } else {
                $result = $layer->getResult($i);
                $shp_index = $result->shapeindex;
                $shape = $layer->getfeature($shp_index, -1);
            }
            if ($selecionados == "sim" && array_search($shp_index, $indicesel) === FALSE) {
                continue;
            }
            $considera = "sim";
            //verifica se no registro deve ser considerado
            if ($exclui != "nulo") {
                foreach ($itens as $item) {
                    if ($shape->values[$item] == $exclui) {
                        $considera = "nao";
                    }
                }
            }
            //pega os valores
            $v = array();
            if ($considera == "sim") {
                //pega os valores dos itens do registro
                foreach ($itens as $item) {
                    $vitem = $shape->values[$item];
                    if (!mb_detect_encoding($vitem, "UTF-8", true)) {
                        $vitem = mb_convert_encoding($vitem, "UTF-8", "ISO-8859-1");
                    }
                    if ($chaves == false) {
                        $v[] = $vitem;
                    } else {
                        $v[$item] = $vitem;
                    }
                }
                //pega o centroide
                //echo $i;echo "\n";
                if ($centroide == true) {
                    $c = $shape->getCentroid();
                    if ($prjTema != "" && $prjMapa != $prjTema) {
                        $projOutObj = ms_newprojectionobj($prjTema);
                        $projInObj = ms_newprojectionobj($prjMapa);
                        $c->project($projInObj, $projOutObj);
                    }
                    $v["centroide"] = "POINT(" . $c->x . " " . $c->y . ")";
                }
                //echo $i;echo "---\n";
                //pega a cor da classe onde cai o registro
                if ($nclasses > 0 && $versao >= 6) {
                    $cx = $layer->getClassIndex($shape);
                    if ($cx > -1) {
                        $classe = $layer->getclass($cx);
                        $cor = $classe->getstyle(0)->color;
                        $v["cores"] = $cor->red . " " . $cor->green . " " . $cor->blue;
                    }
                }
                if (count($v) == 1) {
                    $valores[] = $v[0];
                } else {
                    $valores[] = $v;
                }
            }
        }
        $layer->close();
    }
    return $valores;
}
Ejemplo n.º 13
0
 function extensaoShape($shape)
 {
     if (!$this->layer) {
         return "erro";
     }
     $prjMapa = $this->mapa->getProjection();
     $prjTema = $this->layer->getProjection();
     $ret = $shape->bounds;
     //
     //verifica se o retangulo est&aacute; ou n&atilde;o em coordenadas geogr&aacute;ficas
     //
     if ($ret->minx > 180 || $ret->minx < -180) {
         //reprojeta o retangulo
         if ($prjTema != "" && $prjMapa != $prjTema) {
             $projInObj = ms_newprojectionobj($prjTema);
             $projOutObj = ms_newprojectionobj($prjMapa);
             $ret->project($projInObj, $projOutObj);
         }
     }
     $ext = $ret->minx . " " . $ret->miny . " " . $ret->maxx . " " . $ret->maxy;
     if ($shape->type == MS_SHP_POINT || $shape->type == 0) {
         $minx = $ret->minx;
         $minx = $minx - 0.03;
         $maxx = $ret->maxx;
         $maxx = $maxx + 0.03;
         $miny = $ret->miny;
         $miny = $miny - 0.03;
         $maxy = $ret->maxy;
         $maxy = $maxy + 0.03;
         $ext = $minx . " " . $miny . " " . $maxx . " " . $maxy;
     }
     return $ext;
 }
Ejemplo n.º 14
0
function autoClasses(&$nlayer, $mapa, $locaplic = null)
{
    $postgis_mapa = "";
    $substituicon = "nao";
    include dirname(__FILE__) . "/../ms_configura.php";
    if ($nlayer->connectiontype == MS_POSTGIS) {
        if ($nlayer->connection == " ") {
            $nlayer->set("connection", $postgis_mapa);
            $substituicon = "sim";
        }
    }
    //
    //gera classes automaticamente (temas vetoriais)
    if ($nlayer->getmetadata("classesitem") != "") {
        $itemnome = $nlayer->getmetadata("classesnome");
        $itemid = $nlayer->getmetadata("classesitem");
        $itemcor = $nlayer->getmetadata("classescor");
        $itemsimbolo = $nlayer->getmetadata("classesimbolo");
        $itemtamanho = $nlayer->getmetadata("classestamanho");
        $classeoriginal = $nlayer->getclass(0);
        //
        //pega a extensao geografica que devera ser utilizada
        //
        $prjMapa = $mapa->getProjection();
        $prjTema = $nlayer->getProjection();
        $ret = $nlayer->getmetadata("extensao");
        if ($ret == "") {
            $ret = $nlayer->getextent();
            //reprojeta o retangulo
            if ($prjTema != "" && $prjMapa != $prjTema) {
                $projInObj = ms_newprojectionobj($prjTema);
                $projOutObj = ms_newprojectionobj($prjMapa);
                $ret->project($projInObj, $projOutObj);
            }
        } else {
            $temp = explode(" ", $ret);
            $ret = ms_newRectObj();
            $ret->setextent($temp[0], $temp[1], $temp[2], $temp[3]);
        }
        //
        $sopen = $nlayer->open();
        if ($sopen == MS_FAILURE) {
            return "erro";
        }
        $status = $nlayer->whichShapes($ret);
        $parametrosClasses = array();
        if ($status == 0) {
            while ($shape = $nlayer->nextShape()) {
                $id = trim($shape->values[$itemid]);
                if (!$parametrosClasses[$id]) {
                    $nome = "";
                    if ($itemnome != "") {
                        $nome = trim($shape->values[$itemnome]);
                    }
                    $cor = "";
                    if ($itemcor != "") {
                        $cor = explode(",", trim($shape->values[$itemcor]));
                    }
                    if (count($cor) != 3) {
                        $cor = explode(" ", trim($shape->values[$itemcor]));
                    }
                    $tamanho = "";
                    if ($itemtamanho != "") {
                        $tamanho = trim($shape->values[$itemtamanho]);
                    }
                    $simbolo = "";
                    if ($itemsimbolo != "") {
                        $simbolo = trim($shape->values[$itemsimbolo]);
                    }
                    $parametrosClasses[$id] = array("nome" => $nome, "cor" => $cor, "tamanho" => $tamanho, "simbolo" => $simbolo);
                }
            }
            $fechou = $nlayer->close();
            //echo "<pre>";var_dump($parametrosClasses);
            if (count($parametrosClasses) > 0) {
                $ids = array_keys($parametrosClasses);
                for ($i = 0; $i < count($parametrosClasses); ++$i) {
                    $p = $parametrosClasses[$ids[$i]];
                    //echo "<pre>";var_dump($p);
                    $nclasse = ms_newClassObj($nlayer, $classeoriginal);
                    if ($p["nome"] != "") {
                        $nclasse->set("name", $p["nome"]);
                    }
                    $estilo = $nclasse->getstyle(0);
                    if ($p["cor"] != "") {
                        $cor = $p["cor"];
                        $ncor = $estilo->color;
                        if ($ncor == "") {
                            $ncor = $estilo->outlinecolor;
                        }
                        $ncor->setrgb($cor[0], $cor[1], $cor[2]);
                    }
                    if ($p["tamanho"] != "") {
                        $estilo->set("size", $p["tamanho"]);
                    }
                    if ($p["simbolo"] != "") {
                        $estilo->set("symbolname", $p["simbolo"]);
                    }
                    $strE = "('[" . $itemid . "]'eq'" . $ids[$i] . "')";
                    $nclasse->setexpression($strE);
                }
                $classeoriginal->set("status", MS_DELETE);
            }
        }
        if ($substituicon == "sim") {
            $nlayer->set("connection", " ");
        }
    }
    $pf = $nlayer->getmetadata("palletefile");
    if ($pf != "") {
        if (!file_exists($pf)) {
            return;
        }
        $ps = $nlayer->getmetadata("palletesteps");
        if ($ps == "") {
            $ps = 8;
        }
        //
        //pega os valores do arquivo
        //
        $rules = array();
        $abre = fopen($pf, "r");
        $paletteRules = array();
        while (!feof($abre)) {
            $line = trim(fgets($abre));
            $pos = strpos($line, "#");
            if ($pos === false || $pos > 0) {
                $paletteEntry = explode(" ", $line);
                $rules[] = array("v0" => $paletteEntry[0], "v1" => $paletteEntry[1], "r0" => $paletteEntry[2], "g0" => $paletteEntry[3], "b0" => $paletteEntry[4], "r1" => $paletteEntry[5], "g1" => $paletteEntry[6], "b1" => $paletteEntry[7]);
            }
        }
        fclose($abre);
        foreach ($rules as $rule) {
            $delta = ceil(($rule["v1"] - $rule["v0"]) / $ps);
            $legenda = true;
            for ($value = $rule["v0"]; $value < $rule["v1"]; $value += $delta) {
                $class = ms_newClassObj($nlayer);
                $style = ms_newStyleObj($class);
                if ($legenda) {
                    $class->set(name, round($value, 0));
                    $legenda = true;
                }
                $expression = "([pixel] > " . round($value, 0) . " AND [pixel] <= " . round($value + $delta, 0) . ")";
                $class->setExpression($expression);
                $rgb = getRGBpallete($rule, $value);
                $style->color->setRGB($rgb[0], $rgb[1], $rgb[2]);
            }
        }
    }
    return;
}
Ejemplo n.º 15
0
function zoomTemaMiniatura($nomelayer, &$mapa)
{
    $layer = $mapa->getlayerbyname($nomelayer);
    if ($layer->data == "" && $layer->connection == "") {
        return;
    }
    $prjMapa = $mapa->getProjection();
    $prjTema = $layer->getProjection();
    $extatual = $mapa->extent;
    $ret = $layer->getmetadata("extensao");
    if ($layer->type > 2 && $ret == "") {
        return;
    }
    $ct = $layer->connectiontype;
    if ($ret == "" && $ct != 1) {
        return;
    }
    if ($ret == "") {
        $ret = $layer->getextent();
        //reprojeta o retangulo
        if ($prjTema != "" && $prjMapa != $prjTema) {
            $projInObj = ms_newprojectionobj($prjTema);
            $projOutObj = ms_newprojectionobj($prjMapa);
            $ret->project($projInObj, $projOutObj);
        }
        $extatual->setextent($ret->minx, $ret->miny, $ret->maxx, $ret->maxy);
    } else {
        $ret = explode(" ", $ret);
        $extatual->setextent($ret[0], $ret[1], $ret[2], $ret[3]);
    }
}
Ejemplo n.º 16
0
 /**
  * Test if layer has the same projection as map
  */
 function checkProjection()
 {
     $mapProjStr = $this->map->getProjection();
     $qLayerProjStr = $this->qLayer->getProjection();
     if ($mapProjStr && $qLayerProjStr && $mapProjStr != $qLayerProjStr) {
         $changeLayProj = 1;
         if ($_SESSION['MS_VERSION'] < 6) {
             $this->mapProjObj = ms_newprojectionobj($mapProjStr);
             $this->qLayerProjObj = ms_newprojectionobj($qLayerProjStr);
         } else {
             $this->mapProjObj = new projectionObj($mapProjStr);
             $this->qLayerProjObj = new projectionObj($qLayerProjStr);
         }
     } else {
         $changeLayProj = 0;
     }
     return $changeLayProj;
 }
Ejemplo n.º 17
0
 /**
  * Return extent of layer as array
  * @param bool $inMapProjection define if extent shall be returned in map projection 
  * @return object extent with minx, miny, maxx, maxy properties 
  */
 public function getLayerExtent($inMapProjection)
 {
     // PostgIS layers
     if ($this->layer->connectiontype == 6) {
         $data = trim($this->layer->data);
         $dataList1 = preg_split("/\\s/", $data);
         $dataList2 = preg_split("/using/i", $data);
         $geomFld = array_shift($dataList1);
         // use filter for layer extent
         $filter = trim($this->layer->getFilterString());
         if (!$filter) {
             $filter = "TRUE";
         }
         $sql = "select ST_xmin(extent) as minx, ST_ymin(extent) as miny, ST_xmax(extent) as maxx, ST_ymax(extent) as maxy  \n                    from (SELECT St_Extent({$geomFld}) as extent " . substr($dataList2[0], strlen($geomFld)) . "WHERE {$filter}) as bar";
         pm_logDebug(3, $sql, "P.MAPPER-DEBUG: pmaplayer.php/getLayerExtent() - SQL for PG layer extent");
         // load DLL on Win if required
         if (PHP_OS == "WINNT" || PHP_OS == "WIN32") {
             if (!extension_loaded('pgsql')) {
                 if (function_exists("dl")) {
                     dl('php_pgsql.dll');
                 } else {
                     error_log("P.MAPPER ERROR: This version of PHP does support the 'dl()' function. Please enable 'php_pgsql.dll' in your php.ini");
                     return false;
                 }
             }
         }
         $connString = $this->layer->connection;
         if (!($connection = pg_Connect($connString))) {
             error_log("P.MAPPER: Could not connect to database");
             error_log("P.MAPPER: PG Connection error: " . pg_last_error($connection));
             exit;
         }
         $qresult = pg_query($connection, $sql);
         if (!$qresult) {
             error_log("P.MAPPER: PG Query error for : {$query}" . pg_result_error($qresult));
         }
         $pgE = pg_fetch_object($qresult);
         $layerExt = ms_newRectObj();
         $layerExt->setExtent($pgE->minx, $pgE->miny, $pgE->maxx, $pgE->maxy);
     } else {
         $layerExt = @$this->layer->getExtent();
         // Raster layers (no extent function available, so take map extent)
         if (!$layerExt) {
             $layerExt = $this->map->extent;
         }
         pm_logDebug(3, $this->layer->type, "pmap layerInfo");
     }
     // if layer projection != map projection, reproject layer extent
     if ($inMapProjection) {
         $mapProjStr = $this->map->getProjection();
         $layerProjStr = $this->layer->getProjection();
         if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) {
             if ($_SESSION['MS_VERSION'] < 6) {
                 $mapProjObj = ms_newprojectionobj($mapProjStr);
                 $layerProjObj = ms_newprojectionobj($layerProjStr);
             } else {
                 $mapProjObj = new projectionObj($mapProjStr);
                 $layerProjObj = new projectionObj($layerProjStr);
             }
             $layerExt->project($layerProjObj, $mapProjObj);
         }
     }
     pm_logDebug(3, $layerExt, "pmap layerExt");
     return $layerExt;
 }
 flush();
 sleep(1);
 $srid = 4326;
 $escapar = "'";
 $projOutObj = "";
 $projInObj = "";
 //
 //caso o usuario tenha definido a projecao de saida, os dados devem ser projetados
 //
 if ($_POST["outsrid"] != "") {
     $mapObj->setProjection("init=epsg:" . $_POST["outsrid"]);
     $prjMapa = $mapObj->getProjection();
     $prjTema = $layer->getProjection();
     if ($prjTema != "" && $prjMapa != $prjTema) {
         $projInObj = ms_newprojectionobj($prjTema);
         $projOutObj = ms_newprojectionobj($prjMapa);
     }
 }
 for ($i = 0; $i < $numshapes; $i++) {
     $s = $layer->getShape(new resultObj($i));
     //projeta o shape se existir .prj
     if ($_FILES['i3GEOuploadprj']['tmp_name'] != "" && $projInObj != "") {
         $s->project($projInObj, $projOutObj);
         //para nao projetar com postgis
         $_POST["insrid"] = $_POST["outsrid"];
     }
     $vs = array();
     foreach ($colunas as $coluna) {
         $escape = "";
         if ($tipoColuna[$coluna] == "varchar") {
             $texto = $s->getValue($layer, $coluna);
Ejemplo n.º 19
0
 function gravaCoordenadasPt($tema, $limitepontos = "TRUE", $extendelimite, $item = "")
 {
     $prjMapa = $this->mapa->getProjection();
     $layerPt = $this->mapa->getlayerbyname($tema);
     $prjTema = $layerPt->getProjection();
     $layerPt->set("tolerance", 0);
     $layerPt->set("template", "none.htm");
     $nomefinal = nomeRandomico();
     $nomearq = $this->diretorio . "/" . $nomefinal;
     $itemspt = pegaItens($layerPt);
     $shapes = retornaShapesSelecionados($layerPt, $this->arquivo, $this->mapa);
     if (count($shapes) == 0) {
         $shapes = retornaShapesMapext($layerPt, $this->mapa);
     }
     $pontos = array();
     $pontosz = array();
     if ($prjTema != "" && $prjMapa != $prjTema) {
         $projInObj = ms_newprojectionobj($prjTema);
         $projOutObj = ms_newprojectionobj($prjMapa);
     }
     foreach ($shapes as $shape) {
         $pt = $shape->getCentroid();
         if ($prjTema != "" && $prjMapa != $prjTema) {
             $pt->project($projInObj, $projOutObj);
         }
         $pontos[] = $pt->x . "  " . $pt->y . "\n";
         $pontosx[] = $pt->x;
         $pontosy[] = $pt->y;
         if ($item != "") {
             $pontosz[] = trim($shape->values[$item]);
         }
     }
     $layerPt->close();
     // grava o arquivo com os pontos em x
     $f = fopen($nomearq . "x", "w");
     foreach ($pontosx as $pt) {
         fwrite($f, $pt . "\n");
     }
     fclose($f);
     // grava o arquivo com os pontos em y
     $f = fopen($nomearq . "y", "w");
     foreach ($pontosy as $pt) {
         fwrite($f, $pt . "\n");
     }
     fclose($f);
     // grava o arquivo com os pontos em z
     $f = fopen($nomearq . "z", "w");
     foreach ($pontosz as $pt) {
         fwrite($f, $pt . "\n");
     }
     fclose($f);
     if ($limitepontos == "TRUE") {
         $xi = min($pontosx);
         $xf = max($pontosx);
         $yi = min($pontosy);
         $yf = max($pontosy);
     } else {
         $ext = $this->mapa->extent;
         $xi = $ext->minx;
         $xf = $ext->maxx;
         $yi = $ext->miny;
         $yf = $ext->maxy;
     }
     if ($extendelimite > 0) {
         $dx = $xf - $xi;
         $dy = $yf - $yi;
         $maisx = $dx * $extendelimite / 100;
         $maisy = $dy * $extendelimite / 100;
         $xi = $xi - $maisx;
         $xf = $xf + $maisx;
         $yi = $yi - $maisy;
         $yf = $yf + $maisy;
     }
     $dimx = "c(" . $xi . "," . $xf . ")";
     $dimy = "c(" . $yi . "," . $yf . ")";
     return array("dimx" => $dimx, "dimy" => $dimy, "arqx" => $nomearq . "x", "arqy" => $nomearq . "y", "arqz" => $nomearq . "z", "prefixoarquivo" => $nomearq);
 }
Ejemplo n.º 20
0
 /**
  * EXECUTE QUERY
  */
 public function q_execMapQuery()
 {
     //--------------------------------
     // Initialize tolerance to 0
     //--------------------------------
     $msLayers = array();
     // query in specified groups only:
     if (isset($_REQUEST['groups']) && $_REQUEST['groups']) {
         $msLayers = getLayersByGroupOrLayerName($this->map, $_REQUEST['groups']);
         // all groups:
     } else {
         for ($i = 0; $i < $this->map->numlayers; $i++) {
             $msLayers[] = $this->map->getLayer($i);
         }
     }
     foreach ($msLayers as $msLayer) {
         // change tolerance only for buffer zone search.
         if ($this->queryType == 'object') {
             $msLayer->set('tolerance', 0);
         }
     }
     // Modified by Thomas RAFFIN (SIRAP)
     // to test (substitution)
     // query by point
     // Modified by Thomas RAFFIN (SIRAP)
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     $oldDatas = array();
     for ($i = 0; $i < $this->map->numlayers; $i++) {
         $qLayer = $this->map->getLayer($i);
         $layerName = $qLayer->name;
         if ($qLayer->getMetaData('PM_RESULT_DATASUBSTITION') != '') {
             $oldDatas[$layerName] = $qLayer->data;
             $qLayer->set('data', $qLayer->getMetaData('PM_RESULT_DATASUBSTITION'));
         }
     }
     // few lines from incphp/query/query.php
     // Patch from Alessandro Pasotti for fixing problems with result returned
     $this->map->setSize($this->mapwidth, $this->mapheight);
     // Set $this->map->extent to values of current map extent
     // otherwise values of TOLERANCE in map file are not interpreted correctly
     $this->map->setExtent($this->GEOEXT['minx'], $this->GEOEXT['miny'], $this->GEOEXT['maxx'], $this->GEOEXT['maxy']);
     $this->map->preparequery();
     if ($this->queryType == 'object') {
         if (isset($_SESSION['pluginsConfig']['graphicalqueries']) && isset($_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'])) {
             $bufferOnlyWithScale = $_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'] == 1;
         } else {
             $bufferOnlyWithScale = true;
         }
         if (!$bufferOnlyWithScale) {
             //				PMCommon::setGroups($this->map, $this->querygroups, $this->scale, 0, 1);
             PMCommon::setGroups($this->map, $this->querygroups, 0, 0, 1);
         }
         // Search selected object
         $jsonPMResult = $_SESSION['JSON_Results'];
         // "[...]" ou "{...}"
         $PMResult = json_decode($jsonPMResult);
         // array ou class
         if ($PMResult) {
             $objUnion = false;
             // List layer of selected object
             $layersWithResult = $PMResult[0];
             // be carreful : 0.000000001 is too small !!
             $smallBuffer = 1.0E-8;
             $mapProjStr = $this->map->getProjection();
             if ($_SESSION['MS_VERSION'] < 6) {
                 $mapProjObj = ms_newprojectionobj($mapProjStr);
             } else {
                 $mapProjObj = new projectionObj($mapProjStr);
             }
             // Loop on layers
             $layerName = '';
             foreach ($layersWithResult as $layerWithResult) {
                 $objUnionLayer = false;
                 // init layer to close the last open one
                 $layer = false;
                 $layerProjObj = false;
                 // Loop on layer objects
                 foreach ($layerWithResult->values as $selectedObject) {
                     // layer name
                     $currentLayerName = $selectedObject[0]->shplink[0];
                     if ($currentLayerName != $layerName) {
                         if ($layer) {
                             $layer->close();
                         }
                         $layerName = $currentLayerName;
                         $layer = $this->map->getLayerByName($layerName);
                         $layerProjObj = false;
                         $layerProjStr = $layer->getProjection();
                         if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) {
                             if ($_SESSION['MS_VERSION'] < 6) {
                                 $layerProjObj = ms_newprojectionobj($layerProjStr);
                             } else {
                                 $layerProjObj = new projectionObj($layerProjStr);
                             }
                         }
                         $layer->open();
                     }
                     $shpIndex = $selectedObject[0]->shplink[1];
                     // Retrieve shape by its index.
                     $objShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $layer, null, $shpIndex, -1);
                     // changed for compatibility with PG layers and MS >= 5.6
                     // reproject
                     if ($layerProjObj) {
                         $objShape->project($layerProjObj, $mapProjObj);
                     }
                     // Union of the shapes
                     if ($objUnionLayer) {
                         $objUnionLayer = $objShape->union($objUnionLayer);
                     } else {
                         $objUnionLayer = $objShape;
                     }
                 }
                 // End foreach : Loop of the layer
                 // close layer if exists
                 if ($layer) {
                     $layer->close();
                 }
                 if ($objUnionLayer) {
                     // Line : Buffer to convert Line or Point to Polygon
                     if ($objUnionLayer->type == MS_SHAPE_LINE && isset($_REQUEST['select_buffer']) && $_REQUEST['select_buffer'] > 0 || $objUnionLayer->type == MS_SHAPE_POINT) {
                         $objUnionLayer = $objUnionLayer->buffer($smallBuffer);
                         // if polygon -> the outline is removed to not select contiguous objects
                     } else {
                         if ($objUnionLayer->type == MS_SHAPE_POLYGON && !isset($_REQUEST['select_buffer'])) {
                             $objBoundary = $objUnionLayer->boundary();
                             $objBoundary = $objBoundary->buffer($smallBuffer);
                             $objUnionLayer = $objUnionLayer->difference($objBoundary);
                         }
                     }
                 }
                 if ($objUnionLayer) {
                     if ($objUnion) {
                         $objUnion = $objUnion->union($objUnionLayer);
                     } else {
                         $objUnion = $objUnionLayer;
                     }
                 }
                 // End if($objUnionLayer)
             }
             // End foreach : loop of layers
             // Buffer -> Buffer zone
             if (isset($_REQUEST['select_buffer'])) {
                 if ($objUnion) {
                     $objUnion = $objUnion->buffer($_REQUEST['select_buffer']);
                     unset($_REQUEST['select_buffer']);
                 }
             }
             if ($objUnion) {
                 // Query
                 @$this->map->queryByShape($objUnion);
             }
         }
         // Query by point
     } else {
         if ($this->queryType == 'point') {
             $tmpPoint = ms_newPointObj();
             $tmpPoint->setXYZ($_REQUEST['select_pointX'], $_REQUEST['select_pointY'], 0);
             if (isset($_REQUEST['select_buffer'])) {
                 @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $_REQUEST['select_buffer']);
             } else {
                 @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, -1);
             }
             PMCommon::freeMsObj($tmpPoint);
             // query by Shape
         } else {
             if ($this->queryType == 'polygon') {
                 //'shape')
                 $poly = $_REQUEST['select_poly'];
                 $tmpLine = ms_newLineObj();
                 $tmpPoly = explode(',', $poly);
                 foreach ($tmpPoly as $point) {
                     $tmpTab = explode(' ', $point);
                     $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                 }
                 $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON);
                 $objPoly->add($tmpLine);
                 // Buffer -> Buffer zone
                 if (isset($_REQUEST['select_buffer'])) {
                     $objPoly = $objPoly->buffer($_REQUEST['select_buffer']);
                     unset($_REQUEST['select_buffer']);
                 }
                 @$this->map->queryByShape($objPoly);
                 PMCommon::freeMsObj($tmpLine);
                 PMCommon::freeMsObj($objPoly);
                 // query by PolyLine
             } else {
                 if ($this->queryType == 'line') {
                     $poly = $_REQUEST['select_line'];
                     $tmpLine = ms_newLineObj();
                     $tmpPoly = explode(',', $poly);
                     foreach ($tmpPoly as $point) {
                         $tmpTab = explode(' ', $point);
                         $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                     }
                     // Reduce the polygon to a polyline
                     for ($i = count($tmpPoly) - 1; $i >= 0; $i--) {
                         $tmpTab = explode(' ', $tmpPoly[$i]);
                         $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                     }
                     $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON);
                     $objPoly->add($tmpLine);
                     // Buffer -> Buffer zone
                     if (isset($_REQUEST['select_buffer'])) {
                         $bufferLocal = $_REQUEST['select_buffer'];
                         if ($bufferLocal < 0) {
                             $bufferLocal = 0;
                         }
                         $objPoly = $objPoly->buffer($bufferLocal);
                         unset($_REQUEST['select_buffer']);
                     }
                     @$this->map->queryByShape($objPoly);
                     PMCommon::freeMsObj($tmpLine);
                     PMCommon::freeMsObj($objPoly);
                     // query by circle
                 } else {
                     if ($this->queryType == 'circle') {
                         $point = $_REQUEST['select_point'];
                         $radius = $_REQUEST['select_radius'];
                         $tmpPoint = ms_newPointObj();
                         $tmpTab = explode(' ', $point);
                         $tmpPoint->setXYZ($tmpTab[0], $tmpTab[1], 0);
                         if (isset($_REQUEST['select_buffer'])) {
                             @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius + $_REQUEST['select_buffer']);
                         } else {
                             @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius);
                         }
                         PMCommon::freeMsObj($tmpPoint);
                     }
                 }
             }
         }
     }
     // Modified by Thomas RAFFIN (SIRAP)
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     // reset data tag
     foreach ($oldDatas as $qLayer => $oldData) {
         $qLayer = $this->map->getLayerByName($qLayer);
         $qLayer->set('data', $oldData);
     }
 }
Ejemplo n.º 21
0
function projetaExt($map_file, $ext, $separador = " ")
{
    $ext = str_replace($separador, " ", $ext);
    $extA = explode(" ", $ext);
    $mapa = ms_newMapObj($map_file);
    $ponto = false;
    if ($extA[0] < 180 && $extA[0] > -180) {
        if (count($extA) == 2) {
            $ponto = true;
            $extA[] = $extA[0] + 1;
            $extA[] = $extA[1] + 1;
        }
        $rect = ms_newRectObj();
        $rect->setextent($extA[0], $extA[1], $extA[2], $extA[3]);
        $prjMapa = $mapa->getProjection();
        $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs");
        $projOutObj = ms_newprojectionobj($prjMapa);
        $rect->project($projInObj, $projOutObj);
        if ($ponto == false) {
            $ext = $rect->minx . " " . $rect->miny . " " . $rect->maxx . " " . $rect->maxy;
        } else {
            $ext = $rect->minx . " " . $rect->miny;
        }
    }
    $ext = str_replace(" ", $separador, $ext);
    return $ext;
}
Ejemplo n.º 22
0
 /**
  * Check if layer has same projection as map
  */
 public static function checkProjection($map, $chkLayer)
 {
     $mapProjStr = trim($map->getProjection());
     $xyLayerProjStr = trim($chkLayer->getProjection());
     //error_log("$mapProjStr \n $xyLayerProjStr");
     if ($mapProjStr && $xyLayerProjStr && $mapProjStr != $xyLayerProjStr) {
         if ($_SESSION['MS_VERSION'] < 6) {
             $changeLayProj['mapProj'] = ms_newprojectionobj($mapProjStr);
             $changeLayProj['layProj'] = ms_newprojectionobj($xyLayerProjStr);
         } else {
             $changeLayProj['mapProj'] = new projectionObj($mapProjStr);
             $changeLayProj['layProj'] = new projectionObj($xyLayerProjStr);
         }
     } else {
         $changeLayProj = false;
     }
     return $changeLayProj;
 }
Ejemplo n.º 23
0
 public static function calculateExtent($map, $groups, $applyMapExtentIfNull = false, $addBuffer = false)
 {
     $mapExtent = ms_newrectObj();
     $layers = getLayersByGroupOrLayerName($map, $groups);
     foreach ($layers as $layer) {
         $layerExtent = false;
         if ($layer) {
             if ($layer->connectiontype == MS_POSTGIS || $layer->connectiontype == MS_ORACLESPATIAL) {
                 //get dns string containing : type of database, user name, password, host and database.
                 $dsn = PluginsMapUtils::getDSNConnection($layer);
                 if ($dsn) {
                     // code from mapserver mailing list (by Armin Burger):
                     // get table and filter :
                     $data = PluginsMapUtils::getQueryParamsFromDataString($layer, false, false);
                     $mapLayerFilter = $data['mapLayerFilter'];
                     $fromTable = $data['fromTable'];
                     $geomFld = $data['geomFld'];
                     $sql = 'SELECT ST_xmin(extent) AS minx, ST_ymin(extent) AS miny, ST_xmax(extent) AS maxx, ST_ymax(extent) AS maxy ';
                     $sql .= "FROM (SELECT St_Extent({$geomFld}) AS extent FROM {$fromTable} ";
                     $sql .= ($mapLayerFilter ? "WHERE {$mapLayerFilter}" : '') . ' ';
                     $sql .= ') AS bar';
                     $sql .= ' WHERE extent IS NOT NULL';
                     pm_logDebug(4, "calculateExtent - sql:{$sql}");
                     // DB:
                     require_once dirname(__FILE__) . '/easyMDB2.inc.php';
                     $edb = new Easy_MDB2();
                     $edb->setDSN($dsn);
                     $edb->start();
                     $qresultE = $edb->selectByQuery($sql, '');
                     $resValues = $qresultE['values'][0];
                     if ($resValues) {
                         $resIsValid = true;
                         foreach ($resValues as $val) {
                             if (!isset($val) || $val == 0 || $val == -1) {
                                 $resIsValid = false;
                                 break;
                             }
                         }
                         if ($resIsValid) {
                             $layerExtent = ms_newRectObj();
                             $layerExtent->setExtent($resValues['minx'], $resValues['miny'], $resValues['maxx'], $resValues['maxy']);
                         }
                     }
                 }
             } else {
                 if ($layer->type != MS_LAYER_RASTER && ($layer->connectiontype == MS_SHAPEFILE || $layer->connectiontype == MS_TILED_SHAPEFILE || $layer->connectiontype == MS_OGR)) {
                     // SHP layer, OGR layer
                     $layerExtent = @$layer->getExtent();
                 }
             }
             if ($layerExtent) {
                 // change projection
                 $mapProjStr = $map->getProjection();
                 $layerProjStr = $layer->getProjection();
                 if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) {
                     if ($_SESSION['MS_VERSION'] < 6) {
                         $mapProjObj = ms_newprojectionobj($mapProjStr);
                         $layerProjObj = ms_newprojectionobj($layerProjStr);
                     } else {
                         $mapProjObj = new projectionObj($mapProjStr);
                         $layerProjObj = new projectionObj($layerProjStr);
                     }
                     $layerExtent->project($layerProjObj, $mapProjObj);
                 }
                 // add buffer around freshly calculated extent
                 if ($addBuffer) {
                     $minx = $layerExtent->minx;
                     $miny = $layerExtent->miny;
                     $maxx = $layerExtent->maxx;
                     $maxy = $layerExtent->maxy;
                     $pointBuffer = isset($_SESSION['pointBuffer']) ? $_SESSION['pointBuffer'] : 50;
                     $shapeQueryBuffer = isset($_SESSION['shapeQueryBuffer']) ? $_SESSION['shapeQueryBuffer'] : 0.01;
                     $buf = 0;
                     if ($layer->type == MS_LAYER_POINT || $layer->type == MS_LAYER_ANNOTATION) {
                         $buf = $pointBuffer;
                         // set buffer depending on dimensions of your coordinate system
                     } else {
                         if (isset($shapeQueryBuffer) && $shapeQueryBuffer > 0) {
                             $buf = $shapeQueryBuffer * (($maxx - $minx + ($maxy - $miny)) / 2);
                         }
                     }
                     if ($buf > 0) {
                         $minx -= $buf;
                         $miny -= $buf;
                         $maxx += $buf;
                         $maxy += $buf;
                         $layerExtent->setExtent($minx, $miny, $maxx, $maxy);
                     }
                 }
                 if ($mapExtent->minx == -1 && $mapExtent->miny == -1 && $mapExtent->maxx == -1 && $mapExtent->maxy == -1) {
                     $minx = $layerExtent->minx;
                     $miny = $layerExtent->miny;
                     $maxx = $layerExtent->maxx;
                     $maxy = $layerExtent->maxy;
                 } else {
                     $minx = $layerExtent->minx < $mapExtent->minx ? $layerExtent->minx : $mapExtent->minx;
                     $miny = $layerExtent->miny < $mapExtent->miny ? $layerExtent->miny : $mapExtent->miny;
                     $maxx = $layerExtent->maxx > $mapExtent->maxx ? $layerExtent->maxx : $mapExtent->maxx;
                     $maxy = $layerExtent->maxy > $mapExtent->maxy ? $layerExtent->maxy : $mapExtent->maxy;
                 }
                 $mapExtent->setExtent($minx, $miny, $maxx, $maxy);
             }
         }
     }
     if ($mapExtent->minx == -1 || $mapExtent->miny == -1 || $mapExtent->maxx == -1 || $mapExtent->maxy == -1) {
         $mapExtent = $map->extent;
         if (!$applyMapExtentIfNull) {
             $mapExtent->setExtent(0, 0, 1, 1);
         }
     }
     return $mapExtent;
 }