private function url_createLayer() { if (!is_file($_SESSION['PM_TPL_MAP_FILE'])) { error_log("P.MAPPER ERROR: cannot find template map. Check INI settings for 'tplMapFile'"); return false; } $tplMap = ms_newMapObj($_SESSION['PM_TPL_MAP_FILE']); $poiLayer = $tplMap->getLayerByName("poi"); $txtLayer = ms_newLayerObj($this->map, $poiLayer); $txtLayer->set("name", "url_txtlayer"); $txtLayer->set("type", 0); $txtLayer->set("status", MS_ON); $url_points = $_SESSION['url_points']; foreach ($url_points as $upnt) { // Create line, add xp point, create shape and add line and text, add shape to layer //$pointList = explode(",", $f); $px = $upnt[0]; $py = $upnt[1]; $txt = $upnt[2]; $newLine = ms_newLineObj(); $newLine->addXY($px, $py); $newShape = ms_newShapeObj(0); $newShape->add($newLine); $newShape->set("text", $txt); $txtLayer->addFeature($newShape); } }
function addPoint($row, $lon, $lat, $name) { global $shpFile, $dbfFile; // Create the shape $shp = ms_newShapeObj(MS_SHAPE_POINT); $pt = ms_newPointobj(); $pt->setXY($lon, $lat, 0); $line = ms_newLineObj(); $line->add($pt); $shp->add($line); $shpFile->addShape($shp); dbase_add_record($dbfFile, array($row["station"], $name, $row["years"], $row["cvalid"], $row["high"], $row["low"], $row["precip"], $row["max_precip"], $row["max_precip_yr"], $row["max_high"], $row["max_low"], $row["min_high"], $row["min_low"], $row["max_high_yr"], $row["max_low_yr"], $row["min_high_yr"], $row["min_low_yr"])); }
function adicionaTemaGeoRSS($servico, $dir_tmp, $locaplic, $canal) { $xml = simplexml_load_file($servico); $conta = 0; foreach ($xml->channel as $c) { if ($conta == $canal) { $canal = $c; } } $nos = $canal->item; //verifica se o canal faz referencia a elementos externos //se sim, usa todos os elementos do xml no lugar do canal foreach ($canal->items as $t) { foreach ($t->xpath('rdf:Seq') as $x) { foreach ($x->xpath('rdf:li') as $z) { $nos = $xml->item; } } } $resultado = array(); $tipog = ""; foreach ($nos as $item) { $env = array(); //define o tipo if ($item->xpath('geo:lat')) { $tipog = "geo"; } if ($item->xpath('georss:point')) { $tipog = "georsspoint"; } if ($item->xpath('georss:where')) { $tipog = "envelope"; } if ($tipog == "envelope") { foreach ($item->xpath('georss:where') as $w) { foreach ($w->xpath('gml:Envelope') as $e) { //$lc = $e->xpath('gml:lowerCorner'); $lc = (string) $e->children('gml', TRUE)->lowerCorner; //$uc = $e->xpath('gml:upperCorner'); $uc = (string) $e->children('gml', TRUE)->upperCorner; $lc = explode(" ", $lc); $uc = explode(" ", $uc); if (is_numeric($lc[0])) { $ymin = $lc[0]; $ymax = $uc[0]; $xmin = $lc[1]; $xmax = $uc[1]; if ($ymin != "") { $env = array($xmin, $ymin, $xmax, $ymax); } } } } } if ($tipog == "geo") { if ($item->xpath('geo:lon')) { $x = (string) $item->children('geo', TRUE)->lon; } else { $x = (string) $item->children('geo', TRUE)->long; } //$y = $item->xpath('geo:lat'); $y = (string) $item->children('geo', TRUE)->lat; $env = array($y, $x); } if ($tipog == "georsspoint") { //$temp = $item->xpath('georss:point'); $temp = (string) $item->children('georss', TRUE)->point; $env = explode(" ", $temp); } if (count($env) > 0) { $resultado[] = array(ixml($item, "title"), ixml($item, "link"), ixml($item, "description"), ixml($item, "category"), $env); } } //cria o shapefile com os dados if (count($resultado) > 0) { //para manipular dbf include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php"; $diretorio = dirname($this->arquivo); $tipol = MS_SHP_POLYGON; if ($tipog == "georsspoint") { $tipol = MS_SHP_POINT; } if ($tipog == "geo") { $tipol = MS_SHP_POINT; } $novonomelayer = nomeRandomico(10) . "georss"; $nomeshp = $diretorio . "/" . $novonomelayer; $novoshpf = ms_newShapefileObj($nomeshp, $tipol); $def[] = array("TITULO", "C", "254"); $def[] = array("LINK", "C", "254"); $def[] = array("DESC", "C", "254"); $def[] = array("CATEGORIA", "C", "254"); if (!function_exists(dbase_create)) { $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"; $db = xbase_open($dbname, 2); $reg = array(); $novoshpf = ms_newShapefileObj($nomeshp . ".shp", -2); //acrescenta os shapes foreach ($resultado as $r) { $pts = $r[4]; if ($tipol == MS_SHP_POLYGON) { $shp = ms_newShapeObj(MS_SHP_POLYGON); $linha = ms_newLineObj(); $linha->addXY($pts[0], $pts[3]); $linha->addXY($pts[2], $pts[3]); $linha->addXY($pts[2], $pts[1]); $linha->addXY($pts[0], $pts[1]); $linha->addXY($pts[0], $pts[3]); } else { $shp = ms_newShapeObj(MS_SHP_POINT); $linha = ms_newLineObj(); $linha->addXY($pts[1], $pts[0]); } $shp->add($linha); $novoshpf->addShape($shp); $reg = array($r[0], $r[1], $r[2], $r[3]); xbase_add_record($db, $reg); $reg = array(); } xbase_close($db); if ($tipog == "georsspoint" || $tipog == "geo") { $tipol = MS_LAYER_POINT; } else { $tipol = MS_LAYER_POLYGON; } $layer = criaLayer($this->mapa, $tipol, MS_DEFAULT, "GeoRSS", "SIM"); $layer->set("data", $nomeshp . ".shp"); $layer->set("name", basename($nomeshp)); $layer->setmetadata("DOWNLOAD", "sim"); $layer->setmetadata("TEMALOCAL", "SIM"); //evita problemas no modo tile if ($this->v > 5) { $layer->setprocessing("LABEL_NO_CLIP=True"); $layer->setprocessing("POLYLINE_NO_CLIP=True"); } if ($tipol == MS_LAYER_POLYGON) { $classe = $layer->getclass(0); $estilo = $classe->getstyle(0); $estilo->set("symbolname", "p4"); $estilo->set("size", 5); $cor = $estilo->color; $cor->setrgb(255, 0, 0); $coro = $estilo->outlinecolor; $coro->setrgb(255, 0, 0); } //$layer->set("transparency",50); $layer->setmetadata("nomeoriginal", basename($nomeshp)); //echo $tipol; return "ok"; } return "erro"; }
$e_style2 = ms_newStyleObj($e_class2); $e_style2->color->setRGB(200, 160, 100); $e_style2->set("size", 7); $e_style2->set("symbolname", 'circle'); $e_track = ms_newLayerObj($e_map); $e_track->set('name', 'temptrack'); $e_track->set('status', MS_ON); $e_track->set('type', MS_LAYER_LINE); $e_track->addFeature($e_shape); $e_class = ms_newClassObj($e_track); $e_style = ms_newStyleObj($e_class); $e_style->color->setRGB(255, 255, 20); $e_style->set("size", 3); $e_style->set("symbolname", 'circle'); $e_shapestart = ms_newShapeObj(MS_SHAPE_POINT); $e_line = ms_newLineObj(); list($px, $py) = split(' ', $_SESSION['track'][0]); $e_line->addXY($px, $py); $e_shapestart->add($e_line); $e_track3 = ms_newLayerObj($e_map); $e_track3->set('name', 'temptrackstart'); $e_track3->set('status', MS_ON); $e_track3->set('type', MS_LAYER_POINT); $e_track3->addFeature($e_shapestart); $e_class3 = ms_newClassObj($e_track3); $e_style3 = ms_newStyleObj($e_class3); $e_style3->set("symbolname", 'flag2'); } $e_image = $e_map->draw(); $image = $e_image->saveWebImage(); $e_ref = $e_map->drawreferencemap();
/** * 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); } }
function inserePoligonosUrl() { global $tamanhosimbolo, $simbolo, $corsimbolo, $poligonos, $nometemapoligonos, $dir_tmp, $imgdir, $tmpfname, $locaplic; include_once "pacotes/phpxbase/api_conversion.php"; if (!isset($nometemapoligonos)) { $nometemapoligonos = "Poligonos"; } if ($nometemapoligonos == "") { $nometemapoligonos = "Poligonos"; } // //cria o shape file // $tipol = MS_SHP_POLYGON; $nomeshp = $dir_tmp . "/" . $imgdir . "/poligonosins"; // cria o dbf $def = array(); $items = array("COORD"); foreach ($items as $ni) { $def[] = array($ni, "C", "254"); } if (!function_exists(dbase_create)) { xbase_create($nomeshp . ".dbf", $def); } else { dbase_create($nomeshp . ".dbf", $def); } $dbname = $nomeshp . ".dbf"; $db = xbase_open($dbname, 2); $novoshpf = ms_newShapefileObj($nomeshp, $tipol); $linhas = explode(",", trim($poligonos)); $pontosLinhas = array(); //guarda os pontos de cada linha em arrays foreach ($linhas as $l) { $tempPTs = explode(" ", trim($l)); $temp = array(); foreach ($tempPTs as $p) { if (is_numeric($p)) { $temp[] = $p; } } $pontosLinhas[] = $temp; } foreach ($pontosLinhas as $ptsl) { $linhas = $ptsl; $shape = ms_newShapeObj($tipol); $linha = ms_newLineObj(); $reg = array(); $reg[] = ""; for ($ci = 0; $ci < count($linhas); $ci = $ci + 2) { $linha->addXY($linhas[$ci], $linhas[$ci + 1]); } $shape->add($linha); $novoshpf->addShape($shape); xbase_add_record($db, $reg); } $novoshpf->free(); xbase_close($db); //adiciona o layer $mapa = ms_newMapObj($tmpfname); $layer = ms_newLayerObj($mapa); $layer->set("name", "linhains"); $layer->set("data", $nomeshp . ".shp"); $layer->setmetadata("DOWNLOAD", "sim"); $layer->setmetadata("temalocal", "sim"); $layer->setmetadata("tema", $nometemapoligonos); $layer->setmetadata("classe", "sim"); $layer->setmetadata("ATLAS", "nao"); $layer->set("type", MS_LAYER_POLYGON); $layer->set("opacity", "50"); $layer->set("status", MS_DEFAULT); $classe = ms_newClassObj($layer); $classe->set("name", " "); $estilo = ms_newStyleObj($classe); $cor = $estilo->color; if (!isset($corsimbolo)) { $corsimbolo = "255,0,0"; } $corsimbolo = str_replace(" ", ",", $corsimbolo); $corsimbolo = explode(",", $corsimbolo); $cor->setRGB($corsimbolo[0], $corsimbolo[1], $corsimbolo[2]); $salvo = $mapa->save($tmpfname); erroCriacao(); }
function selecaoPT($xy, $tipo, $tolerancia) { if ($tipo == "novo") { $this->selecaoLimpa(); $tipo = "adiciona"; } if ($tipo == "limpa") { return $this->selecaoLimpa(); } if ($tipo == "inverte") { return $this->selecaoInverte(); } if (!$this->layer) { return "erro"; } $shp_atual = array(); if ($this->qyfileTema != "" && file_exists($this->qyfileTema)) { $shp_atual = $this->unserializeQ($this->qyfileTema); } $shpi = array(); $c = explode(" ", $xy); $pt = ms_newPointObj(); $pt->setXY($c[0], $c[1]); if ($tolerancia == 0) { $this->layer->set("tolerance", 0); $this->layer->set("toleranceunits", 6); if ($this->layer->type == MS_LAYER_POINT || $this->layer->type == MS_LAYER_LINE) { $this->layer->set("tolerance", 5); $ident = @$this->layer->queryByPoint($pt, 1, 0); } else { $ident = @$this->layer->queryByPoint($pt, 1, 0); } } else { error_reporting(0); $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); //$dd1 = ms_newpointobj(); //$dd1->setXY($rect->minx, $rect->miny); $poPoint->project($projInObj, $projOutObj); $dd2 = ms_newpointobj(); $dd2->setXY($poPoint->x + $tolerancia, $poPoint->y); $dd2->project($projOutObj, $projInObj); $d = $pt->distanceToPoint($dd2); if ($d < 0) { $d = $d * -1; } //calcula a distancia 29100 //gera o buffer $s = ms_newShapeObj(MS_SHAPE_POINT); $linha = ms_newLineObj(); $linha->add($pt); $s->add($linha); $buffer = $s->buffer($d); $ident = @$this->layer->queryByShape($buffer); } if ($ident != 1) { $res_count = $this->layer->getNumresults(); $shpi = array(); for ($i = 0; $i < $res_count; ++$i) { $result = $this->layer->getResult($i); $shpi[] = $result->shapeindex; } } if ($tipo == "adiciona") { return $this->selecaoAdiciona($shpi, $shp_atual); } if ($tipo == "retira") { return $this->selecaoRetira($shpi, $shp_atual); } }
function calculaAreaPixel($map_file, $celsize) { $mapa = ms_newMapObj($map_file); $rect = $mapa->extent; $projInObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs"); $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=0,lon_0=" . $rect->minx . ",x_0=5000000,y_0=10000000"); $y = $rect->maxy - ($rect->maxy - $rect->miny) / 2; $x = $rect->maxx - ($rect->maxx - $rect->minx) / 2; $shape = ms_newShapeObj(MS_SHAPE_POLYGON); $linha = ms_newLineObj(); $linha->addXY($x, $y); $linha->addXY($x + $celsize, $y); $linha->addXY($x + $celsize, $y - $celsize); $linha->addXY($x, $y - $celsize); $linha->addXY($x, $y); $shape->add($linha); $shape->project($projInObj, $projOutObj); $s = $shape->towkt(); $shape = ms_shapeObjFromWkt($s); $area = $shape->getArea(); return $area; }
$oLabelObj2->set("size", 7); $oLabelObj2->set("type", MS_TRUETYPE); $oLabelObj2->set("font", "arial"); $oLabelObj2->color->setRGB(0, 0, 0); $oLabelObj2->outlinecolor->setRGB(255, 255, 255); $oMapClass2 = ms_newClassObj($oLayerPoints2); $oMapClass2->addLabel($oLabelObj2); //auteur et logo if ($printLogo && isset($_GET['printNomAuteur'])) { $auteurNom = $_GET['printNomAuteur']; $oLayerPoints3 = ms_newLayerObj($oMap); $oLayerPoints3->set("name", "Title"); $oLayerPoints3->set("type", MS_LAYER_ANNOTATION); $oLayerPoints3->set("status", MS_DEFAULT); $oLayerPoints3->set("transform", MS_FALSE); $oCoordList3 = ms_newLineObj(); $oPointShape3 = ms_newShapeObj(MS_SHAPE_POINT); $oCoordList3->addXY($nMapWidth - $heightMaxLogo - 5, $nMapHeight - 5); $oPointShape3->add($oCoordList3); $oPointShape3->set("text", $auteurNom); $oLayerPoints3->addFeature($oPointShape3); $oLabelObj3 = new labelObj(); $oLabelObj3->set("position", MS_CL); $oLabelObj3->set("size", 7); $oLabelObj3->set("type", MS_TRUETYPE); $oLabelObj3->set("font", "arial"); $oLabelObj3->set("align", MS_ALIGN_LEFT); $oLabelObj3->color->setRGB(0, 0, 0); $oLabelObj3->outlinecolor->setRGB(255, 255, 255); $oMapClass3 = ms_newClassObj($oLayerPoints3); $oMapClass3->addLabel($oLabelObj3);
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"; }
function updatePolDBFRecord($szFileName, $aszPointProperties, $nId = -1, $aPuntos) { $dbfFile = dbase_open($szFileName . '.dbf', 2); $nCount = dbase_numrecords($dbfFile); $nMaxID = $nCount + 1; $aszPointProperties[0] = $nMaxID; // add the record to the dbase file if the array is populated if (count($aszPointProperties) > 0) { $shpFile = ms_newShapeFileObj($szFileName, -2); $oShp = ms_newShapeObj(MS_SHP_LINE); $oLine = ms_newLineObj(); //$oLine->addXY($aPuntos[0], $aPuntos[1]); //$oLine->addXY($aPuntos[2], $aPuntos[3]); $nPoints = count($aPuntos); for ($i = 0; $i < $nPoints; $i++) { if (fmod($i, 2) == 0) { //$aX = $aPuntos[$i]; } else { $j = $i - 1; //$aPuntos[$i]; $oLine->addXY($aPuntos[$j], $aPuntos[$i]); } } $oShp->add($oLine); $oLine->free(); $shpFile->addShape($oShp); $aszPointProperties[2] = $oShp->getLength(); $aszPointProperties[3] = $oShp->getArea(); dbase_add_record($dbfFile, array_values($aszPointProperties)); } $oShp->free(); $shpFile->free(); // close the dbf dbase_close($dbfFile); // return success return true; // end updatePolDBFRecord() function }
/** * 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); } }
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"; }
function updatePtoDBFRecord($szFileName, $aszPointProperties, $nId = -1, $aPuntos) { $dbfFile = dbase_open($szFileName . '.dbf', 2); // loop through the database and match the id $nCount = dbase_numrecords($dbfFile); //$nMaxID = 0; $nMaxID = $nCount + 1; $aszPointProperties[0] = $nMaxID; // add the record to the dbase file if the array is populated if (count($aszPointProperties) > 0) { $shpFile = ms_newShapefileObj(dirname(__FILE__) . '\\' . $szFileName, -2); $nPoints = count($aPuntos); if ($nPoints > 0) { $oShp = ms_newShapeObj(MS_SHP_POINT); $oPoint = ms_newLineObj(); $oPoint->addXY($aPuntos[0], $aPuntos[1]); $oShp->add($oPoint); $oPoint->free(); $shpFile->addShape($oShp); $oShp->free(); dbase_add_record($dbfFile, array_values($aszPointProperties)); } } $shpFile->free(); // close the dbf dbase_close($dbfFile); // return success return true; }
function lcls_drawlayer($drawlayer) { global $zMap, $zImage, $userlayers, $ext, $sizex, $sizey; if ($userlayers["{$drawlayer}"]["layertype"] == 'point') { $layertype = MS_LAYER_POINT; $shapetype = MS_SHAPE_POINT; } elseif ($userlayers["{$drawlayer}"]["layertype"] == 'line') { $layertype = MS_LAYER_LINE; $shapetype = MS_SHAPE_LINE; } $zUser = ms_newLayerObj($zMap); $zUser->set("status", MS_ON); $zUser->set("type", $layertype); $zUser->set("classitem", "item"); $zUser->set("name", $userlayers["{$drawlayer}"]["layername"]); #$zUser->set("group", $userlayers["$drawlayer"]["layergroup"]); $zUclass = ms_newClassObj($zUser); $zUclass->set("name", $userlayers["{$drawlayer}"]["layername"]); if ($userlayers[$drawlayer][layercolor]) { list($r, $v, $b) = split(' ', $userlayers[$drawlayer][layercolor]); $zUclass->set("color", $zMap->addColor($r, $v, $b)); } if ($userlayers["{$drawlayer}"]["layersymbol"]) { $zUclass->set("symbolname", $userlayers["{$drawlayer}"]["layersymbol"]); } $zUclass->set("size", $userlayers["{$drawlayer}"]["layersize"]); $zUclass->set("outlinecolor", "-1"); $listlines = listlines($drawlayer, $ext); if (is_array($listlines)) { foreach ($listlines as $o => $l) { if (is_array($l[1])) { $zUclass->set("status", MS_ON); $zUshape = ms_newShapeObj($shapetype); foreach ($l[1] as $drawpoint) { $zUline = ms_newLineObj(); $zUline->addXY($drawpoint[E], $drawpoint[N], 0); $imgx = geo2pix($drawpoint[E], $ext[0], $ext[2], $sizex); $imgy = $sizey - geo2pix($drawpoint[N], $ext[1], $ext[3], $sizey); $pointslist["{$imgx}/{$imgy}"] = array($o, $l[0]); $zUshape->add($zUline); } } if (is_object($zUshape)) { $zUshape->draw($zMap, $zUser, $zImage, 1, "test"); } } } return $pointslist; }