function pegaSelecaoRegioes() { global $m, $map_file, $postgis_mapa; $codigo_tipo_regiao = ""; $selecaoRegiao = array(); $regiao = ""; $item = ""; $registros = ""; if ($map_file != "") { $mapa = ms_newMapObj($map_file); $c = $mapa->numlayers; for ($i = 0; $i < $c; ++$i) { $l = $mapa->getlayer($i); //verifica o alias na conexao if (!empty($postgis_mapa)) { if ($l->connectiontype == MS_POSTGIS) { $lcon = $l->connection; if ($lcon == " " || $lcon == "" || in_array($lcon, array_keys($postgis_mapa))) { if ($lcon == " " || $lcon == "") { $l->set("connection", $postgis_mapa); } else { $l->set("connection", $postgis_mapa[$lcon]); } } } } // $registros = array(); if ($l->status == MS_DEFAULT && $l->getmetadata("METAESTAT_CODIGO_TIPO_REGIAO") != "") { //verifica se tem selecao $qyfile = dirname($map_file) . "/" . $l->name . ".php"; if (file_exists($qyfile)) { $codigo_tipo_regiao = $l->getmetadata("METAESTAT_CODIGO_TIPO_REGIAO"); //pega os registros $shapes = retornaShapesSelecionados($l, $map_file, $mapa); //pega o nome da coluna que identifica cada registro $regiao = $m->listaTipoRegiao($codigo_tipo_regiao); $item = $regiao["identificador"]; foreach ($shapes as $shape) { $registros[] = $shape->values[$item]; } $reg = $item . " IN ('" . implode("','", $registros) . "') "; $selecaoRegiao[$codigo_tipo_regiao] = array("item" => $item, "sql" => $reg); break; //mantem a primeira ocorrencia de regiao que possui selecao } else { $selecaoRegiao[$codigo_tipo_regiao] = ""; } } } return array("selecaoRegiao" => $selecaoRegiao, "codigo_tipo_regiao" => $codigo_tipo_regiao); } }
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"; }
function criaSHP($tema, $map_file, $locaplic, $dir_tmp, $nomeRand = TRUE, $prj = "", $projetaToMap = true, $shapesSel = false) { include dirname(__FILE__) . "/../ms_configura.php"; $versao = versao(); $versao = $versao["principal"]; //para manipular dbf if (file_exists($locaplic . "/pacotes/phpxbase/api_conversion.php")) { include_once $locaplic . "/pacotes/phpxbase/api_conversion.php"; } else { include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php"; } $map = @ms_newMapObj($map_file); $nameMapfile = $map->name; substituiConObj($map, $postgis_mapa); $layer = $map->getlayerbyname($tema); //e necessario abrir ou nao vai projetar $layer->open(); $prjMapa = $map->getProjection(); $prjTema = $layer->getProjection(); if ($prjTema != "") { $projInObj = new projectionObj($prjTema); $projOutObj = new projectionObj($prjMapa); } else { $projInObj = ""; $projOutObj = ""; $projetaToMap = false; } $layer->set("template", "none.htm"); $diretorio = dirname($dir_tmp); $tipol = MS_SHP_POINT; if ($layer->type == MS_LAYER_LINE) { $tipol = MS_SHP_ARC; } if ($layer->type == MS_LAYER_POLYGON) { $tipol = MS_SHP_POLYGON; } if ($nomeRand == true) { $novonomelayer = $tema . "_" . nomeRandomico(5); } else { $novonomelayer = $tema; } $novonomelayer = str_replace(".", "-", $novonomelayer); $nomeshp = $dir_tmp . "/" . $nameMapfile . "_" . $novonomelayer; if (file_exists($nomeshp . ".shp")) { return $nomeshp; } $novoshpf = ms_newShapefileObj($nomeshp, $tipol); //se for do tipo features $data = $layer->data; $resultadoFinal = true; if ($data == "") { $def[] = array("ID", "C", "50"); $reg[] = 0; if (!function_exists("dbase_create")) { $db = xbase_create($nomeshp . ".dbf", $def); xbase_add_record($db, $reg); xbase_close($db); } else { $db = dbase_create($nomeshp . ".dbf", $def); dbase_add_record($db, $reg); dbase_close($db); } if ($versao >= 6) { $shape = $layer->getshape(new resultObj(0)); } else { $s = $layer->getfeature(0, -1); $result = $layer->getResult(0); $shpi = $result->shapeindex; $shape = $layer->getfeature($shpi, -1); } $novoshpf = ms_newShapefileObj($nomeshp . ".shp", -2); $novoshpf->addShape($shape); $resultadoFinal = true; } else { if ($shapesSel == false) { $shapesSel = retornaShapesSelecionados($layer, $map_file, $map, false); } $items = pegaItens($layer); // cria o dbf $def = array(); $cni = 0; foreach ($items as $ni) { $temp = strtoupper($ni); $temp = substr($temp, 0, 8) . $cni; // //nao tem como descobrir o tamanho e tipo do campo // $def[] = array($temp, "C", "254"); $cni = $cni + 1; } if (!function_exists("dbase_create")) { $db = xbase_create($nomeshp . ".dbf", $def); } else { $db = dbase_create($nomeshp . ".dbf", $def); } $dbname = $nomeshp . ".dbf"; $reg = array(); $novoshpf = ms_newShapefileObj($nomeshp . ".shp", -2); $res_count = count($shapesSel); if ($res_count > 0) { for ($i = 0; $i < $res_count; ++$i) { $shape = $shapesSel[$i]; if ($projetaToMap == true) { $shape->project($projInObj, $projOutObj); } foreach ($items as $ni) { $vreg = $shape->values[$ni]; if (strlen($vreg) > 255) { $vreg = substr($vreg, 0, 255); } $reg[] = $vreg; } $novoshpf->addShape($shape); if (!function_exists("dbase_create")) { xbase_add_record($db, $reg); } else { dbase_add_record($db, $reg); } $reg = array(); } if (!function_exists("dbase_create")) { xbase_close($db); } else { dbase_close($db); } // //verifica a quantidade de registros no final // if (function_exists("dbase_open")) { $db = dbase_open($nomeshp . ".dbf", 0); } else { $db = xbase_open($nomeshp . ".dbf", 0); } if (function_exists("dbase_numrecords")) { $record_numbers = dbase_numrecords($db); } else { $record_numbers = xbase_numrecords($db); } if (function_exists("dbase_close")) { dbase_close($db); } else { xbase_close($db); } if ($record_numbers != $res_count) { if (file_exists($nomeshp . ".dbf")) { unlink($nomeshp . ".dbf"); } if (file_exists($nomeshp . ".shp")) { unlink($nomeshp . ".shp"); } if (file_exists($nomeshp . ".shx")) { unlink($nomeshp . ".shx"); } if (file_exists($nomeshp . ".prj")) { unlink($nomeshp . ".prj"); } $resultadoFinal = false; } } else { $resultadoFinal = false; } } if ($resultadoFinal == false) { return false; } else { //gera o arquivo prj if ($prj != "") { gravaDados(array($prj), $nomeshp . ".prj"); } elseif ($projetaToMap == false) { $nomePrjOriginal = str_replace(".shp", ".prj", $layer->data); $nomeDestino = $nomeshp . ".prj"; if (file_exists($nomePrjOriginal) && !file_exists($nomeDestino)) { copy($nomePrjOriginal, $nomeDestino); } } return $nomeshp; } }
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); }
include_once dirname(__FILE__) . "/../safe.php"; verificaBlFerramentas(basename(dirname(__FILE__)), $i3geoBlFerramentas, false); if ($statusFerramentas["melhorcaminho"] != true) { exit; } // //faz a busca da função que deve ser executada // $retorno = ""; //string que será retornada ao browser via JSON switch (strtoupper($funcao)) { case "SHAPE2PONTOS": $mapa = ms_newMapObj($map_file); $layer = $mapa->getlayerbyname($tema); $shapes = retornaShapesSelecionados($layer, $map_file, $mapa); if (count($shapes) == 0) { $shapes = retornaShapesMapext($layer, $mapa); } //quando ponto 0 if ($layer->type == 0) { $objLine = $shapes[0]->line(0); $pontoA = $objLine->point(0); $objLine = $shapes[count($shapes) - 1]->line(0); $pontoB = $objLine->point(0); } //quando linha 1 if ($layer->type == 1) { $objLine = $shapes[0]->line(0); $pontoA = $objLine->point(0); $pontoB = $objLine->point($objLine->numpoints - 1);
function listaPontosShapeSel() { //error_reporting(0); if (!$this->layer) { return "erro"; } $this->layer->set("template", "none.htm"); $this->layer->setfilter(""); $shapes = retornaShapesSelecionados($this->layer, $this->arquivo, $this->mapa); $xy = array(); foreach ($shapes as $shape) { $nlinhas = $shape->numlines; for ($j = 0; $j < $nlinhas; ++$j) { $lin = $shape->line($j); $npontos = $lin->numpoints; for ($k = 0; $k < $npontos; ++$k) { $pt = $lin->point($k); $xy[] = array("x" => $pt->x, "y" => $pt->y); } } } $fechou = $this->layer->close(); return $xy; }
function estatDescritivas($item, $exclui) { if (!$this->layer) { return "erro"; } $this->layer->set("template", "none.htm"); $items = pegaItens($this->layer, $this->mapa); $valores = array(); $filtro = $this->layer->getfilterstring(); if ($filtro != "") { $this->layer->setfilter(""); } //le o arquivo de query se existir e checa se existe seleção para o tema $shapes = retornaShapesSelecionados($this->layer, $this->arquivo, $this->mapa); if (count($shapes) == 0) { $shapes = retornaShapesMapext($this->layer, $this->mapa); } //pega os valores foreach ($shapes as $shape) { $v = $shape->values[$item]; $valores[] = $v; } $fechou = $this->layer->close(); $valoresn = array(); //verifica se a lista de valores contem numeros e exclusao foreach ($valores as $valor) { if (is_numeric($valor)) { if ($exclui != "") { if ($valor != $exclui) { $valoresn[] = $valor; } } else { $valoresn[] = $valor; } } } if (count($valoresn) == 0) { return "erro. Nenhum valor valido"; } //faz os calculos if (file_exists($this->locaplic . "/classe_estatistica.php")) { include_once $this->locaplic . "/classe_estatistica.php"; } else { include_once "classe_estatistica.php"; } $estat = new estatistica(); $resultado = $estat->calcula($valoresn); $resultado = $estat->resultado; $indice = $estat->indice; if ($resultado['min'] == "") { return "erro. Nenhum valor valido"; } $chaves = array_keys($indice); return array("indices" => $chaves, "variaveis" => $indice, "valores" => $resultado); }