コード例 #1
0
 function getDataStore($nomelayer, $colunasvalor, $colunanomeregiao, $titulo, $descricao, $ext = "", $mapType = "")
 {
     //$indicatorID, $year, $region){
     if (!function_exists("versao")) {
         include dirname(__FILE__) . "/../../classesphp/funcoes_gerais.php";
     }
     $versao = versao();
     $versao = $versao["principal"];
     $mapa = ms_newMapObj($this->map_file);
     if ($ext == "") {
         $mapa = extPadrao($mapa);
     } else {
         $e = str_replace(",", " ", $ext);
         $e = explode(" ", $ext);
         $extatual = $mapa->extent;
         $extatual->setextent(min($e[0], $e[2]), min($e[1], $e[3]), max($e[0], $e[2]), max($e[1], $e[3]));
     }
     $layer = $mapa->getlayerbyname($nomelayer);
     $layer->set("template", "none.html");
     $existesel = "nao";
     if ($this->postgis_mapa != "" && $this->postgis_mapa != " ") {
         if ($layer->connectiontype == MS_POSTGIS) {
             $lcon = $layer->connection;
             if ($lcon == " " || $lcon == "" || in_array($lcon, array_keys($this->postgis_mapa))) {
                 if ($lcon == " " || $lcon == "") {
                     $layer->set("connection", $this->postgis_mapa);
                 } else {
                     $layer->set("connection", $this->postgis_mapa[$lcon]);
                 }
             }
         }
     }
     $itens = pegaItens($layer, $mapa);
     carregaquery2($this->map_file, $layer, $mapa);
     if ($layer->getNumresults() > 0) {
         $existesel = "sim";
     }
     if ($existesel == "nao") {
         $layer->querybyrect($mapa->extent);
     }
     $layer->open();
     $res_count = $layer->getNumresults();
     $dataStore = array();
     $dataStore['indicators']['valores'] = array("name" => $titulo, "description" => $descricao, "source" => "", "decimals" => 2, "max" => 0, "min" => 0);
     for ($i = 0; $i < $res_count; $i++) {
         $valitem = array();
         if ($versao >= 6) {
             $shape = $layer->getShape($layer->getResult($i));
         } else {
             $shape = $layer->getFeature($layer->getResult($i)->shapeindex);
         }
         $pt = $shape->getCentroid();
         $texto = $shape->values[$colunanomeregiao];
         /*
         if(!mb_detect_encoding($texto,"ISO-8859-1",true)){
         	$texto = mb_convert_encoding($texto,"ISO-8859-1","UTF-8");
         }
         */
         if ($mapType == "bar") {
             $wkt = "";
         } else {
             $wkt = $shape->toWkt();
         }
         $dataStore['features'][$i] = array("featureID" => $i, "name" => $texto, "lon" => round($pt->x, 6), "lat" => round($pt->y, 6), "wkt" => $wkt);
         //[0] � o ano
         foreach ($colunasvalor as $colunavalor) {
             $valor = $shape->values[$colunavalor];
             settype($valor, "float");
             //echo $valor;
             if (is_numeric($valor)) {
                 $valor = number_format($valor, 2, '.', '');
                 $dataStore['indicators']['valores']['values'][$colunavalor][$i] = $valor;
                 $indicatorYears[$colunavalor] = $colunavalor;
                 $todosV[] = $valor;
             }
         }
     }
     $fechou = $layer->close();
     $dataStore['indicators']['valores']['years'] = $indicatorYears;
     $dataStore['indicators']['valores']['max'] = max($todosV);
     $dataStore['indicators']['valores']['min'] = min($todosV);
     //echo "<pre>";
     //var_dump($dataStore);
     return $dataStore;
     /*
     $sqlregion = '';
             if ($region) $sqlregion = "region = $region AND";
             $sqlyear = '';
             if ($year) $sqlyear = "AND year = $year";
         	// Add features - exclude Antarctica
         	$sql = "SELECT un AS featureID, name, lon, lat, AsText(geom) AS wkt
                     FROM $this->featureTable
                     WHERE $sqlregion un != 10
                     ORDER BY featureID";
     
         	$features = $this->dbc->query($sql);
         	while($row = $features->fetch_array(MYSQLI_ASSOC))
         	{
         		// First field should be feature id
         		$featureID = array_shift($row);
         		// Add feature to dataStore
         		$dataStore['features'][$featureID] = $row;
         	}
     
     
         		$indicatorYears = array();
     
                 // Select indicator metadata
         		$sql = "SELECT name, description, source, decimals,
                             (SELECT ROUND(MAX(value),decimals) FROM indicator_values, $this->featureTable WHERE variable=$indicatorID AND indicator_values.area=un $sqlyear) AS max,
                             (SELECT ROUND(MIN(value),decimals) FROM indicator_values, $this->featureTable WHERE variable=$indicatorID AND indicator_values.area=un $sqlyear) AS min
                         FROM $this->indicatorTable
                         WHERE id=$indicatorID";
     
         		$result = $this->dbc->query($sql);
         		$indicator = $result->fetch_assoc();
         		$precision = $indicator['decimals'];
     
         		// Add indicator to dataStore
         		$dataStore['indicators'][$indicatorID] = $indicator;
     
         		// Select indicator values (only values that have features)
         		$sql = "SELECT indvalues.area AS featureID, indvalues.year, indvalues.value
                         FROM $this->valuesTable AS indvalues, $this->featureTable
                         WHERE indvalues.variable=$indicatorID
                         AND indvalues.area=un
                         $sqlyear
                         ORDER BY indvalues.value"; // Needed for qunatiles calculation
     
                 $result = $this->dbc->query($sql);
     
         		// Add indicator values to dataStore
         		while($row = $result->fetch_row())
         		{
                     $dataStore['indicators'][$indicatorID]['values'][$row[1]][$row[0]] = number_format($row[2], $precision, '.', '');
     
                     // Find all years with values (could also be a separate sql for better performance)
                     $indicatorYears[$row[1]] = $row[1];
         		}
                 sort($indicatorYears);
         		$dataStore['indicators'][$indicatorID]['years'] = $indicatorYears;
         	return $dataStore;
     */
 }
