function drawStateNEXRAD($hlext) { $width = 350; $height = 300; $map = ms_newMapObj("mosaic.map"); $map->set("width", $width); $map->set("height", $height); $map->setextent(-96.639706, 40.375437, -90.140061, 43.501196); $map->setProjection("init=epsg:4326"); $namerica = $map->getlayerbyname("namerica"); $namerica->set("status", MS_ON); $counties = $map->getlayerbyname("counties_unproj"); $counties->set("status", MS_ON); $radarL = $map->getlayerbyname("radar"); $radarL->set("status", MS_ON); $img = $map->prepareImage(); $namerica->draw($img); $radarL->draw($img); $counties->draw($img); $rect = $map->getlayerbyname("rect"); $rect->set("status", MS_ON); /** Draw a box for what we are zoomed in on */ $rt = ms_newRectObj(); $rt->setextent($hlext[0], $hlext[1], $hlext[2], $hlext[3]); $rt->draw($map, $rect, $img, 0, " "); $url = $img->saveWebImage(); $s = "<form name=\"img\" method=\"GET\" action=\"compare.phtml\">"; $s .= "<input type=\"hidden\" name=\"ul_x\" value=\"" . $map->extent->minx . "\">\n<input type=\"hidden\" name=\"ul_y\" value=\"" . $map->extent->maxy . "\">\n<input type=\"hidden\" name=\"lr_x\" value=\"" . $map->extent->maxx . "\">\n<input type=\"hidden\" name=\"lr_y\" value=\"" . $map->extent->miny . "\">\n<input type=\"hidden\" name=\"map_height\" value=\"" . $height . "\">\n<input type=\"hidden\" name=\"map_width\" value=\"" . $width . "\">"; $s .= "<input border=1 name=\"map\" type=\"image\" src=\"{$url}\"></form>"; return $s; }
} } */ $e_limit = ms_newRectObj(); $e_limit->setextent($extminx, $extminy, $extmaxx, $extmaxy); if (!empty($_REQUEST['extent'])) { // extent est une var passée en input hidden list($extminx, $extminy, $extmaxx, $extmaxy) = split(' ', trim(urldecode($_REQUEST['extent']))); } else { unset($_SESSION['pid']); unset($_REQUEST['pid']); $focus = array(); $focus["zoomin"] = "focus"; } $ext = array($extminx, $extminy, $extmaxx, $extmaxy); $e_extent = ms_newRectObj(); $e_extent->setextent($ext[0], $ext[1], $ext[2], $ext[3]); // changement de taille d'image-carte en pixels if (!isset($_REQUEST['size'])) { $sizex = $e_map->width; $sizey = $e_map->height; } else { list($sizex, $sizey) = split('x', $_REQUEST['size']); } $sizecheck["{$sizex}x{$sizey}"] = " selected=\"selected\""; $e_map->set('width', $sizex); $e_map->set('height', $sizey); $e_click = ms_newPointObj(); // objet de pointage $e_click->setXY(floor($sizex / 2), floor($sizey / 2), 0); // par d?faut, comme un clic au centre
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"; }
<?php /* * Draw a map of the CONUS with a simple box showing the area of interest */ require_once "../../config/settings.inc.php"; $extents = isset($_GET["BBOX"]) ? explode(",", $_GET["BBOX"]) : array(-105, 40, -97, 47); $mapFile = "../../data/gis/base4326.map"; $map = ms_newMapObj($mapFile); $map->setSize(300, 130); $map->setExtent(-126, 24, -66, 50); $img = $map->prepareImage(); $namerica = $map->getlayerbyname("namerica"); $namerica->set("status", MS_ON); $namerica->draw($img); $lakes = $map->getlayerbyname("lakes"); $lakes->set("status", MS_ON); $lakes->draw($img); $states = $map->getlayerbyname("states"); $states->set("status", MS_ON); $states->draw($img); /* Now we draw a box */ $rect = $map->getlayerbyname("rect"); $rect->set("status", MS_ON); $rt = ms_newRectObj(); $rt->setextent($extents[0], $extents[1], $extents[2], $extents[3]); $rt->draw($map, $rect, $img, 0, " "); header("Content-type: image/png"); $img->saveImage('');
/** * 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; }
function retornaShapesSelecionados($objLayer, $map_file, $objMapa, $indexado = false) { $shapes = array(); $qyfile = dirname($map_file) . "/" . $objLayer->name . "_qy.map"; if (!file_exists($qyfile)) { return $shapes; } $handle = fopen($qyfile, "r"); $conteudo = fread($handle, filesize($qyfile)); fclose($handle); $listaDeIndices = unserialize($conteudo); if (count($listaDeIndices) == 0) { return $shapes; } $versao = versao(); $versao = $versao["principal"]; if ($objLayer->connectiontype != MS_POSTGIS) { //pega os shapes selecionados carregaquery2($map_file, $objLayer, $objMapa); $sopen = $objLayer->open(); if ($sopen == MS_FAILURE) { return "erro"; } $res_count = $objLayer->getNumresults(); $centroides = array(); $shapes = array(); //pega um shape especifico for ($i = 0; $i < $res_count; ++$i) { if ($versao >= 6) { $shape = $objLayer->getShape($objLayer->getResult($i)); $shp_index = $shape->index; } else { $result = $objLayer->getResult($i); $shp_index = $result->shapeindex; $shape = $objLayer->getfeature($shp_index, -1); } if ($indexado == true) { $shapes[$shp_index] = $shape; } else { $shapes[] = $shape; } } $fechou = $objLayer->close(); } else { //var_dump($listaDeIndices);exit; $rect = ms_newRectObj(); $rect->set("minx", -180); $rect->set("miny", -90); $rect->set("maxx", 180); $rect->set("maxy", 90); $status = $objLayer->open(); $status = $objLayer->whichShapes($rect); while ($shape = $objLayer->nextShape()) { if (in_array($shape->index, $listaDeIndices)) { if ($indexado == true) { $shapes[$shape->index] = $shape; } else { $shapes[] = $shape; } } } $objLayer->close(); } return $shapes; }
function selecaoBOX($tipo, $ext, $retornaShapes = false) { if ($tipo == "novo") { $this->selecaoLimpa(); $tipo = "adiciona"; } if (!$this->layer) { return "erro"; } $this->layer->set("tolerance", 0); if ($tipo == "limpa") { return $this->selecaoLimpa(); } if ($tipo == "inverte") { return $this->selecaoInverte(); } if (file_exists($this->qyfile)) { $this->mapa->loadquery($this->qyfile); } $indxlayer = $this->layer->index; $shp_atual = array(); if ($this->qyfileTema != "" && file_exists($this->qyfileTema)) { $shp_atual = $this->unserializeQ($this->qyfileTema); } $shpi = array(); $temp = explode(" ", $ext); $rect = ms_newRectObj(); $rect->set("minx", min(array($temp[0], $temp[2]))); $rect->set("miny", min(array($temp[1], $temp[3]))); $rect->set("maxx", max(array($temp[0], $temp[2]))); $rect->set("maxy", max(array($temp[1], $temp[3]))); $ident = $this->layer->queryByRect($rect); if ($ident != 1) { $res_count = $this->layer->getNumresults(); //echo $res_count;exit;325449 $shpi = array(); for ($i = 0; $i < $res_count; ++$i) { $result = $this->layer->getResult($i); if ($result != MS_FALSE) { if ($retornaShapes == false) { $shpi[] = $result->shapeindex; } else { if ($this->v >= 6) { $shpi[] = $this->layer->getshape($result); } else { $shpi[] = $this->layer->getfeature($result->shapeindex, -1); } } } } } if ($retornaShapes == true) { return $shpi; } if ($tipo == "adiciona") { return $this->selecaoAdiciona($shpi, $shp_atual); } if ($tipo == "retira") { return $this->selecaoRetira($shpi, $shp_atual); } }
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; }
function gradeDeHex($dd, $px, $py, $locaplic, $nptx, $npty, $proj = false) { set_time_limit(180); // http://gmc.yoyogames.com/index.php?showtopic=336183 $hh = sin(deg2rad(30)) * $dd; $rr = cos(deg2rad(30)) * $dd; // para manipular dbf if ($this->dbaseExiste == false) { include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php"; } $nomegrade = nomeRandomico(); $nomeshp = $this->diretorio . "/" . $nomegrade; // pega a extensão geográfica do mapa $this->mapa->preparequery(); $r = $this->mapa->extent; $ext = ms_newRectObj(); $ext->setextent($r->minx, $r->miny, $r->maxx, $r->maxy); if ($proj == true) { // caso precise projetar $projInObj = ms_newprojectionobj("proj=latlong,a=6378137,b=6378137"); $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"); $ext->project($projInObj, $projOutObj); $pt = ms_newpointobj(); $pt->setXY($px, $py); $pt->project($projInObj, $projOutObj); $px = $pt->x; $py = $pt->y; } $fx = $ext->maxx; $fy = $ext->miny; // calcula a distância entre os pontos em dd se nao tiver sido especificada ou for 0 $distx = $fx - $px; $disty = $fy - $py; if ($distx < 0) { $distx = $distx * -1; } if ($disty < 0) { $disty = $disty * -1; } if ($nptx == "") { $nptx = round($distx / $dd, 0); } if ($npty == "") { $npty = round($disty / $dd, 0); } // cria o shapefile $novoshpf = ms_newShapefileObj($nomeshp, MS_SHP_POLYGON); $def = array(); $def[] = array("id", "C", "20"); if ($this->dbaseExiste == false) { $db = xbase_create($nomeshp . ".dbf", $def); xbase_close($db); } else { $db = dbase_create($nomeshp . ".dbf", $def); dbase_close($db); } // acrescenta os pontos no novo shapefile $dbname = $nomeshp . ".dbf"; if ($this->dbaseExiste == false) { $db = xbase_open($dbname, 2); } else { $db = dbase_open($dbname, 2); } $reg = array(); $w = $this->mapa->width; $h = $this->mapa->height; $valorcoluna = $px; $par = false; for ($coluna = 0; $coluna < $nptx; $coluna++) { $x = $valorcoluna; $valorlinha = $py; if ($par == true) { $valorlinha = $valorlinha - $rr; $par = false; } else { // $y = $y + $hh; $par = true; } for ($linha = 0; $linha < $npty; $linha++) { $y = $valorlinha; $valorlinha = $valorlinha - 2 * $rr; $poPoint1 = ms_newpointobj(); $poPoint2 = ms_newpointobj(); $poPoint3 = ms_newpointobj(); $poPoint4 = ms_newpointobj(); $poPoint5 = ms_newpointobj(); $poPoint6 = ms_newpointobj(); // Point 0: $x, $y // Point 1: x + s, y // Point 2: x + s + h, y + r // Point 3: x + s, y + r + r // Point 4: x, y + r + r // Point 5: x - h, y + r $poPoint1->setXY($x, $y); $poPoint2->setXY($x + $dd, $y); $poPoint3->setXY($x + $dd + $hh, $y - $rr); $poPoint4->setXY($x + $dd, $y - $rr - $rr); $poPoint5->setXY($x, $y - $rr - $rr); $poPoint6->setXY($x - $hh, $y - $rr); if ($proj == true) { $poPoint1->project($projOutObj, $projInObj); $poPoint2->project($projOutObj, $projInObj); $poPoint3->project($projOutObj, $projInObj); $poPoint4->project($projOutObj, $projInObj); $poPoint5->project($projOutObj, $projInObj); $poPoint6->project($projOutObj, $projInObj); } $linhas = ms_newLineObj(); $linhas->add($poPoint1); $linhas->add($poPoint2); $linhas->add($poPoint3); $linhas->add($poPoint4); $linhas->add($poPoint5); $linhas->add($poPoint6); $linhas->add($poPoint1); $shapen = ms_newShapeObj(MS_SHP_POLYGON); $shapen->add($linhas); $novoshpf->addShape($shapen); $reg[] = $linha . "-" . $coluna; if ($this->dbaseExiste == false) { xbase_add_record($db, $reg); } else { dbase_add_record($db, $reg); } $reg = array(); } $valorcoluna = $valorcoluna + $dd + $hh; } if ($this->dbaseExiste == false) { xbase_close($db); } else { dbase_close($db); } // adiciona o novo tema no mapa $novolayer = criaLayer($this->mapa, MS_LAYER_POLYGON, MS_DEFAULT, "Grade (" . $nomegrade . ")", $metaClasse = "SIM"); $novolayer->set("data", $nomeshp . ".shp"); $novolayer->setmetadata("DOWNLOAD", "SIM"); $novolayer->setmetadata("TEMALOCAL", "SIM"); $novolayer->set("opacity", "50"); if (file_exists($this->qyfile)) { unlink($this->qyfile); } return "ok"; }
/** * 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; }
/** * DRAW XY LAYER: ADD POINTS FROM DB TO MAP IMAGE */ protected function pmap_drawXYLayer($img) { $grouplist = $_SESSION["grouplist"]; // Loop through groups and layers to find XYLayers foreach ($grouplist as $grp) { $glayerList = $grp->getLayers(); foreach ($glayerList as $glayer) { $XYLayerProperties = $glayer->getXYLayerProperties(); if ($XYLayerProperties) { // XYLayer found, now process $mLayer = $this->map->getLayer($glayer->getLayerIdx()); $mLayerStatus = $mLayer->status; if ($mLayerStatus == MS_ON) { // Check if XYLayer is switched ON $pearDbClass = $_SESSION['pearDbClass']; require_once "{$pearDbClass}.php"; require_once "../query/query.php"; // Check if Layer projection differs from Map projection $changeLayProj = PMCommon::checkProjection($this->map, $mLayer); // Map extent for limiting query if ($changeLayProj) { $me = $this->map->extent; $mapExt = ms_newRectObj(); $mapExt->setExtent($me->minx, $me->miny, $me->maxx, $me->maxy); $mapExt->project($changeLayProj['mapProj'], $changeLayProj['layProj']); } else { $mapExt = $this->map->extent; } $map_xmin = $mapExt->minx; $map_ymin = $mapExt->miny; $map_xmax = $mapExt->maxx; $map_ymax = $mapExt->maxy; if ($changeLayProj) { PMCommon::freeMsObj($mapExt); } // XY Layer Properties $dsn = $XYLayerProperties["dsn"]; $xyTable = $XYLayerProperties["xyTable"]; $x_fld = $XYLayerProperties["x_fld"]; $y_fld = $XYLayerProperties["y_fld"]; $classidx_fld = $XYLayerProperties["classidx_fld"]; $resFldStr = $mLayer->getMetaData("RESULT_FIELDS"); $resFieldList = preg_split('/[\\s,]+/', $resFldStr); // Prepare query if (preg_match("/@/", $xyTable)) { // Check for WHERE filter in table definition $xyList = preg_split('/@/', $xyTable); $whereFilter = $xyList[1]; $xyTable = $xyList[0]; } $sql_SELECT = "SELECT {$x_fld}, {$y_fld}, {$classidx_fld} FROM {$xyTable} "; $sql_WHERE = "WHERE " . ($whereFilter ? $whereFilter . " AND " : "") . " {$x_fld} >= {$map_xmin} AND {$x_fld} <= {$map_xmax} AND {$y_fld} >= {$map_ymin} AND {$y_fld} <= {$map_ymax}"; $sql = "{$sql_SELECT} {$sql_WHERE}"; pm_logDebug(3, $sql, "P.MAPPER-DEBUG: map.php/pmap_drawXYLayer() - SQL Cmd:"); // init DB class $db = new $pearDbClass(); // Connect to DB $dbh = $db->connect($dsn); if ($db->isError($dbh)) { PMCommon::db_logErrors($dbh); die; } // Execute query $res = $dbh->query($sql); if ($db->isError($res)) { PMCommon::db_logErrors($res); die; } // Draw points on map image while ($xyRow = $res->fetchRow()) { $ptX = $xyRow[0]; $ptY = $xyRow[1]; $clIdx = $xyRow[2]; $xyPoint = ms_newPointObj(); $xyPoint->setXY($ptX, $ptY); $xyPoint->draw($this->map, $mLayer, $img, $clIdx, ""); PMCommon::freeMsObj($xyPoint); } //$res->free(); $dbh->disconnect(); } } } } }
$zSizex = $zMap->width; $zSizey = $zMap->height; $sizex = $zSizex; $sizey = $zSizey; } else { $zSizex = $sizex; $zSizey = $sizey; } if (!is_array($ext)) { $zExtent = $zMap->extent; } elseif (!empty($fsens)) { $fext = move_map($ext, $fsens); $zExtent = ms_newRectObj(); $zExtent->setextent($fext[0], $fext[1], $fext[2], $fext[3]); } else { $zExtent = ms_newRectObj(); $zExtent->setextent($ext[0], $ext[1], $ext[2], $ext[3]); } $zClick = ms_newPointObj(); if ($act and ($refx and $refy) and sizeof($ext) > 3) { $refx = floor($refx * ($sizex / $conf[globals][minimapx])); $refy = floor($refy * ($sizey / $conf[globals][minimapy])); $zClick->setXY($refx, $refy, 0); $zMap->zoomscale($scl * 1000, $zClick, $sizex, $sizey, $zLimit, $zLimit); } else { if ($act != "edition" and $click_x and $click_y) { $zClick->setXY($click_x, $click_y, 0); $clicked = TRUE; } else { $zClick->setXY(floor($sizex / 2), floor($sizey / 2), 0); $clicked = FALSE;
function reprojectExtent($inExt) { $qShpBounds = ms_newRectObj(); // Apply buffer in order to have a correct re-projection of POINT layers $pjbuff = $this->qLayer->type == 0 ? 1.0E-7 : 0; $sMinx = $inExt[1] - $pjbuff; $sMiny = $inExt[2] - $pjbuff; $sMaxx = $inExt[3] + $pjbuff; $sMaxy = $inExt[4] + $pjbuff; $qShpBounds->set("minx", $sMinx); $qShpBounds->set("miny", $sMiny); $qShpBounds->set("maxx", $sMaxx); $qShpBounds->set("maxy", $sMaxy); $qShpBounds->project($this->qLayerProjObj, $this->mapProjObj); $pb['shpMinx'] = $qShpBounds->minx; $pb['shpMiny'] = $qShpBounds->miny; $pb['shpMaxx'] = $qShpBounds->maxx; $pb['shpMaxy'] = $qShpBounds->maxy; return $pb; }
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; }