Commit 97c797b31aead97e08cb1bf8adc7b641b4bd7603
1 parent
9daae7a2
Exists in
master
and in
7 other branches
--no commit message
Showing
1 changed file
with
0 additions
and
338 deletions
Show diff stats
pacotes/gvsig/gvsig2mapfile/class.gvsig2mapfile.php~
... | ... | @@ -1,338 +0,0 @@ |
1 | -<?php | |
2 | -/** | |
3 | - * Manipula um arquivo GVP (projeto gvSIG) para construção de layers Mapserver | |
4 | - * @author Edmar Moretti | |
5 | - * @license GPL2 | |
6 | - */ | |
7 | -class gvsig2mapfile{ | |
8 | - var $arquivoGvp; | |
9 | - var $xml; | |
10 | - var $nomesLayersAdicionados = array(); | |
11 | - /** | |
12 | - * Construtor da classe | |
13 | - * @param string $gvp arquivo de projeto gvsig | |
14 | - * @example $gm = new gvsig2mapfile($gvsiggvp); | |
15 | - * @throws Exception | |
16 | - */ | |
17 | - function __construct($gvp) | |
18 | - { | |
19 | - if(!file_exists($gvp)) | |
20 | - {throw new Exception("Arquivo $gvp não existe");} | |
21 | - else{ | |
22 | - $this->arquivoGvp = $gvp; | |
23 | - if(function_exists("dl")){ | |
24 | - if (!function_exists('simplexml_load_file')) | |
25 | - {dl( 'php_simplexml.'.PHP_SHLIB_SUFFIX );} | |
26 | - } | |
27 | - if (!function_exists('simplexml_load_file')) | |
28 | - {throw new Exception("Função PHP simplexml_load_file não existe");} | |
29 | - $this->xml = simplexml_load_file($gvp); | |
30 | - } | |
31 | - } | |
32 | - /** | |
33 | - * Lista de vistas existentes no projeto gvsig | |
34 | - * @return array | |
35 | - **/ | |
36 | - function getViewsNames(){ | |
37 | - $names = array(); | |
38 | - $this->xml->registerXPathNamespace("tag", "http://www.gvsig.gva.es"); | |
39 | - $results = $this->xml->xpath("/tag:xml-tag/tag:xml-tag/tag:property[@value='ProjectView']/parent::*/tag:property[@key='name']"); | |
40 | - foreach($results as $result){ | |
41 | - $names[] = $this->findAttribute($result,"value"); | |
42 | - } | |
43 | - return $names; | |
44 | - } | |
45 | - | |
46 | - /** | |
47 | - * Retorna uma vista | |
48 | - * @param string $nome | |
49 | - * @return $xml | |
50 | - */ | |
51 | - function getViewByName($nome){ | |
52 | - $this->xml->registerXPathNamespace("tag", "http://www.gvsig.gva.es"); | |
53 | - $result = $this->xml->xpath("/tag:xml-tag/tag:xml-tag/tag:property[@value='ProjectView']/parent::*/tag:property[@value='".$nome."']/parent::*"); | |
54 | - return $result; | |
55 | - } | |
56 | - | |
57 | - /** | |
58 | - * Obtem os dados descritivos de uma visao | |
59 | - * @param string $nome Nome da vista | |
60 | - * @return array ( | |
61 | - "extent"=>array(xmin,ymin,xmax,ymax), | |
62 | - "proj"=>string projecao, | |
63 | - "layerNames"=>string lista de layers separados por virgula | |
64 | - ) | |
65 | - */ | |
66 | - function getViewData($nome){ | |
67 | - $this->xml->registerXPathNamespace("tag", "http://www.gvsig.gva.es"); | |
68 | - $path = "/tag:xml-tag/tag:xml-tag/tag:property[@value='ProjectView']/parent::*/tag:property[@value='".$nome."']/parent::*/tag:xml-tag/tag:xml-tag"; | |
69 | - | |
70 | - $xmin = (float) $this->getValue($path,"adjustedExtentX"); | |
71 | - $ymin = (float) $this->getValue($path,"adjustedExtentY"); | |
72 | - $xmax = $xmin + (float) $this->getValue($path,"adjustedExtentW"); | |
73 | - $ymax = $ymin + (float) $this->getValue($path,"adjustedExtentH"); | |
74 | - | |
75 | - $proj = $this->getValue($path,"proj"); | |
76 | - $nomes = $this->getValue($path,"LayerNames"); | |
77 | - return array( | |
78 | - "extent"=>array($xmin,$ymin,$xmax,$ymax), | |
79 | - "proj"=>(string) $proj, | |
80 | - "layerNames"=>explode(",",str_replace(" ,",",",$nomes)) | |
81 | - ); | |
82 | - } | |
83 | - /** | |
84 | - * Obtem os dados de um layer | |
85 | - * @param string $viewNome | |
86 | - * @param string $layerNome | |
87 | - * @return array( | |
88 | - "minScale"=> string, | |
89 | - "maxScale"=>string, | |
90 | - "visible"=>string, | |
91 | - "proj"=>string, | |
92 | - "transparency"=>string, | |
93 | - "type"=>string, | |
94 | - "data"=>string, | |
95 | - "connection"=>string, | |
96 | - "connectiontype"=>string, | |
97 | - "driverName"=>string, | |
98 | - "isLabeled"=>string, | |
99 | - "legenda"=>array( | |
100 | - "tipoLegenda"=>string, | |
101 | - "classes"=>string | |
102 | - ) | |
103 | - ) | |
104 | - * | |
105 | - */ | |
106 | - function getLayerData($viewNome,$layerNome){ | |
107 | - $this->xml->registerXPathNamespace("tag", "http://www.gvsig.gva.es"); | |
108 | - $path = "/tag:xml-tag/tag:xml-tag/tag:property[@value='ProjectView']/parent::*/tag:property[@value='".$viewNome."']/parent::*/tag:xml-tag/tag:xml-tag/tag:xml-tag/tag:xml-tag/parent::*/tag:property[@value='".$layerNome."']/parent::*"; | |
109 | - $classes = array(); | |
110 | - $render = 'com.iver.cit.gvsig.fmap.rendering'; | |
111 | - | |
112 | - $path1 = $path."/tag:xml-tag/tag:property[@value='".$render.".VectorialUniqueValueLegend']/parent::*/tag:xml-tag"; | |
113 | - $result = $this->xml->xpath($path1); | |
114 | - if($result != FALSE){ | |
115 | - $coluna = (string) $this->getValue($path."/tag:xml-tag","fieldNames"); | |
116 | - $valores = (string) $this->getValue($path."/tag:xml-tag","values"); | |
117 | - $tipocoluna = (string) $this->getValue($path."/tag:xml-tag","fieldTypes"); | |
118 | - $nomes = (string) $this->getValue($path."/tag:xml-tag","keys"); | |
119 | - | |
120 | - $classes = $this->VectorialUniqueValueLegend($result,$path1,$coluna,$tipocoluna,$valores,$nomes); | |
121 | - } | |
122 | - | |
123 | - $path1 = $path."/tag:xml-tag/tag:property[@value='".$render.".SingleSymbolLegend']/parent::*/tag:xml-tag"; | |
124 | - $result = $this->xml->xpath($path1); | |
125 | - if($result != FALSE) | |
126 | - {$classes = $this->SingleSymbolLegend($result,$path1);} | |
127 | - | |
128 | - // | |
129 | - //obtem a conexão | |
130 | - //a senha não pode ser obtida, então, é usado o mesmo nome de usuário em seu lugar. No i3Geo deve-se prever isso na variável de substituição de string. | |
131 | - $driverName = $this->getValue($path,"driverName"); | |
132 | - if($driverName == "gvSIG shp driver"){ | |
133 | - $data = (string) $this->getValue($path,"file"); | |
134 | - $connection = ""; | |
135 | - $connectiontype = ""; | |
136 | - } | |
137 | - if($driverName == "PostGIS JDBC Driver"){ | |
138 | - $path1 = $path."/tag:xml-tag/tag:property[@value='org.postgresql.Driver']/parent::*"; | |
139 | - $tabela = ""; | |
140 | - if($this->getValue($path1,"schema") != "") | |
141 | - {$tabela = (string) $this->getValue($path1,"schema").".";} | |
142 | - $tabela .= (string) $this->getValue($path1,"tablename"); | |
143 | - $data = (string) $this->getValue($path1,"THE_GEOM")." FROM (select ".(string) $this->getValue($path1,"THE_GEOM").",".(string) $this->getValue($path1,"fields")." FROM ".$tabela.") as foo USING UNIQUE ".(string) $this->getValue($path1,"FID")." USING SRID=".(string) $this->getValue($path1,"SRID"); | |
144 | - $connection = "user=".(string) $this->getValue($path1,"username")." password=".(string) $this->getValue($path1,"username")." dbname=".(string) $this->getValue($path1,"dbName")." host=".(string) $this->getValue($path1,"host")." port=".(string) $this->getValue($path1,"port"); | |
145 | - $connectiontype = MS_POSTGIS; | |
146 | - } | |
147 | - return array( | |
148 | - "minScale"=>(string) $this->getValue($path,"minScale"), | |
149 | - "maxScale"=>(string) $this->getValue($path,"maxScale"), | |
150 | - "visible"=>(string) $this->getValue($path,"visible"), | |
151 | - "proj"=>(string) $this->getValue($path,"proj"), | |
152 | - "transparency"=>(string) $this->getValue($path,"transparency"), | |
153 | - "type"=>(string) $this->getValue($path,"type"), | |
154 | - "data"=>$data, | |
155 | - "connection"=>$connection, | |
156 | - "connectiontype"=>$connectiontype, | |
157 | - "driverName"=>(string) $this->getValue($path,"driverName"), | |
158 | - "isLabeled"=>(string) $this->getValue($path,"isLabeled"), | |
159 | - "legenda"=>array( | |
160 | - "tipoLegenda"=>(string) $this->getValue($path."/tag:xml-tag","className"), | |
161 | - "classes"=>$classes | |
162 | - ) | |
163 | - ); | |
164 | - } | |
165 | - function VectorialUniqueValueLegend($result,$path1,$coluna,$tipocoluna,$valores,$nomes){ | |
166 | - $valores = ",".str_replace(" ,",",",$valores); | |
167 | - $valores = explode(",",$valores); | |
168 | - $nomes = ",".str_replace(" ,",",",$nomes); | |
169 | - $nomes = explode(",",$nomes); | |
170 | - $classes = array(); | |
171 | - $c = 0; | |
172 | - | |
173 | - while(list( , $node) = each($result)) { | |
174 | - $classe = array(); | |
175 | - if($tipocoluna == 12) | |
176 | - {$classe["exp"] = "('[".$coluna."]'eq'".$valores[$c]."')";} | |
177 | - else | |
178 | - {$classe["exp"] = "([".$coluna."] = ".$valores[$c]." )";} | |
179 | - $classe["className"] = (string) $this->getValue($path1,"className",$c); | |
180 | - $classe["nome"] = $nomes[$c]; | |
181 | - $classe["desc"] = (string) $this->getValue($path1,"desc",$c); | |
182 | - $classe["color"] = (string) $this->getValue($path1,"color",$c); | |
183 | - $classe["rotation"] = (string) $this->getValue($path1,"rotation",$c); | |
184 | - $classe["offsetX"] = (string) $this->getValue($path1,"offsetX",$c); | |
185 | - $classe["offsetY"] = (string) $this->getValue($path1,"offsetY",$c); | |
186 | - $classe["size"] = (string) $this->getValue($path1,"size",$c); | |
187 | - $classe["markerStyle"] = (string) $this->getValue($path1,"markerStyle",$c); | |
188 | - $classe["hasFill"] = (string) $this->getValue($path1,"hasFill",$c); | |
189 | - $classe["hasOutline"] = (string) $this->getValue($path1,"hasOutline",$c); | |
190 | - if($classe["hasOutline"] == "true"){ | |
191 | - $classe["outline"] = (string) $this->getValue($path1."/tag:xml-tag","color",0); | |
192 | - } | |
193 | - else{ | |
194 | - $classe["outline"] = (string) $this->getValue($path1,"color",$c); | |
195 | - } | |
196 | - if($classe["desc"] != "") | |
197 | - {$classes[] = $classe;} | |
198 | - $c = $c + 1; | |
199 | - } | |
200 | - | |
201 | - //com.iver.cit.gvsig.fmap.rendering.ZSort | |
202 | - return $classes; | |
203 | - } | |
204 | - function SingleSymbolLegend($result,$path){ | |
205 | - $classes = array(); | |
206 | - $c = 0; | |
207 | - | |
208 | - while(list( , $node) = each($result)) { | |
209 | - $classe = array(); | |
210 | - $classe["className"] = (string) $this->getValue($path,"className",$c); | |
211 | - if($classe["className"] != "com.iver.cit.gvsig.fmap.rendering.ZSort"){ | |
212 | - $classe["desc"] = (string) $this->getValue($path,"desc",$c); | |
213 | - $classe["color"] = (string) $this->getValue($path,"color",$c); | |
214 | - $classe["rotation"] = (string) $this->getValue($path,"rotation",$c); | |
215 | - $classe["offsetX"] = (string) $this->getValue($path,"offsetX",$c); | |
216 | - $classe["offsetY"] = (string) $this->getValue($path,"offsetY",$c); | |
217 | - $classe["size"] = (string) $this->getValue($path,"size",$c); | |
218 | - $classe["markerStyle"] = (string) $this->getValue($path,"markerStyle",$c); | |
219 | - $classe["hasFill"] = (string) $this->getValue($path,"hasFill",$c); | |
220 | - $classe["hasOutline"] = (string) $this->getValue($path,"hasOutline",$c); | |
221 | - $classe["exp"] = false; | |
222 | - $classe["nome"] = " "; | |
223 | - if($classe["hasOutline"] == "true"){ | |
224 | - $classe["outline"] = (string) $this->getValue($path."/tag:xml-tag","color"); | |
225 | - } | |
226 | - else{ | |
227 | - $classe["outline"] = (string) $this->getValue($path,"color",$c); | |
228 | - } | |
229 | - $classes[] = $classe; | |
230 | - $c = $c + 1; | |
231 | - } | |
232 | - } | |
233 | - | |
234 | - return $classes; | |
235 | - } | |
236 | - function getValue($path,$key,$i=0){ | |
237 | - $result = $this->xml->xpath($path."/tag:property[@key='".$key."']"); | |
238 | - if($result) | |
239 | - {return $this->findAttribute($result[$i],"value");} | |
240 | - else | |
241 | - {return false;} | |
242 | - } | |
243 | - function addLayers($objMap,$gvsigview,$layerNames){ | |
244 | - foreach($layerNames as $lname){ | |
245 | - $dataLayer = $this->getLayerData($gvsigview,$lname); | |
246 | - $oLayer = ms_newLayerObj($objMap); | |
247 | - $oLayer->setmetadata("TEMA",$lname); | |
248 | - $oLayer->set("template","none.htm"); | |
249 | - $oLayer = $this->data2layer($oLayer,$dataLayer); | |
250 | - //evita problemas no modo tile | |
251 | - $oLayer->setprocessing("LABEL_NO_CLIP=True"); | |
252 | - $oLayer->setprocessing("POLYLINE_NO_CLIP=True"); | |
253 | - } | |
254 | - return $objMap; | |
255 | - } | |
256 | - function data2layer($oLayer,$dataLayer){ | |
257 | - $oLayer->set("name",basename($this->arquivoGvp)."_".$oLayer->index); //$this->nomeRandomico()); | |
258 | - $this->nomesLayersAdicionados[] = $oLayer->name; | |
259 | - $oLayer->set("data",$dataLayer["data"]); | |
260 | - if($dataLayer["connectiontype"] != "") | |
261 | - {$oLayer->setConnectionType($dataLayer["connectiontype"]);} | |
262 | - if($dataLayer["connection"] != "") | |
263 | - {$oLayer->set("connection",$dataLayer["connection"]);} | |
264 | - $oLayer->set("status",MS_DEFAULT); | |
265 | - if($dataLayer["visible"] == "false") | |
266 | - {$oLayer->set("status",MS_OFF);} | |
267 | - if(!empty($dataLayer["transparency"])){ | |
268 | - $opacidade = ($dataLayer["transparency"] * 100) / 255; | |
269 | - $oLayer->set("opacity",$opacidade); | |
270 | - } | |
271 | - if($dataLayer["minScale"] > 0) | |
272 | - {$oLayer->set("minscaledenom",$dataLayer["minScale"]);} | |
273 | - if($dataLayer["maxScale"] > 0) | |
274 | - {$oLayer->set("maxscaledenom",$dataLayer["maxScale"]);} | |
275 | - | |
276 | - $tipo = $dataLayer["legenda"]["classes"][0]["className"]; | |
277 | - $oLayer->set("type",1); | |
278 | - if($tipo == "com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol") | |
279 | - {$oLayer->set("type",0);} | |
280 | - if($tipo == "com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol") | |
281 | - {$oLayer->set("type",2);} | |
282 | - | |
283 | - foreach($dataLayer["legenda"]["classes"] as $data){ | |
284 | - //var_dump($data); | |
285 | - $classe = ms_newClassObj($oLayer); | |
286 | - $classe->set("name",$data["nome"]); | |
287 | - $estilo = ms_newStyleObj($classe); | |
288 | - if($oLayer->type == 0){ | |
289 | - $estilo->set("symbolname","ponto"); | |
290 | - } | |
291 | - if(!empty($data["color"])){ | |
292 | - if($data["hasFill"] == "true"){ | |
293 | - $ncor = explode(",",$data["color"]); | |
294 | - $cor = $estilo->color; | |
295 | - $cor->setrgb($ncor[0],$ncor[1],$ncor[2]); | |
296 | - } | |
297 | - if($data["hasOutline"] == "true" && $data["outline"] != ""){ | |
298 | - $ncor = explode(",",$data["outline"]); | |
299 | - $cor = $estilo->outlinecolor; | |
300 | - $cor->setrgb($ncor[0],$ncor[1],$ncor[2]); | |
301 | - } | |
302 | - | |
303 | -if($data["hasFill"] == "" && $data["hasOutline"] == ""){ | |
304 | - $ncor = explode(",",$data["color"]); | |
305 | - $cor = $estilo->color; | |
306 | - $cor->setrgb($ncor[0],$ncor[1],$ncor[2]); | |
307 | -} | |
308 | - } | |
309 | - if($data["size"] != false) | |
310 | - {$estilo->set("size",$data["size"]);} | |
311 | - if($data["exp"] != false) | |
312 | - {$classe->setExpression($data["exp"]);} | |
313 | - } | |
314 | - | |
315 | - return $oLayer; | |
316 | - } | |
317 | - function findAttribute($object, $attribute) { | |
318 | - $return = false; | |
319 | - if(@$object->attributes()){ | |
320 | - foreach($object->attributes() as $a => $b) { | |
321 | - if ($a == $attribute) { | |
322 | - $return = $b; | |
323 | - } | |
324 | - } | |
325 | - } | |
326 | - return $return; | |
327 | - } | |
328 | - function nomeRandomico($n=10) | |
329 | - { | |
330 | - $nomes = ""; | |
331 | - $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
332 | - $max = 51; | |
333 | - for($i=0; $i < $n; ++$i) | |
334 | - {$nomes .= $a{mt_rand(0, $max)};} | |
335 | - return $nomes; | |
336 | - } | |
337 | -} | |
338 | -?> |