コード例 #2
0
 function buscaRegistros($palavra, $lista, $tipo, $onde)
 {
     //error_reporting(0);
     $resultado = array();
     if ($onde == "mapa") {
         $this->mapa = extPadrao($this->mapa);
     }
     $ptvs = explode("|", $lista);
     //monta a lista de temas que serao utilizados
     foreach ($ptvs as $p) {
         $pp = explode(",", $p);
         $temas[] = $pp[1];
     }
     $temas = array_unique($temas);
     //monta a lista de itens por tema
     foreach ($temas as $tema) {
         $temp = array();
         foreach ($ptvs as $p) {
             $pp = explode(",", $p);
             if ($pp[1] == $tema) {
                 $temp[] = $pp[0];
             }
             $temasi[$tema] = $temp;
         }
     }
     $encontrado = "nao";
     $palavra = trim($palavra);
     foreach ($temas as $tema) {
         $registros = array();
         $items = $temasi[$tema];
         $l = $this->mapa->getlayerbyname($tema);
         $this->layer = $l;
         $l->set("template", "none.htm");
         if ($l->data == "") {
             return "Erro. O tema n&atilde;o tem tabela";
         }
         if (strtoupper($l->getmetadata("convcaracter")) == "NAO") {
             $convC = false;
         } else {
             $convC = true;
         }
         $filtro = $l->getfilterstring();
         if ($filtro != "") {
             $l->setfilter("");
         }
         $sopen = $l->open();
         if ($sopen == MS_FAILURE) {
             return "erro";
         }
         $l->close();
         $ret = $this->mapa->extent;
         $fr = array();
         if (@$l->queryByrect($ret) == MS_SUCCESS) {
             $l->open();
             $res_count = $l->getNumresults();
             $palavra = $this->remove_accents(strtolower($palavra));
             for ($i = 0; $i < $res_count; ++$i) {
                 $valitem = array();
                 if ($this->v >= 6) {
                     $shape = $l->getShape($l->getResult($i));
                     $indx = $shape->index;
                 } else {
                     $result = $l->getResult($i);
                     $indx = $result->shapeindex;
                     $shape = $l->getfeature($indx, -1);
                 }
                 $novoreg = array();
                 $r = array();
                 foreach ($items as $item) {
                     $v = trim($shape->values[$item]);
                     $nv = $this->remove_accents(strtolower($v));
                     //echo $v." - ".$nv."<br>";
                     if ($tipo == "exata") {
                         if ($nv == $palavra) {
                             if ($convC == true) {
                                 $v = $this->converte($v);
                             }
                             $r[] = array("item" => $item, "valor" => $v);
                             $encontrado = "sim";
                         }
                     } else {
                         if (stristr($nv, $palavra)) {
                             if ($convC == true) {
                                 $v = $this->converte($v);
                             }
                             $r[] = array("item" => $item, "valor" => $v);
                             $encontrado = "sim";
                         }
                     }
                 }
                 if ($encontrado == "sim") {
                     $ret = $this->extensaoShape($shape, $l);
                     /*
                      if (($prjTema != "") && ($prjMapa != $prjTema)){
                     $ret->project($projInObj, $projOutObj);
                     }
                     */
                     $novoreg["box"] = $ret;
                     $novoreg["valores"] = $r;
                     $encontrado = "nao";
                     $fr[] = $novoreg;
                 }
             }
             $resultado[] = array("tema" => $tema, "resultado" => $fr);
         }
     }
     return $resultado;
 }