Commit 5faef42eb74f8af67eba360e47e7bd8f2ef57d64
1 parent
fae8e969
Exists in
master
and in
7 other branches
Adaptação da biblioteca TME para funcionamento no i3Geo
Showing
3 changed files
with
306 additions
and
3 deletions
Show diff stats
pacotes/tme/TME_Engine.php
... | ... | @@ -352,7 +352,7 @@ class ThematicMap |
352 | 352 | . " </Style>" . PHP_EOL; // End of shared style |
353 | 353 | |
354 | 354 | $kmlFolder = " <Folder>" . PHP_EOL |
355 | - . " <name>Years</name>" . PHP_EOL | |
355 | + . " <name>Colunas</name>" . PHP_EOL | |
356 | 356 | . " <open>1</open>" . PHP_EOL; |
357 | 357 | |
358 | 358 | if ($this->timeType == 'series') { |
... | ... | @@ -597,7 +597,7 @@ class ThematicMap |
597 | 597 | |
598 | 598 | // Add title |
599 | 599 | $kml .= " <ScreenOverlay>" . PHP_EOL |
600 | - . " <name>Title</name>" . PHP_EOL | |
600 | + . " <name>Título</name>" . PHP_EOL | |
601 | 601 | . " <Icon>" . PHP_EOL |
602 | 602 | . " <href>files/brand.png</href>" . PHP_EOL |
603 | 603 | . " </Icon>" . PHP_EOL |
... | ... | @@ -609,7 +609,7 @@ class ThematicMap |
609 | 609 | // Add legend |
610 | 610 | if ($this->showLegend && $this->colourType == 'scale') { |
611 | 611 | $kml .= " <ScreenOverlay>" . PHP_EOL |
612 | - . " <name>Legend</name>" . PHP_EOL | |
612 | + . " <name>Legenda</name>" . PHP_EOL | |
613 | 613 | . " <Icon>" . PHP_EOL |
614 | 614 | . " <href>files/legend.png</href>" . PHP_EOL |
615 | 615 | . " </Icon>" . PHP_EOL | ... | ... |
... | ... | @@ -0,0 +1,59 @@ |
1 | +<?php | |
2 | +// | |
3 | +// SOFTWARE NAME: Thematic Mapping Engine | |
4 | +// SOFTWARE RELEASE: 1.6 | |
5 | +// COPYRIGHT NOTICE: Copyright (C) 2008 Bjorn Sandvik, | |
6 | +// bjorn@thematicmapping.org | |
7 | +// SOFTWARE LICENSE: GNU General Public License version 3 (GPLv3) | |
8 | +// NOTICE: > | |
9 | +// This program is free software; you can redistribute it and/or | |
10 | +// modify it under the terms of version 3 of the GNU General | |
11 | +// Public License as published by the Free Software Foundation. | |
12 | +// | |
13 | +// This program is distributed in the hope that it will be useful, | |
14 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | +// GNU General Public License for more details. | |
17 | +// http://www.gnu.org/licenses/ | |
18 | +// | |
19 | +// | |
20 | +//adaptado para o i3Geo por Edmar Moretti | |
21 | + | |
22 | +// This file shows how maps can be created with the DataConnector | |
23 | +// and ThematicMap classes. | |
24 | + | |
25 | + | |
26 | +// Can be changed to another data connector class | |
27 | +require_once ('TME_i3geo_DataConnector.php'); | |
28 | + | |
29 | +// Include engine class | |
30 | +require_once ('TME_Engine.php'); | |
31 | +if(!isset($_GET["sid"])) | |
32 | +{echo "Erro. Acesso não permitido";exit;} | |
33 | +$dataConnector = new DataConnector($_GET["sid"]); | |
34 | +$colunas = str_replace(","," ",$_GET["colunasvalor"]); | |
35 | +$colunas = explode(" ",$colunas); | |
36 | +$dataStore = $dataConnector->getDataStore($_GET["nomelayer"],$colunas,$_GET["colunanomeregiao"],$_GET["ext"],$_GET["titulo"],$_GET["descricao"]); | |
37 | +//choropleth,prism,bar,symbol | |
38 | +$ano = ""; | |
39 | +$tipo = "slider"; | |
40 | +if(count($colunas) == 1){ | |
41 | + $ano = $colunas[0]; | |
42 | + $tipo = "year"; | |
43 | +} | |
44 | + | |
45 | +$parameters = array( 'mapType' => 'bar', | |
46 | + 'indicator' => 'valores', | |
47 | + 'year' => $ano, | |
48 | + 'classification' => 'equal', | |
49 | + 'mapTitle' => 'Título do Mapa', | |
50 | + 'timeType' => $tipo //para mais de um ano, escolha slider ou series | |
51 | + ); | |
52 | + | |
53 | +// Create thematic map object | |
54 | +$map = new ThematicMap($dataStore, $parameters); | |
55 | +$file = $map->getKML(); | |
56 | + | |
57 | +echo "<p><a href='$file'>$file</a>"; | |
58 | + | |
59 | +?> | |
0 | 60 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,244 @@ |
1 | +<?php | |
2 | +// | |
3 | +// SOFTWARE NAME: Thematic Mapping Engine | |
4 | +// SOFTWARE RELEASE: 1.6 | |
5 | +// COPYRIGHT NOTICE: Copyright (C) 2008 Bjorn Sandvik, | |
6 | +// bjorn@thematicmapping.org | |
7 | +// SOFTWARE LICENSE: GNU General Public License version 3 (GPLv3) | |
8 | +// NOTICE: > | |
9 | +// This program is free software; you can redistribute it and/or | |
10 | +// modify it under the terms of version 3 of the GNU General | |
11 | +// Public License as published by the Free Software Foundation. | |
12 | +// | |
13 | +// This program is distributed in the hope that it will be useful, | |
14 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | +// GNU General Public License for more details. | |
17 | +// http://www.gnu.org/licenses/ | |
18 | +// | |
19 | +//adaptado para o i3Geo por Edmar Moretti | |
20 | + | |
21 | + | |
22 | + | |
23 | +// Set database access information as constants | |
24 | +// Should be stored outside of the Web directory | |
25 | +//DEFINE ('DB_USER', 'myuser'); | |
26 | +//DEFINE ('DB_PASSWORD', 'mypass'); | |
27 | +//DEFINE ('DB_HOST', 'localhost'); | |
28 | +//DEFINE ('DB_NAME', 'tme'); | |
29 | + | |
30 | + | |
31 | +class DataConnector | |
32 | +{ | |
33 | + public $featureTable = 'country_simpl'; | |
34 | + public $indicatorTable = 'indicator'; | |
35 | + public $valuesTable = 'indicator_values'; | |
36 | + public $map_file; | |
37 | + public $postgis_mapa; | |
38 | + private $dbc; | |
39 | + | |
40 | + // Constructor | |
41 | + function __construct($sid) | |
42 | + { | |
43 | + if (!function_exists('ms_GetVersion')) | |
44 | + { | |
45 | + if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) | |
46 | + { | |
47 | + if(!@dl('php_mapscript_48.dll')) | |
48 | + dl('php_mapscript.dll'); | |
49 | + } | |
50 | + else | |
51 | + {dl('php_mapscript.so');} | |
52 | + } | |
53 | + include("../../classesphp/carrega_ext.php"); | |
54 | + //verificação de segurança | |
55 | + $_SESSION = array(); | |
56 | + session_name("i3GeoPHP"); | |
57 | + session_id($sid); | |
58 | + session_start(); | |
59 | + if(@$_SESSION["fingerprint"]) | |
60 | + { | |
61 | + $f = explode(",",$_SESSION["fingerprint"]); | |
62 | + if (md5('I3GEOSEC' . $_SERVER['HTTP_USER_AGENT'] . session_id()) != $f[0] && !in_array($_GET["telaR"],$f) ) | |
63 | + {exit;} | |
64 | + } | |
65 | + else | |
66 | + {exit;} | |
67 | + if(!isset($_SESSION["map_file"])) | |
68 | + {exit;} | |
69 | + $this->map_file = $_SESSION["map_file"]; | |
70 | + $this->postgis_mapa = $_SESSION["postgis_mapa"]; | |
71 | + } | |
72 | + // Fetch all indicators | |
73 | + function getIndicators(){ | |
74 | + $sql = 'SELECT id, name, description, source FROM indicator ORDER BY name'; | |
75 | + $result = $this->dbc->query($sql); | |
76 | + | |
77 | + // Loop thorough all indicators | |
78 | + while($row = $result->fetch_row()) | |
79 | + { | |
80 | + // Add values to array | |
81 | + $indicators[] = array('id' => $row[0], | |
82 | + 'name' => $row[1], | |
83 | + 'description' => $row[2], | |
84 | + 'source' => $row[3]); | |
85 | + } | |
86 | + | |
87 | + // Make JSON encoded array | |
88 | + $json = json_encode(array('indicators' => $indicators)); | |
89 | + return $json; | |
90 | + } | |
91 | + | |
92 | + // Fetch all avaialbe years for one indicator | |
93 | + function getIndicatorYears($indicatorID){ | |
94 | + $sql = "SELECT DISTINCT year FROM indicator_values WHERE variable=$indicatorID ORDER BY year"; | |
95 | + $result = $this->dbc->query($sql); | |
96 | + | |
97 | + // Loop thorough all years | |
98 | + while($row = $result->fetch_row()) | |
99 | + { | |
100 | + // Add values to array | |
101 | + $years[] = array('year' => $row[0]); | |
102 | + } | |
103 | + // Make JSON encoded array | |
104 | + $json = json_encode(array('years' => $years)); | |
105 | + return $json; | |
106 | + } | |
107 | + | |
108 | + // Make data store | |
109 | + function getDataStore($nomelayer,$colunasvalor,$colunanomeregiao,$ext,$titulo,$descricao){ //$indicatorID, $year, $region){ | |
110 | + include("../../classesphp/funcoes_gerais.php"); | |
111 | + $versao = versao(); | |
112 | + $versao = $versao["principal"]; | |
113 | + $mapa = ms_newMapObj($this->map_file); | |
114 | + $layer = $mapa->getlayerbyname($nomelayer); | |
115 | + if($ext && $ext != ""){ | |
116 | + $e = explode(" ",$ext); | |
117 | + $extatual = $mapa->extent; | |
118 | + $extatual->setextent((min($e[0],$e[2])),(min($e[1],$e[3])),(max($e[0],$e[2])),(max($e[1],$e[3]))); | |
119 | + } | |
120 | + $layer->set("template","none.html"); | |
121 | + $existesel = "nao"; | |
122 | + if (($this->postgis_mapa != "") && ($this->postgis_mapa != " ")) | |
123 | + { | |
124 | + if ($layer->connectiontype == MS_POSTGIS) | |
125 | + { | |
126 | + $lcon = $layer->connection; | |
127 | + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($this->postgis_mapa)))) | |
128 | + { | |
129 | + if(($lcon == " ") || ($lcon == "")) | |
130 | + {$layer->set("connection",$this->postgis_mapa);} | |
131 | + else | |
132 | + {$layer->set("connection",$this->postgis_mapa[$lcon]);} | |
133 | + } | |
134 | + } | |
135 | + } | |
136 | + $itens = pegaItens($layer,$mapa); | |
137 | + carregaquery2($this->map_file,$layer,$mapa); | |
138 | + if ($layer->getNumresults() > 0){$existesel = "sim";} | |
139 | + if ($existesel == "nao") | |
140 | + {$layer->querybyrect($mapa->extent);} | |
141 | + $layer->open(); | |
142 | + $res_count = $layer->getNumresults(); | |
143 | + $dataStore = array(); | |
144 | + $dataStore['indicators']['valores'] = array( | |
145 | + "name"=>$titulo, | |
146 | + "description"=>$descricao, | |
147 | + "source"=>"", | |
148 | + "decimals"=>2, | |
149 | + "max"=>0, | |
150 | + "min"=>0 | |
151 | + ); | |
152 | + for ($i = 0; $i < $res_count; $i++) | |
153 | + { | |
154 | + $valitem = array(); | |
155 | + if($versao == 6) | |
156 | + {$shape = $layer->getShape($layer->getResult($i));} | |
157 | + else{$shape = $layer->getFeature($layer->getResult($i)->shapeindex);} | |
158 | + $pt = $shape->getCentroid(); | |
159 | + $dataStore['features'][$i] = array( | |
160 | + "featureID"=>$i, | |
161 | + "name"=>$shape->values[$colunanomeregiao], | |
162 | + "lon"=>$pt->x, | |
163 | + "lat"=>$pt->y, | |
164 | + "wkt"=>$shape->toWkt() | |
165 | + ); | |
166 | + //[0] é o ano | |
167 | + foreach($colunasvalor as $colunavalor){ | |
168 | + $valor = number_format($shape->values[$colunavalor], 2, '.', ''); | |
169 | + $dataStore['indicators']['valores']['values'][$colunavalor][$i] = $valor; | |
170 | + $indicatorYears[$colunavalor] = $colunavalor; | |
171 | + $todosV[] = $valor; | |
172 | + } | |
173 | + } | |
174 | + $fechou = $layer->close(); | |
175 | + $dataStore['indicators']['valores']['years'] = $indicatorYears; | |
176 | + $dataStore['indicators']['valores']['max'] = max($todosV); | |
177 | + $dataStore['indicators']['valores']['min'] = min($todosV); | |
178 | + echo "<pre>"; | |
179 | + var_dump($dataStore); | |
180 | + return $dataStore; | |
181 | + /* | |
182 | + $sqlregion = ''; | |
183 | + if ($region) $sqlregion = "region = $region AND"; | |
184 | + $sqlyear = ''; | |
185 | + if ($year) $sqlyear = "AND year = $year"; | |
186 | + // Add features - exclude Antarctica | |
187 | + $sql = "SELECT un AS featureID, name, lon, lat, AsText(geom) AS wkt | |
188 | + FROM $this->featureTable | |
189 | + WHERE $sqlregion un != 10 | |
190 | + ORDER BY featureID"; | |
191 | + | |
192 | + $features = $this->dbc->query($sql); | |
193 | + while($row = $features->fetch_array(MYSQLI_ASSOC)) | |
194 | + { | |
195 | + // First field should be feature id | |
196 | + $featureID = array_shift($row); | |
197 | + // Add feature to dataStore | |
198 | + $dataStore['features'][$featureID] = $row; | |
199 | + } | |
200 | + | |
201 | + | |
202 | + $indicatorYears = array(); | |
203 | + | |
204 | + // Select indicator metadata | |
205 | + $sql = "SELECT name, description, source, decimals, | |
206 | + (SELECT ROUND(MAX(value),decimals) FROM indicator_values, $this->featureTable WHERE variable=$indicatorID AND indicator_values.area=un $sqlyear) AS max, | |
207 | + (SELECT ROUND(MIN(value),decimals) FROM indicator_values, $this->featureTable WHERE variable=$indicatorID AND indicator_values.area=un $sqlyear) AS min | |
208 | + FROM $this->indicatorTable | |
209 | + WHERE id=$indicatorID"; | |
210 | + | |
211 | + $result = $this->dbc->query($sql); | |
212 | + $indicator = $result->fetch_assoc(); | |
213 | + $precision = $indicator['decimals']; | |
214 | + | |
215 | + // Add indicator to dataStore | |
216 | + $dataStore['indicators'][$indicatorID] = $indicator; | |
217 | + | |
218 | + // Select indicator values (only values that have features) | |
219 | + $sql = "SELECT indvalues.area AS featureID, indvalues.year, indvalues.value | |
220 | + FROM $this->valuesTable AS indvalues, $this->featureTable | |
221 | + WHERE indvalues.variable=$indicatorID | |
222 | + AND indvalues.area=un | |
223 | + $sqlyear | |
224 | + ORDER BY indvalues.value"; // Needed for qunatiles calculation | |
225 | + | |
226 | + $result = $this->dbc->query($sql); | |
227 | + | |
228 | + // Add indicator values to dataStore | |
229 | + while($row = $result->fetch_row()) | |
230 | + { | |
231 | + $dataStore['indicators'][$indicatorID]['values'][$row[1]][$row[0]] = number_format($row[2], $precision, '.', ''); | |
232 | + | |
233 | + // Find all years with values (could also be a separate sql for better performance) | |
234 | + $indicatorYears[$row[1]] = $row[1]; | |
235 | + } | |
236 | + sort($indicatorYears); | |
237 | + $dataStore['indicators'][$indicatorID]['years'] = $indicatorYears; | |
238 | + return $dataStore; | |
239 | + */ | |
240 | + } | |
241 | +} | |
242 | + | |
243 | + | |
244 | +?> | |
0 | 245 | \ No newline at end of file | ... | ... |