exec.php
7.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
if(empty($_GET)){
echo "
Esse programa gera um arquivo gif a partir de uma camada existente em i3geo/temas <br>
O arquivo gif é gerado na pasta temporária e reaproveitado como cache <br>
<br>Parâmetros: <br>
&tema = código do tema (mapfile) existente em i3geo/temas<br>
&colunat = coluna da tabela de atributos do tema que contém o período.
Essa coluna será utilizada para gerar o filtro para o desenho de cada frame que comporá o gif<br>
&tempo = tempo em milisegundos entre cada frame<br>
&w = largura da imagem em pixels<br>
&h = altura da imagem em pixels<br>
&cache = sim|nao utiliza cache do arquivo gif?<br>
&mapext = extensão geográfica xmin,ymin,xmax,ymax que será usada nas imagens<br>
&legenda = sim|nao<br>
&transparente = sim|nao<br>
";
exit;
}
//http://localhost:8014/i3geo/ferramentas/animagif/exec.php?transparente=nao&legenda=sim&tema=dengue_casos_provaveis&colunat=semana_ano_epidemiologico&w=500&h=500&mapext=-74%20-32%20-34%204
include("../../ms_configura.php");
include("../../classesphp/funcoes_gerais.php");
include("../../classesphp/pega_variaveis.php");
include("../../classesphp/carrega_ext.php");
if($cache == "nao"){
$nometemp = nomeRandomico();
} else {
$nometemp = md5(implode("",$_GET));
}
if(empty($tempo)){
$tempo = 40;
}
$arqtemp = $dir_tmp."/".$nometemp;
if(file_exists($arqtemp.".gif")){
$gifBinary = file_get_contents($arqtemp.".gif");
//retorna o gif para o navegador
header('Content-type: image/gif');
header('Content-Disposition: filename="'.$tema.'.gif"');
echo $gifBinary;
exit;
}
//
//carrega o phpmapscript
//
if (!function_exists('ms_GetVersion'))
{
if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
{
if(!@dl('php_mapscript_48.dll'))
dl('php_mapscript.dll');
}
else
{dl('php_mapscript.so');
}
}
$versao = versao();
$versao = $versao["principal"];
//cria um mapa temporario
if($base == "" or !isset($base)){
$base = "";
if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')){
$base = $locaplic."/aplicmap/geral1windowsv".$versao.".map";
}
else{
if($base == "" && file_exists('/var/www/i3geo/aplicmap/geral1debianv'.$versao.'.map')){
$base = "/var/www/i3geo/aplicmap/geral1debianv".$versao.".map";
}
if($base == "" && file_exists('/var/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){
$base = "/var/www/html/i3geo/aplicmap/geral1fedorav".$versao.".map";
}
if($base == "" && file_exists('/opt/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){
$base = "/opt/www/html/i3geo/aplicmap/geral1v".$versao.".map";
}
if($base == ""){
$base = $locaplic."/aplicmap/geral1v".$versao.".map";
}
}
}
else{
if(!file_exists($base)){
$base = $locaplic."/aplicmap/".$base;
}
}
$mapa = ms_newMapObj($base);
//remove as camadas do mapa base
$numlayers = $mapa->numlayers;
for ($i=0;$i < $numlayers;$i++){
$layern = $mapa->getlayer($i);
if($layern->name != "copyright"){
$layern->set("status",MS_DELETE);
}
else{
$layern->set("status",MS_DEFAULT);
}
}
//ajusta o label
$l = $mapa->getlayerbyname("copyright");
if($l != ""){
$classe = $l->getclass(0);
$label = $classe->getLabel(0);
$label->updatefromstring("LABEL TYPE TRUETYPE END");
$label->set("font","arial");
$label->set("size",15);
$label->updatefromstring("LABEL POSITION lr END");
$label->updatefromstring('LABEL STYLE GEOMTRANSFORM "labelpoly" COLOR 255 255 255 END END');
}
//
$mapa->save($arqtemp.".map");
//adiciona ao mapa base as camadas do mapfile indicado em $tema
$nmapa = ms_newMapObj($locaplic."/temas/".$tema.".map");
$numlayers = $nmapa->numlayers;
for ($i=0;$i < $numlayers;$i++){
$layern = $nmapa->getlayer($i);
$layern->set("status",MS_DEFAULT);
if (!empty($postgis_mapa)){
if ($layern->connectiontype == MS_POSTGIS){
$lcon = $layern->connection;
error_reporting(0);
if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
if(($lcon == " ") || ($lcon == "")){
$layern->set("connection",$postgis_mapa);
}
else{
$layern->set("connection",$postgis_mapa[$lcon]);
}
}
}
}
autoClasses($layern,$nmapa);
cloneInlineSymbol($layern,$nmapa,$mapa);
ms_newLayerObj($mapa, $layern);
}
$mapa->save($arqtemp.".map");
//aplica a extensao geografica
$layer = $mapa->getlayerbyname($tema);
$extatual = $mapa->extent;
$ret = "";
if(isset($mapext)){
$ret = str_replace(","," ",$mapext);
}
else{
$ret = $layer->getmetadata("extensao");
}
if ($ret != ""){
$ret = explode(" ",$ret);
$extatual->setextent($ret[0],$ret[1],$ret[2],$ret[3]);
}
$mapa->setsize($w,$h);
$sca = $mapa->scalebar;
$sca->set("status",MS_OFF);
if($legenda == "sim"){
$leg = $mapa->legend;
$leg->set("status",MS_EMBED);
$cor = $leg->imagecolor;
$cor->setrgb(250,250,250);
$labelleg = $leg->label;
//$labelleg->set("type",MS_TRUETYPE);
//$labelleg->set("font","arial");
$labelleg->set("size",10);
//$leg->set("keyspacingy",10);
$layer = $mapa->getlayerbyname($tema);
$nclass = $layer->numclasses;
for($i=0;$i<$nclass;$i++){
$classe = $layer->getclass($i);
if($classe->title === ""){
$classe->title = $classe->name;
}
}
}
$c = $mapa->imagecolor;
$c->setrgb(-1,-1,-1);
$o = $mapa->outputformat;
$o->set("imagemode",MS_IMAGEMODE_RGBA);
if($transparente == "sim"){
$o->set("transparent",MS_TRUE);
}
$mapa->save($arqtemp.".map");
$mapa = ms_newMapObj($arqtemp.".map");
if(validaAcessoTemas($arqtemp.".map",false) == true){
echo "Existem temas restritos";exit;
}
//pega a lista de valores unicos da $colunat
include_once("../../classesphp/classe_atributos.php");
$m = new Atributos($arqtemp.".map",$tema);
$lista = $m->listaRegistros($colunat,"mapa","sim",0,"","tudo","nao");
$lista = $lista[1]["registros"];
$listaunica = array();
foreach($lista as $l){
$v = $l["valores"][0]["valor"];
if($v != ""){
$listaunica[] = $v;
}
}
sort($listaunica);
//cria as imagens para cada periodo
$layer = $mapa->getlayerbyname($tema);
$l = $mapa->getlayerbyname("copyright");
if($l != ""){
$c = $l->getclass(0);
$label = $c->getLabel(0);
}
$imagens = array();
$duracao = array();
$objImagem = "";
//$listaunica = array($listaunica[1]);
foreach($listaunica as $d){
if(strtoupper($colunat) == $colunat){
$filtro = "(('[$colunat]' = '$d'))";
}
else{
$filtro = "$colunat = '$d'";
}
$layer->setfilter($filtro);
//$mapa->save($arqtemp.".map");echo $arqtemp;exit;
$nomec = $arqtemp.$d.".png";
$s = "LABEL TEXT '".$d."' END";
if($l != ""){
$label->updateFromString($s);
}
if($objImagem == ""){
$objImagem = $mapa->draw();
$objImagem->saveImage($nomec);
}
else{
$i = $mapa->draw();
$objImagem->pasteImage($i,-1);
$objImagem->saveImage($nomec);
}
$imagens[] = $nomec;
$duracao[] = $tempo;
}
//junta as imagens no gif
include("../../pacotes/gifcreator/GifCreator.php");
$gc = new GifCreator();
$gc->create($imagens, $duracao, 0);
$gifBinary = $gc->getGif();
file_put_contents($arqtemp.".gif", $gifBinary);
//retorna o gif para o navegador
header('Content-type: image/gif');
header('Content-Disposition: filename="'.$tema.'.gif"');
echo $gifBinary;
exit;
?>