mapa_googleearth.php
10.1 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
/*
Title: mapa_googleearth.php
Faz o processamento de um mapfile segundo as necessidades do i3geo, como por exemplo, fazendo a substituição
das variáveis de conexão com banco e outras operações específicas do i3Geo.
É utilizado especificamente nas interfaces que utilizam a biblioteca Google Earth.
Licenca:
GPL2
i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet
Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil
Desenvolvedor: Edmar Moretti edmar.moretti@gmail.com
Este programa é software livre; você pode redistribuí-lo
e/ou modificá-lo sob os termos da Licença Pública Geral
GNU conforme publicada pela Free Software Foundation;
Este programa é distribuído na expectativa de que seja útil,
porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita
de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA.
Consulte a Licença Pública Geral do GNU para mais detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral do
GNU junto com este programa; se não, escreva para a
Free Software Foundation, Inc., no endereço
59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
Arquivo:
i3geo/classesphp/mapa_googleearth.php
*/
include("sani_request.php");
//error_reporting(0);
error_reporting(0);
//para efeitos de compatibilidade
if (!function_exists('ms_GetVersion')){
include_once ("carrega_ext.php");
}
clearstatcache();
if (!function_exists('ms_GetVersion'))
{
$s = PHP_SHLIB_SUFFIX;
@dl( 'php_mapscript.'.$s );
$ler_extensoes[] = 'php_mapscript';
}
//verificação de segurança
$_SESSION = array();
session_name("i3GeoPHP");
if(@$_GET["g_sid"])
{session_id($_GET["g_sid"]);}
else
{exit;}
session_start();
if(!isset($_SESSION["map_file"]))
{exit;}
//
$map_fileX = $_SESSION["map_file"];
$postgis_mapa = $_SESSION["postgis_mapa"];
//por seguranca
include_once("funcoes_gerais.php");
restauraCon($map_fileX,$postgis_mapa);
if($_GET["REQUEST"] == "GetKml")
{retornaKml();}
else
{retornaWms($map_fileX,$postgis_mapa);}
return;
function retornaKml(){
$protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']);
//$servidor = strtolower($protocolo[0])."://".$_SERVER['HTTP_HOST'];
//$url = $servidor.'http://localhost:80/cgi-bin/mapserv.exe?map=c:/ms4w/tmp/ms_tmp/rPzBHuOtQa/rPzBHuOtQa.map&width=1500&height=1500&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4618&STYLES=&FORMAT=image/jpeg&TRANSPARENT=TRUE&layers=estadosl';
$serv = strtolower($protocolo[0]) . '://'.$_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] ? ':'.$_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'];
$url = $serv."?g_sid=".$_GET["g_sid"]."&WIDTH=1500&HEIGHT=1500&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image/png&TRANSPARENT=TRUE&layer=".$_GET["layer"]."&TIPOIMAGEM=".$_GET["TIPOIMAGEM"];
if(isset($_GET["telaR"])){
$url .= "&telaR=".$_GET["telaR"];
}
$kml = '
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<GroundOverlay>
<name>'.$_GET["layer"].'</name>
<Icon>
<href>'.$url.'</href>
<viewRefreshMode>onStop</viewRefreshMode>
<refreshMode>onChange</refreshMode>
</Icon>
<LatLonBox>
<north></north>
<south></south>
<east></east>
<west></west>
</LatLonBox>
</GroundOverlay>
</Document>
</kml>';
echo header("Content-type: application/xml");
echo $kml;
}
function retornaWms($map_fileX,$postgis_mapa){
error_reporting(0);
if(isset($_GET["bbox"]))
{$_GET["BBOX"] = $_GET["bbox"];}
if(isset($_GET["BBOX"]))
{
$_GET["mapext"] = str_replace(","," ",$_GET["BBOX"]);
$m = explode(" ",$_GET["mapext"]);
$dx = $m[0] - $m[2];
if($dx < 0){$dx = $dx * -1;}
$dy = $m[1] - $m[3];
if($dy < 0){$dy = $dy * -1;}
$_GET["HEIGHT"] = ($_GET["WIDTH"] / $dx) * $dy;
//$_GET["map_size"] = $_GET["WIDTH"]." ".$_GET["HEIGHT"];
}
$mapa = ms_newMapObj($map_fileX);
$mapa->setProjection("init=epsg:4326");
//
//resolve o problema da seleção na versão nova do mapserver
//
$qyfile = dirname($map_fileX)."/".$_GET["layer"]."_qy.map";
$qy = file_exists($qyfile);
$o = $mapa->outputformat;
$o->set("imagemode",MS_IMAGEMODE_RGBA);
if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao´e alterado
$numlayers = $mapa->numlayers;
for ($i=0;$i < $numlayers;++$i)
{
$l = $mapa->getlayer($i);
if ($l->getmetadata("classesnome") != "")
{
if(!function_exists("autoClasses"))
{include_once("funcoes_gerais.php");}
autoClasses($l,$mapa);
}
$layerName = $l->name;
if($layerName != $_GET["layer"])
{$l->set("status",MS_OFF);}
if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != "")
{
$l->set("status",MS_DEFAULT);
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]);}
}
}
}
}
$l->set("template","none.htm");
}
}
else{
$mapa->selectOutputFormat("jpeg");
$of = $mapa->outputformat;
$of->set("imagemode",MS_IMAGEMODE_RGBA);
$of->set("driver","AGG/PNG");
$of->set("transparent",MS_ON);
}
$mapa->setsize($_GET["WIDTH"],$_GET["HEIGHT"]);
if(isset($_GET["mapext"])){
$mapext = explode(" ",$_GET["mapext"]);
$mapa->setExtent($mapext[0],$mapext[1],$mapext[2],$mapext[3]);
}
if(!isset($_GET["telaR"])){
$legenda = $mapa->legend;
$legenda->set("status",MS_OFF);
$escala = $mapa->scalebar;
$escala->set("status",MS_OFF);
}
//
//se o layer não for do tipo fundo
//
if(isset($_GET["tipolayer"]) && $_GET["tipolayer"] != "fundo")
{$o->set("transparent",MS_TRUE);}
if($qy != true)
{$img = $mapa->draw();}
else
{
$handle = fopen ($qyfile, "r");
$conteudo = fread ($handle, filesize ($qyfile));
fclose ($handle);
$shp = unserialize($conteudo);
$l = $mapa->getLayerByname($_GET["layer"]);
if ($l->connectiontype != MS_POSTGIS){
$indxlayer = $l->index;
foreach ($shp as $indx)
{$mapa->querybyindex($indxlayer,-1,$indx,MS_TRUE);}
$qm = $mapa->querymap;
$qm->set("width",$map_size[0]);
$qm->set("height",$map_size[1]);
$img = $mapa->drawQuery();
}
else{
$img = $mapa->draw();
$c = $mapa->querymap->color;
$numclasses = $l->numclasses;
if ($numclasses > 0)
{
$classe0 = $l->getClass(0);
$classe0->setexpression("");
$classe0->set("name"," ");
for ($i=1; $i < $numclasses; ++$i)
{
$classe = $l->getClass($i);
$classe->set("status",MS_DELETE);
}
}
$cor = $classe0->getstyle(0)->color;
$cor->setrgb($c->red,$c->green,$c->blue);
$cor = $classe0->getstyle(0)->outlinecolor;
$cor->setrgb($c->red,$c->green,$c->blue);
$status = $l->open();
$status = $l->whichShapes($mapa->extent);
while ($shape = $l->nextShape())
{
if(in_array($shape->index,$shp))
$shape->draw($mapa,$l,$img);
}
$l->close();
}
}
if (!function_exists('imagepng'))
{
$s = PHP_SHLIB_SUFFIX;
@dl( 'php_gd.'.$s );
if (!function_exists('imagepng'))
{@dl( 'php_gd2.'.$s );}
if (!function_exists('imagepng'))
{$_GET["TIPOIMAGEM"] = "";}
}
if(isset($_GET["TIPOIMAGEM"]) && trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum")
{
if($img->imagepath == "")
{echo "Erro IMAGEPATH vazio";exit;}
$nomer = ($img->imagepath)."filtroimgtemp".nomeRandomico().".png";
$img->saveImage($nomer);
filtraImagem($nomer,$_GET["TIPOIMAGEM"]);
$img = imagecreatefrompng($nomer);
imagealphablending($img, false);
imagesavealpha($img, true);
ob_clean();
echo header("Content-type: image/png \n\n");
imagepng($img);
}
else{
ob_clean();
if($img->imagepath == "")
{echo "Erro IMAGEPATH vazio";exit;}
$nomer = ($img->imagepath)."imgtemp".nomeRandomico().".png";
$img->saveImage($nomer);
$img = imagecreatefrompng($nomer);
imagealphablending($img, false);
imagesavealpha($img, true);
ob_clean();
echo header("Content-type: image/png \n\n");
imagepng($img);
}
}
function nomeRandomico($n=10)
{
$nomes = "";
$a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ';
$max = 51;
for($i=0; $i < $n; ++$i)
{$nomes .= $a{mt_rand(0, $max)};}
return $nomes;
}
function filtraImagem($nomer,$tipoimagem){
include_once("classe_imagem.php");
$tiposImagem = explode(" ",$tipoimagem);
foreach ($tiposImagem as $tipoimagem){
$m = new Imagem($nomer);
if ($tipoimagem == "cinza")
{imagepng($m->cinzaNormal(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "sepiaclara")
{imagepng($m->sepiaClara(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "sepianormal")
{imagepng($m->sepiaNormal(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "negativo")
{imagepng($m->negativo(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "detectaBordas")
{imagepng($m->detectaBordas(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "embassa")
{imagepng($m->embassa(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "gaussian_blur")
{imagepng($m->gaussian_blur(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "selective_blur")
{imagepng($m->selective_blur(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "mean_removal")
{imagepng($m->mean_removal(),str_replace("\\","/",$nomer));}
if ($tipoimagem == "pixelate")
{imagepng($m->pixelate(),str_replace("\\","/",$nomer));}
}
}
function ilegal(){
$img = imagecreatefrompng("../imagens/ilegal.png");
imagealphablending($img, false);
imagesavealpha($img, true);
ob_clean();
echo header("Content-type: image/png \n\n");
imagepng($img);
exit;
}
?>