1 |
<?php |
---|
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 |
$bFoundAttributes = false; |
---|
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 |
function GetLayerAttributes( $oLayer ) |
---|
80 |
{ |
---|
81 |
$aszAttributes = array(); |
---|
82 |
|
---|
83 |
if ( |
---|
84 |
$oLayer->connectiontype == MS_WMS) |
---|
85 |
{ |
---|
86 |
|
---|
87 |
|
---|
88 |
$szLayerName = $oLayer->getMetaData( "wms_name" ); |
---|
89 |
if ($szLayerName == "") |
---|
90 |
$szLayerName = $oLayer->name; |
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
$aszInfo = getWFSConnection( $oLayer->connection, $szLayerName ); |
---|
95 |
|
---|
96 |
$szWFSConnection = $aszInfo['wfs']; |
---|
97 |
|
---|
98 |
|
---|
99 |
$szWFSTypeName = ""; |
---|
100 |
$sep = ''; |
---|
101 |
|
---|
102 |
foreach( $aszInfo['typename'] as $szTypeName ) |
---|
103 |
{ |
---|
104 |
$szWFSTypeName .= $sep.$szTypeName; |
---|
105 |
$sep = ','; |
---|
106 |
} |
---|
107 |
|
---|
108 |
|
---|
109 |
if ( $szWFSConnection != "" ) |
---|
110 |
{ |
---|
111 |
$szWFSConnection = fixWFSURL( $szWFSConnection, $szWFSTypeName ); |
---|
112 |
|
---|
113 |
|
---|
114 |
$aszAttributes['name'] = $oLayer->name; |
---|
115 |
$aszAttributes['index'] = $oLayer->index; |
---|
116 |
$aszAttributes['onlineresource'] = $szWFSConnection; |
---|
117 |
$aszAttributes['minx'] = ""; |
---|
118 |
$aszAttributes['miny'] = ""; |
---|
119 |
$aszAttributes['maxx'] = ""; |
---|
120 |
$aszAttributes['maxy'] = ""; |
---|
121 |
$aszAttributes['fields'] = getAttributeTypes( $szWFSConnection. |
---|
122 |
'request=describefeaturetype', $szLayerName ); |
---|
123 |
} |
---|
124 |
} |
---|
125 |
elseif ($oLayer->type == MS_LAYER_POINT || |
---|
126 |
$oLayer->type == MS_LAYER_LINE || |
---|
127 |
$oLayer->type == MS_LAYER_POLYGON ) |
---|
128 |
{ |
---|
129 |
|
---|
130 |
|
---|
131 |
switch( $oLayer->connectiontype ) |
---|
132 |
{ |
---|
133 |
case MS_WFS: |
---|
134 |
|
---|
135 |
|
---|
136 |
$szLayerName = $oLayer->getMetaData( "wms_name" ); |
---|
137 |
if ($szLayerName == "") |
---|
138 |
$szLayerName = $oLayer->name; |
---|
139 |
|
---|
140 |
|
---|
141 |
$szWFSConnection = $oLayer->connection; |
---|
142 |
|
---|
143 |
|
---|
144 |
$szWFSConnection = fixWFSURL( $szWFSConnection, $szLayerName ); |
---|
145 |
|
---|
146 |
|
---|
147 |
$aszAttributes['name'] = $oLayer->name; |
---|
148 |
$aszAttributes['index'] = $oLayer->index; |
---|
149 |
$aszAttributes['onlineresource'] = $szWFSConnection; |
---|
150 |
$aszAttributes['minx'] = ""; |
---|
151 |
$aszAttributes['miny'] = ""; |
---|
152 |
$aszAttributes['maxx'] = ""; |
---|
153 |
$aszAttributes['maxy'] = ""; |
---|
154 |
$aszAttributes['fields'] = getAttributeTypes( $szWFSConnection. |
---|
155 |
'request=describefeaturetype', $szLayerName ); |
---|
156 |
|
---|
157 |
|
---|
158 |
break; |
---|
159 |
|
---|
160 |
|
---|
161 |
default: |
---|
162 |
|
---|
163 |
$oLayer->open(); |
---|
164 |
|
---|
165 |
|
---|
166 |
|
---|
167 |
if ($oLayer->connectiontype == MS_TILED_SHAPEFILE || |
---|
168 |
$oLayer->tileindex != "") |
---|
169 |
{ |
---|
170 |
|
---|
171 |
|
---|
172 |
$nTile = 0; |
---|
173 |
} |
---|
174 |
else |
---|
175 |
{ |
---|
176 |
|
---|
177 |
$nTile = -1; |
---|
178 |
} |
---|
179 |
|
---|
180 |
|
---|
181 |
$oShape = $oLayer->getShape($nTile, 0 ); |
---|
182 |
$aszAttributes['name'] = $oLayer->name; |
---|
183 |
$aszAttributes['index'] = $oLayer->index; |
---|
184 |
$oRect = $oShape->bounds; |
---|
185 |
$aszAttributes['minx'] = $oRect->minx; |
---|
186 |
$aszAttributes['miny'] = $oRect->miny; |
---|
187 |
$aszAttributes['maxx'] = $oRect->maxx; |
---|
188 |
$aszAttributes['maxy'] = $oRect->maxy; |
---|
189 |
|
---|
190 |
foreach($oShape->values as $key => $value) |
---|
191 |
{ |
---|
192 |
$aszAttributes['fields'][$key] = "string"; |
---|
193 |
} |
---|
194 |
break; |
---|
195 |
} |
---|
196 |
} |
---|
197 |
|
---|
198 |
return $aszAttributes; |
---|
199 |
} |
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 |
|
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 |
function GetLayerFeatures( $oMap, $oLayer, $aszIncludeAttributes = array() ) |
---|
214 |
{ |
---|
215 |
|
---|
216 |
$aszFeatures = array(); |
---|
217 |
$szLayerName = $oLayer->name; |
---|
218 |
$szWFSTypeName = ''; |
---|
219 |
if ( $oLayer->connectiontype == MS_WMS ) |
---|
220 |
{ |
---|
221 |
|
---|
222 |
|
---|
223 |
$szLayerName = $oLayer->getMetaData( "wms_name" ); |
---|
224 |
if ($szLayerName == "") |
---|
225 |
$szLayerName = $oLayer->name; |
---|
226 |
|
---|
227 |
|
---|
228 |
$aszInfo = getWFSConnection( $oLayer->connection, $szLayerName ); |
---|
229 |
$szWFSConnection = $aszInfo['wfs']; |
---|
230 |
|
---|
231 |
|
---|
232 |
if ( isset( $aszInfo['typename'] ) && is_array( $aszInfo['typename'] ) ) |
---|
233 |
{ |
---|
234 |
|
---|
235 |
foreach( $aszInfo['typename'] as $szTypeName ) |
---|
236 |
{ |
---|
237 |
$szWFSTypeName .= $szTypeName.','; |
---|
238 |
} |
---|
239 |
} |
---|
240 |
|
---|
241 |
|
---|
242 |
if ( substr( $szWFSTypeName, -1, 1 ) == ',' ) |
---|
243 |
{ |
---|
244 |
$szWFSTypeName = substr( $szWFSTypeName, 0, -1 ); |
---|
245 |
} |
---|
246 |
|
---|
247 |
|
---|
248 |
if ( $szWFSConnection != "" ) |
---|
249 |
{ |
---|
250 |
|
---|
251 |
$szWFSConnection = fixWFSURL( $szWFSConnection, $szWFSTypeName ); |
---|
252 |
|
---|
253 |
|
---|
254 |
$aszAttributes = getAttributeTypes( $szWFSConnection. |
---|
255 |
'request=describefeaturetype', $szLayerName ); |
---|
256 |
|
---|
257 |
|
---|
258 |
$szLayerType = ''; |
---|
259 |
foreach( $aszAttributes as $key=>$value ) |
---|
260 |
{ |
---|
261 |
|
---|
262 |
if ( $key == 'LayerType' ) |
---|
263 |
{ |
---|
264 |
$szLayerType = $value; |
---|
265 |
break; |
---|
266 |
} |
---|
267 |
} |
---|
268 |
|
---|
269 |
|
---|
270 |
$oCloneLayer = ms_newLayerObj( $oMap, $oLayer ); |
---|
271 |
|
---|
272 |
|
---|
273 |
$oLayer->set( 'name', $oLayer->name.'tmp_backup' ); |
---|
274 |
|
---|
275 |
|
---|
276 |
$oCloneLayer->set( 'connectiontype', MS_WFS ); |
---|
277 |
$oCloneLayer->set( 'connection', $szWFSConnection.'&ttt=1' ); |
---|
278 |
$oCloneLayer->set( 'type', $szLayerType ); |
---|
279 |
} |
---|
280 |
else |
---|
281 |
{ |
---|
282 |
|
---|
283 |
return array(); |
---|
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 |
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 |
|
---|
327 |
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 |
|
---|
334 |
|
---|
335 |
|
---|
336 |
|
---|
337 |
|
---|
338 |
|
---|
339 |
|
---|
340 |
|
---|
341 |
|
---|
342 |
|
---|
343 |
|
---|
344 |
|
---|
345 |
|
---|
346 |
|
---|
347 |
|
---|
348 |
|
---|
349 |
|
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|
354 |
|
---|
355 |
$szTmpGML = !isset( $oCloneLayer ) ? $oLayer->executeWFSGetfeature() : |
---|
356 |
$oCloneLayer->executeWFSGetfeature(); |
---|
357 |
|
---|
358 |
|
---|
359 |
if ( file_exists( $szTmpGML ) ) |
---|
360 |
{ |
---|
361 |
|
---|
362 |
$aszFeatures = parseFeatures( $szTmpGML, $szLayerName, |
---|
363 |
$aszIncludeAttributes ); |
---|
364 |
|
---|
365 |
|
---|
366 |
unlink( $szTmpGML ); |
---|
367 |
} |
---|
368 |
|
---|
369 |
|
---|
370 |
|
---|
371 |
if ( isset( $oCloneLayer ) ) |
---|
372 |
{ |
---|
373 |
|
---|
374 |
$oLayer->set( 'name', substr( $oLayer->name, 0, -10 ) ); |
---|
375 |
|
---|
376 |
} |
---|
377 |
|
---|
378 |
|
---|
379 |
return $aszFeatures; |
---|
380 |
} |
---|
381 |
|
---|
382 |
|
---|
383 |
|
---|
384 |
|
---|
385 |
|
---|
386 |
|
---|
387 |
function getWFSSRS( $szXmlUrl ) |
---|
388 |
{ |
---|
389 |
|
---|
390 |
if (function_exists( 'file_get_contents' )) |
---|
391 |
{ |
---|
392 |
$data = file_get_contents( $szXmlUrl ); |
---|
393 |
} |
---|
394 |
else |
---|
395 |
{ |
---|
396 |
$data = implode( '', file($szXmlUrl) ); |
---|
397 |
} |
---|
398 |
|
---|
399 |
if ( stristr( $data, '<SERVICEEXCEPTIONREPORT' ) !== false ) |
---|
400 |
return ""; |
---|
401 |
|
---|
402 |
|
---|
403 |
$parser = xml_parser_create(); |
---|
404 |
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); |
---|
405 |
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); |
---|
406 |
xml_parse_into_struct($parser,$data,$values,$tags); |
---|
407 |
xml_parser_free($parser); |
---|
408 |
|
---|
409 |
return $values[$tags['SRS'][0]]['value']; |
---|
410 |
} |
---|
411 |
|
---|
412 |
|
---|
413 |
|
---|
414 |
|
---|
415 |
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|
420 |
|
---|
421 |
|
---|
422 |
function getAttributeTypes( $szXmlUrl, $szLayerName ) |
---|
423 |
{ |
---|
424 |
|
---|
425 |
$data = ""; |
---|
426 |
$axReturn = ""; |
---|
427 |
|
---|
428 |
|
---|
429 |
$aszFile = file( $szXmlUrl ); |
---|
430 |
|
---|
431 |
|
---|
432 |
if ( is_array( $aszFile ) ) |
---|
433 |
{ |
---|
434 |
foreach( $aszFile as $line ) |
---|
435 |
$data .= $line; |
---|
436 |
} |
---|
437 |
|
---|
438 |
|
---|
439 |
if ( !is_array( $aszFile ) || |
---|
440 |
strpos( strtoupper( $data ), '<SERVICEEXCEPTIONREPORT' ) !== false ) |
---|
441 |
return array(); |
---|
442 |
|
---|
443 |
|
---|
444 |
$parser = xml_parser_create(); |
---|
445 |
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); |
---|
446 |
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); |
---|
447 |
xml_parse_into_struct($parser,$data,$values,$tags); |
---|
448 |
xml_parser_free($parser); |
---|
449 |
|
---|
450 |
|
---|
451 |
foreach ($tags as $key=>$val) |
---|
452 |
{ |
---|
453 |
|
---|
454 |
if (strtoupper( $key ) == "SEQUENCE") |
---|
455 |
{ |
---|
456 |
$ranges = $val; |
---|
457 |
|
---|
458 |
|
---|
459 |
$nCount = count($ranges); |
---|
460 |
for ($i=0; $i < $nCount; $i+=2) |
---|
461 |
{ |
---|
462 |
$offset = $ranges[$i] + 1; |
---|
463 |
$len = $ranges[$i + 1] - $offset; |
---|
464 |
$axReturn = parseElements( array_slice($values, $offset, $len) ); |
---|
465 |
} |
---|
466 |
} |
---|
467 |
else |
---|
468 |
{ |
---|
469 |
|
---|
470 |
continue; |
---|
471 |
} |
---|
472 |
} |
---|
473 |
|
---|
474 |
|
---|
475 |
return $axReturn; |
---|
476 |
|
---|
477 |
|
---|
478 |
} |
---|
479 |
|
---|
480 |
|
---|
481 |
|
---|
482 |
|
---|
483 |
|
---|
484 |
|
---|
485 |
|
---|
486 |
|
---|
487 |
|
---|
488 |
|
---|
489 |
|
---|
490 |
function parseElements( $axValues ) |
---|
491 |
{ |
---|
492 |
|
---|
493 |
$aszReturn = array(); |
---|
494 |
|
---|
495 |
|
---|
496 |
$nCount = count( $axValues ); |
---|
497 |
for ( $i=0; $i < $nCount; $i++ ) |
---|
498 |
{ |
---|
499 |
|
---|
500 |
if ( strtoupper( $axValues[$i]["tag"] ) == "ELEMENT" ) |
---|
501 |
{ |
---|
502 |
|
---|
503 |
if ( isset( $axValues[$i]["attributes"]["name"] ) && |
---|
504 |
$axValues[$i]["attributes"]["type"] ) |
---|
505 |
{ |
---|
506 |
$aszReturn[$axValues[$i]["attributes"]["name"]] = |
---|
507 |
$axValues[$i]["attributes"]["type"]; |
---|
508 |
} |
---|
509 |
|
---|
510 |
|
---|
511 |
$szLayerType = ''; |
---|
512 |
if ( isset( $axValues[$i]["attributes"]["ref"] ) ) |
---|
513 |
$szLayerType = strtoupper( $axValues[$i]["attributes"]["ref"] ); |
---|
514 |
elseif ( isset( $axValues[$i]["attributes"]["type"] ) && |
---|
515 |
strtoupper( substr( $axValues[$i]["attributes"]["type"], 0, 4 ) ) == 'GML:' ) |
---|
516 |
$szLayerType = strtoupper( $axValues[$i]["attributes"]["type"] ); |
---|
517 |
|
---|
518 |
|
---|
519 |
if ( strlen( $szLayerType ) > 0 ) |
---|
520 |
{ |
---|
521 |
|
---|
522 |
if ( strpos( $szLayerType, 'POLYGON' ) !== false ) |
---|
523 |
$aszReturn['LayerType'] = 'MS_LAYER_POLYGON'; |
---|
524 |
elseif ( strpos( $szLayerType, 'BOX' ) !== false ) |
---|
525 |
$aszReturn['LayerType'] = 'MS_LAYER_POLYGON'; |
---|
526 |
elseif ( strpos( $szLayerType, 'LINE' ) !== false ) |
---|
527 |
$aszReturn['LayerType'] = 'MS_LAYER_LINE'; |
---|
528 |
elseif ( strpos( $szLayerType, 'POINT' ) !== false ) |
---|
529 |
$aszReturn['LayerType'] = 'MS_LAYER_POINT'; |
---|
530 |
} |
---|
531 |
} |
---|
532 |
} |
---|
533 |
|
---|
534 |
|
---|
535 |
return $aszReturn; |
---|
536 |
|
---|
537 |
|
---|
538 |
} |
---|
539 |
|
---|
540 |
|
---|
541 |
|
---|
542 |
|
---|
543 |
|
---|
544 |
|
---|
545 |
|
---|
546 |
|
---|
547 |
|
---|
548 |
|
---|
549 |
|
---|
550 |
function getWFSConnection( $szWMSConnection, $szSelectedLayerName ) |
---|
551 |
{ |
---|
552 |
|
---|
553 |
$szUpperCase = strtoupper( $szWMSConnection ); |
---|
554 |
|
---|
555 |
|
---|
556 |
if ( substr( $szWMSConnection, -1 ) != "?" && |
---|
557 |
substr( $szWMSConnection, -1 ) != "&" ) |
---|
558 |
{ |
---|
559 |
|
---|
560 |
if ( strpos( $szWMSConnection, "?" ) === false ) |
---|
561 |
{ |
---|
562 |
$szWMSConnection .= "?"; |
---|
563 |
} |
---|
564 |
else |
---|
565 |
$szWMSConnection .= "&"; |
---|
566 |
} |
---|
567 |
|
---|
568 |
|
---|
569 |
if ( strpos( $szUpperCase, "VERSION=" ) === false ) |
---|
570 |
$szWMSConnection .= "VERSION=1.1.0&"; |
---|
571 |
|
---|
572 |
|
---|
573 |
if ( strpos( $szUpperCase, "SERVICE=" ) === false ) |
---|
574 |
$szWMSConnection .= "SERVICE=WMS&"; |
---|
575 |
|
---|
576 |
|
---|
577 |
if ( strpos( $szUpperCase, "LAYERS=" ) === false ) |
---|
578 |
$szWMSConnection .= "LAYERS=".$szSelectedLayerName."&"; |
---|
579 |
|
---|
580 |
|
---|
581 |
$szWMSConnection .= "REQUEST=DESCRIBELAYER"; |
---|
582 |
|
---|
583 |
|
---|
584 |
|
---|
585 |
return getWFSResource( $szWMSConnection ); |
---|
586 |
|
---|
587 |
|
---|
588 |
} |
---|
589 |
|
---|
590 |
|
---|
591 |
|
---|
592 |
|
---|
593 |
|
---|
594 |
|
---|
595 |
|
---|
596 |
|
---|
597 |
|
---|
598 |
|
---|
599 |
|
---|
600 |
function getWFSResource( $szURL ) |
---|
601 |
{ |
---|
602 |
|
---|
603 |
$data = ""; |
---|
604 |
$aszReturn = array( 'wfs'=>'', 'typename'=>array() ); |
---|
605 |
|
---|
606 |
|
---|
607 |
if (!function_exists('file_get_contents')) |
---|
608 |
{ |
---|
609 |
$szXMLFile = implode( "", file($szURL) ); |
---|
610 |
} |
---|
611 |
else |
---|
612 |
{ |
---|
613 |
$szXMLFile = file_get_contents( $szURL ); |
---|
614 |
} |
---|
615 |
|
---|
616 |
|
---|
617 |
if ( strpos( strtoupper( $szXMLFile ), '<SERVICEEXCEPTIONREPORT' ) !== false ) |
---|
618 |
{ |
---|
619 |
return false; |
---|
620 |
} |
---|
621 |
|
---|
622 |
|
---|
623 |
$parser = xml_parser_create(); |
---|
624 |
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
---|
625 |
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
---|
626 |
xml_parse_into_struct($parser, $szXMLFile, $aVals, $index); |
---|
627 |
xml_parser_free($parser); |
---|
628 |
|
---|
629 |
|
---|
630 |
$aVals = lowercaseArrayKeys( $aVals ); |
---|
631 |
|
---|
632 |
|
---|
633 |
|
---|
634 |
|
---|
635 |
$nCount = count( $aVals ); |
---|
636 |
for( $i=0; $i<$nCount; $i++ ) |
---|
637 |
{ |
---|
638 |
|
---|
639 |
if ( strtolower( $aVals[$i]['tag'] ) == 'layerdescription' && |
---|
640 |
isset( $aVals[$i]['attributes']['wfs'] ) ) |
---|
641 |
{ |
---|
642 |
$aszReturn['wfs'] = $aVals[$i]['attributes']['wfs']; |
---|
643 |
} |
---|
644 |
|
---|
645 |
|
---|
646 |
if ( strtolower( $aVals[$i]['tag'] ) == 'query' ) |
---|
647 |
{ |
---|
648 |
array_push( $aszReturn['typename'], |
---|
649 |
$aVals[$i]['attributes']['typename'] ); |
---|
650 |
} |
---|
651 |
} |
---|
652 |
|
---|
653 |
|
---|
654 |
return $aszReturn; |
---|
655 |
|
---|
656 |
|
---|
657 |
} |
---|
658 |
|
---|
659 |
|
---|
660 |
|
---|
661 |
|
---|
662 |
|
---|
663 |
|
---|
664 |
|
---|
665 |
|
---|
666 |
|
---|
667 |
|
---|
668 |
|
---|
669 |
|
---|
670 |
function fixWFSURL( $szConnection, $szWFSTypeName ) |
---|
671 |
{ |
---|
672 |
|
---|
673 |
$szUpperCase = strtoupper( $szConnection ); |
---|
674 |
|
---|
675 |
|
---|
676 |
if ( substr( $szConnection, -1 ) != "?" && |
---|
677 |
substr( $szConnection, -1 ) != "&" ) |
---|
678 |
{ |
---|
679 |
|
---|
680 |
if ( strpos( $szConnection, "?" ) === false ) |
---|
681 |
{ |
---|
682 |
$szConnection .= "?"; |
---|
683 |
} |
---|
684 |
else |
---|
685 |
$szConnection .= "&"; |
---|
686 |
} |
---|
687 |
|
---|
688 |
|
---|
689 |
if ( strpos( $szUpperCase, "VERSION=" ) === false ) |
---|
690 |
$szConnection .= "VERSION=1.0.0&"; |
---|
691 |
|
---|
692 |
|
---|
693 |
if ( strpos( $szUpperCase, "SERVICE=" ) === false ) |
---|
694 |
$szConnection .= "SERVICE=WFS&"; |
---|
695 |
|
---|
696 |
|
---|
697 |
if ( strpos( $szUpperCase, "TYPENAME=" ) === false ) |
---|
698 |
$szConnection .= "TYPENAME=".$szWFSTypeName."&"; |
---|
699 |
|
---|
700 |
|
---|
701 |
return $szConnection; |
---|
702 |
|
---|
703 |
|
---|
704 |
} |
---|
705 |
|
---|
706 |
|
---|
707 |
|
---|
708 |
|
---|
709 |
|
---|
710 |
|
---|
711 |
|
---|
712 |
|
---|
713 |
|
---|
714 |
|
---|
715 |
|
---|
716 |
function lowercaseArrayKeys( $axConvert ) |
---|
717 |
{ |
---|
718 |
|
---|
719 |
$axReturn = array(); |
---|
720 |
|
---|
721 |
|
---|
722 |
$i=0; |
---|
723 |
foreach( $axConvert as $key=>$value ) |
---|
724 |
{ |
---|
725 |
|
---|
726 |
if ( is_array( $value ) ) |
---|
727 |
{ |
---|
728 |
$value = lowercaseArrayKeys( $value ); |
---|
729 |
} |
---|
730 |
|
---|
731 |
|
---|
732 |
$axReturn[strtolower( $key )] = $value; |
---|
733 |
|
---|
734 |
|
---|
735 |
$i++; |
---|
736 |
if ( $i >= 1000000 ) |
---|
737 |
{ |
---|
738 |
die('Error in lowercaseArrayKeys() 1,000,000 entries was exceeded'); |
---|
739 |
} |
---|
740 |
} |
---|
741 |
|
---|
742 |
|
---|
743 |
return $axReturn; |
---|
744 |
} |
---|
745 |
|
---|
746 |
|
---|
747 |
|
---|
748 |
|
---|
749 |
|
---|
750 |
|
---|
751 |
|
---|
752 |
|
---|
753 |
|
---|
754 |
|
---|
755 |
|
---|
756 |
|
---|
757 |
|
---|
758 |
|
---|
759 |
|
---|
760 |
function parseFeatures( $szFile, $szLayer, $aszAttributes = array() ) |
---|
761 |
{ |
---|
762 |
|
---|
763 |
$data = ""; |
---|
764 |
$aszReturn = array(); |
---|
765 |
|
---|
766 |
|
---|
767 |
|
---|
768 |
|
---|
769 |
|
---|
770 |
|
---|
771 |
|
---|
772 |
|
---|
773 |
|
---|
774 |
|
---|
775 |
|
---|
776 |
|
---|
777 |
|
---|
778 |
|
---|
779 |
|
---|
780 |
|
---|
781 |
|
---|
782 |
|
---|
783 |
|
---|
784 |
|
---|
785 |
$h = fopen($szFile, "r"); |
---|
786 |
$loop = 0; |
---|
787 |
do |
---|
788 |
{ |
---|
789 |
$line = fread( $h, 1024 ); |
---|
790 |
if (strlen($line) == 0) |
---|
791 |
break; |
---|
792 |
|
---|
793 |
$data .= $line; |
---|
794 |
|
---|
795 |
$loop ++; |
---|
796 |
if ($loop > 100000) break; |
---|
797 |
} |
---|
798 |
while(true); |
---|
799 |
|
---|
800 |
|
---|
801 |
|
---|
802 |
|
---|
803 |
|
---|
804 |
|
---|
805 |
|
---|
806 |
if ( strpos( strtoupper( $data ), '<SERVICEEXCEPTIONREPORT' ) !== false ) |
---|
807 |
{ |
---|
808 |
return array(); |
---|
809 |
} |
---|
810 |
|
---|
811 |
|
---|
812 |
$parser = xml_parser_create(); |
---|
813 |
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); |
---|
814 |
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); |
---|
815 |
xml_parse_into_struct($parser,$data,$values,$tags); |
---|
816 |
xml_parser_free($parser); |
---|
817 |
|
---|
818 |
|
---|
819 |
foreach ($tags as $key=>$val) |
---|
820 |
{ |
---|
821 |
|
---|
822 |
if ( strtoupper( $key ) == strtoupper( $szLayer ) ) |
---|
823 |
{ |
---|
824 |
$ranges = $val; |
---|
825 |
|
---|
826 |
|
---|
827 |
$nCount = count($ranges); |
---|
828 |
for ($i=0; $i < $nCount; $i+=2) |
---|
829 |
{ |
---|
830 |
if (isset($ranges[$i+1])) |
---|
831 |
{ |
---|
832 |
$offset = $ranges[$i] + 1; |
---|
833 |
$len = $ranges[$i + 1] - $offset; |
---|
834 |
$axTmp = parseFeatureElements( |
---|
835 |
array_slice($values, $offset, $len ), $szLayer, $aszAttributes ); |
---|
836 |
$aszReturn = array_merge( $aszReturn, $axTmp ); |
---|
837 |
} |
---|
838 |
} |
---|
839 |
} |
---|
840 |
else |
---|
841 |
{ |
---|
842 |
|
---|
843 |
continue; |
---|
844 |
} |
---|
845 |
} |
---|
846 |
|
---|
847 |
|
---|
848 |
return $aszReturn; |
---|
849 |
|
---|
850 |
|
---|
851 |
} |
---|
852 |
|
---|
853 |
|
---|
854 |
|
---|
855 |
|
---|
856 |
|
---|
857 |
|
---|
858 |
|
---|
859 |
|
---|
860 |
|
---|
861 |
|
---|
862 |
|
---|
863 |
|
---|
864 |
|
---|
865 |
function parseFeatureElements( $axValues, $szLayer, $aszAttributes = array() ) |
---|
866 |
{ |
---|
867 |
|
---|
868 |
$axReturn = array(); |
---|
869 |
$bAllowAll = ( count( $aszAttributes ) <= 0 ) ? true:false; |
---|
870 |
|
---|
871 |
|
---|
872 |
$aResult = array(); |
---|
873 |
$nCount = count( $axValues ); |
---|
874 |
$j = 0; |
---|
875 |
for ( $i=0; $i < $nCount; $i++ ) |
---|
876 |
{ |
---|
877 |
|
---|
878 |
|
---|
879 |
if ( strtoupper( substr( $axValues[$i]["tag"], 0, 3 ) ) != "GML" ) |
---|
880 |
{ |
---|
881 |
|
---|
882 |
if ( $bAllowAll || in_array( $axValues[$i]['tag'], $aszAttributes ) ) |
---|
883 |
{ |
---|
884 |
|
---|
885 |
|
---|
886 |
if ( isset( $axValues[$i]['value'] ) ) |
---|
887 |
{ |
---|
888 |
|
---|
889 |
$aResult[$axValues[$i]['tag']] = $axValues[$i]['value']; |
---|
890 |
} |
---|
891 |
else |
---|
892 |
{ |
---|
893 |
$aResult[$axValues[$i]['tag']] = ''; |
---|
894 |
} |
---|
895 |
$j++; |
---|
896 |
} |
---|
897 |
} |
---|
898 |
} |
---|
899 |
array_push( $axReturn, $aResult ); |
---|
900 |
|
---|
901 |
|
---|
902 |
return $axReturn; |
---|
903 |
|
---|
904 |
|
---|
905 |
} |
---|
906 |
|
---|
907 |
|
---|
908 |
function getGML( $szURL ) |
---|
909 |
{ |
---|
910 |
|
---|
911 |
$szTmpFile = $_SESSION['gszTmpPath'].md5(uniqid(rand(), true)).'.gml'; |
---|
912 |
|
---|
913 |
|
---|
914 |
$aszFile = file( $szURL ); |
---|
915 |
|
---|
916 |
|
---|
917 |
if ( !is_array( $aszFile ) || |
---|
918 |
strpos( strtoupper( $aszFile[0] ), '<SERVICEEXCEPTIONREPORT' ) !== false ) |
---|
919 |
{ |
---|
920 |
|
---|
921 |
if ( !is_array( $aszFile ) ) |
---|
922 |
$szServerDump = $aszFile; |
---|
923 |
else |
---|
924 |
{ |
---|
925 |
$szServerDump = ""; |
---|
926 |
foreach( $aszFile as $line ) |
---|
927 |
$szServerDump .= $line; |
---|
928 |
} |
---|
929 |
|
---|
930 |
|
---|
931 |
return 'Error'; |
---|
932 |
} |
---|
933 |
|
---|
934 |
|
---|
935 |
if ( !( $fp = fopen( $szTmpFile, "w" ) ) ) |
---|
936 |
{ |
---|
937 |
|
---|
938 |
return 'Error'; |
---|
939 |
} |
---|
940 |
|
---|
941 |
|
---|
942 |
foreach( $aszFile as $line ) |
---|
943 |
{ |
---|
944 |
|
---|
945 |
fputs($fp, $line."\n"); |
---|
946 |
} |
---|
947 |
|
---|
948 |
|
---|
949 |
fclose($fp); |
---|
950 |
|
---|
951 |
|
---|
952 |
return $szTmpFile; |
---|
953 |
} |
---|
954 |
|
---|
955 |
|
---|
956 |
?> |
---|