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 |
include_once( COMMON."wrapper/map_query.php" ); |
---|
31 |
include_once( COMMON."xml_utils/XMLObject.php" ); |
---|
32 |
include_once( COMMON."/phpwms/dbf.php"); |
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
function executeQuery( $oMapSession, $nMinX, $nMinY, $nMaxX = -1, $nMaxY = -1) |
---|
51 |
{ |
---|
52 |
|
---|
53 |
set_time_limit( 120 ); |
---|
54 |
|
---|
55 |
|
---|
56 |
$oMapQuery = new MapQuery( $oMapSession ); |
---|
57 |
|
---|
58 |
|
---|
59 |
$aszWMSResults = array(); |
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 |
$aszLayers = array(); |
---|
66 |
$aszTitles = array(); |
---|
67 |
$oMap = $oMapSession->oMap; |
---|
68 |
$nCount = $oMap->numlayers; |
---|
69 |
for ( $i=0; $i<$nCount; $i++ ) |
---|
70 |
{ |
---|
71 |
|
---|
72 |
$oLayer = $oMap->getLayer( $i ); |
---|
73 |
|
---|
74 |
$bQueryable = false; |
---|
75 |
if ($oLayer->status == MS_ON || $oLayer->status == MS_DEFAULT) |
---|
76 |
{ |
---|
77 |
if ($oLayer->template != "") |
---|
78 |
{ |
---|
79 |
$bQueryable = true; |
---|
80 |
} |
---|
81 |
else |
---|
82 |
{ |
---|
83 |
for( $j=0; $j < $oLayer->numclasses; $j++) |
---|
84 |
{ |
---|
85 |
$oClass = $oLayer->getClass($j); |
---|
86 |
if ($oClass->template != "") |
---|
87 |
{ |
---|
88 |
$bQueryable = true; |
---|
89 |
break; |
---|
90 |
} |
---|
91 |
} |
---|
92 |
} |
---|
93 |
} |
---|
94 |
|
---|
95 |
|
---|
96 |
if ( $bQueryable ) |
---|
97 |
{ |
---|
98 |
array_push( $aszLayers, $oLayer->name ); |
---|
99 |
} |
---|
100 |
} |
---|
101 |
|
---|
102 |
$aResults = array(); |
---|
103 |
|
---|
104 |
if(count($aszLayers) >= 1) |
---|
105 |
{ |
---|
106 |
|
---|
107 |
$oMapQuery->setQueryLayersByName( $aszLayers ); |
---|
108 |
|
---|
109 |
|
---|
110 |
$oResultSet = $oMapQuery->executePointQuery( $nMinX, $nMinY ); |
---|
111 |
|
---|
112 |
|
---|
113 |
if($oResultSet) |
---|
114 |
{ |
---|
115 |
$nCount = $oResultSet->nNumResults; |
---|
116 |
|
---|
117 |
for ( $i=0; $i<$nCount; $i++ ) |
---|
118 |
{ |
---|
119 |
|
---|
120 |
$aRows = $oResultSet->getResultSet( $i ); |
---|
121 |
$oLayer = $oMapSession->oMap->getLayerByName( $aszLayers[$i] ); |
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 |
if ( is_array( $aRows ) ) |
---|
128 |
{ |
---|
129 |
$aResults[$oLayer->index] = $aRows; |
---|
130 |
} |
---|
131 |
else |
---|
132 |
{ |
---|
133 |
|
---|
134 |
if ( strcasecmp(substr( $aRows, 0, 26 ), "no results found for layer" ) != 0 ) |
---|
135 |
{ |
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 |
$aResults[$oLayer->index] = processWMSGetFeatureInfo( $aRows ); |
---|
140 |
|
---|
141 |
} |
---|
142 |
} |
---|
143 |
} |
---|
144 |
} |
---|
145 |
} |
---|
146 |
return $aResults; |
---|
147 |
} |
---|
148 |
|
---|
149 |
function processWMSGetFeatureInfo( $szURL ) |
---|
150 |
{ |
---|
151 |
$aResults = array(); |
---|
152 |
|
---|
153 |
if ( stristr( $szURL, "cubeserv" ) !== false ) |
---|
154 |
{ |
---|
155 |
$szFormat = "application/x-cubestor-gml.1"; |
---|
156 |
$szURL = setURLQueryParam( $szURL, "INFO_FORMAT", $szFormat ); |
---|
157 |
} |
---|
158 |
elseif (stristr( $szURL, "interceptor") !== false ) |
---|
159 |
{ |
---|
160 |
$szFormat = "application/x-cubestor-gml.1"; |
---|
161 |
$szURL = setURLQueryParam( $szURL, "INFO_FORMAT", $szFormat ); |
---|
162 |
} |
---|
163 |
else |
---|
164 |
{ |
---|
165 |
$szFormat = "application/vnd.ogc.gml"; |
---|
166 |
$szURL = setURLQueryParam( $szURL, "INFO_FORMAT", $szFormat ); |
---|
167 |
} |
---|
168 |
$aszRawFile = ""; |
---|
169 |
$nResult = getFeatureInfoResults( $szURL, $aszRawFile ); |
---|
170 |
if ($nResult == -1) |
---|
171 |
{ |
---|
172 |
return $aResults; |
---|
173 |
|
---|
174 |
} |
---|
175 |
elseif ($nResult == 0) |
---|
176 |
{ |
---|
177 |
|
---|
178 |
$szFormat = "text/html"; |
---|
179 |
$szURL = setInfoFormatURL( $szURL, $szFormat ); |
---|
180 |
$nResult = getFeatureInfoResults( $szURL, $aszRawFile ); |
---|
181 |
|
---|
182 |
if ($nResult != 1) |
---|
183 |
return $aResults; |
---|
184 |
} |
---|
185 |
|
---|
186 |
if (strcasecmp( $szFormat, "MIME" ) == 0 || strcasecmp( $szFormat, "text/html" ) == 0) |
---|
187 |
{ |
---|
188 |
$aResults = implode( "", $aszRawFile); |
---|
189 |
} |
---|
190 |
elseif (strcasecmp( $szFormat, "application/x-cubestor-gml.1" ) == 0) |
---|
191 |
{ |
---|
192 |
$szResult = ""; |
---|
193 |
$szXMLDoc = implode( "", $aszRawFile ); |
---|
194 |
if ($szXMLDoc != "") |
---|
195 |
{ |
---|
196 |
$oXMLObj = new XMLObject( $szXMLDoc ); |
---|
197 |
foreach( $oXMLObj->children as $oResult ) |
---|
198 |
{ |
---|
199 |
if (strcasecmp( $oResult->name, "FeatureCollection" ) == 0 ) |
---|
200 |
$aResults = processCubeWerxGML( $oResult ); |
---|
201 |
} |
---|
202 |
} |
---|
203 |
} |
---|
204 |
elseif( strcasecmp( $szFormat, "application/vnd.ogc.gml" ) == 0 ) |
---|
205 |
{ |
---|
206 |
$szResult = ""; |
---|
207 |
$szXMLDoc = implode( "", $aszRawFile); |
---|
208 |
if ($szXMLDoc != "") |
---|
209 |
{ |
---|
210 |
$oXMLObj = new XMLObject( $szXMLDoc ); |
---|
211 |
foreach( $oXMLObj->children as $oResult ) |
---|
212 |
{ |
---|
213 |
if (strcasecmp( $oResult->name, "msGMLOutput" ) == 0 ) |
---|
214 |
$aResults = processMapServerGML( $oResult ); |
---|
215 |
} |
---|
216 |
} |
---|
217 |
} |
---|
218 |
return $aResults; |
---|
219 |
} |
---|
220 |
|
---|
221 |
function getFeatureInfoResults($szURL, &$aszRawFile) |
---|
222 |
{ |
---|
223 |
global $oMLT; |
---|
224 |
|
---|
225 |
|
---|
226 |
$aszRawFile = @file( $szURL ); |
---|
227 |
|
---|
228 |
if ($aszRawFile === false) |
---|
229 |
return -1; |
---|
230 |
else |
---|
231 |
{ |
---|
232 |
$szXMLDoc = trim(implode( "", $aszRawFile)); |
---|
233 |
|
---|
234 |
|
---|
235 |
if ($szXMLDoc == "") |
---|
236 |
{ |
---|
237 |
|
---|
238 |
return 0; |
---|
239 |
} |
---|
240 |
|
---|
241 |
|
---|
242 |
if (stristr($szXMLDoc, "<?xml") === false) |
---|
243 |
{ |
---|
244 |
|
---|
245 |
|
---|
246 |
return 1; |
---|
247 |
} |
---|
248 |
|
---|
249 |
|
---|
250 |
$oXMLObj = new XMLObject( $szXMLDoc ); |
---|
251 |
|
---|
252 |
|
---|
253 |
if (count( $oXMLObj->children ) == 0) |
---|
254 |
{ |
---|
255 |
|
---|
256 |
|
---|
257 |
return 1; |
---|
258 |
} |
---|
259 |
if (strcasecmp($oXMLObj->children[0]->name, "ServiceException") == 0) |
---|
260 |
{ |
---|
261 |
|
---|
262 |
$oXMLObj->dumpObject(); |
---|
263 |
|
---|
264 |
return -1; |
---|
265 |
} |
---|
266 |
|
---|
267 |
|
---|
268 |
return 1; |
---|
269 |
} |
---|
270 |
} |
---|
271 |
|
---|
272 |
|
---|
273 |
|
---|
274 |
function setURLQueryParam( $szURL, $szValue, $szParam ) |
---|
275 |
{ |
---|
276 |
global $oMLT; |
---|
277 |
|
---|
278 |
$aszParts = parse_url( $szURL ); |
---|
279 |
parse_str( $aszParts["query"], $aszQuery ); |
---|
280 |
$aszQuery[$szValue] = $szParam; |
---|
281 |
$szQuery = ""; |
---|
282 |
$szSep = ""; |
---|
283 |
foreach( $aszQuery as $key => $value ) |
---|
284 |
{ |
---|
285 |
$szQuery .= $szSep.$key."=".urlencode( $value ); |
---|
286 |
$szSep = "&"; |
---|
287 |
} |
---|
288 |
$aszParts["query"] = $szQuery; |
---|
289 |
return glue_url( $aszParts ); |
---|
290 |
} |
---|
291 |
|
---|
292 |
|
---|
293 |
|
---|
294 |
function glue_url($parsed) |
---|
295 |
{ |
---|
296 |
if (! is_array($parsed)) |
---|
297 |
return false; |
---|
298 |
$uri = (isset($parsed['scheme'])) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '':'//'): ''; |
---|
299 |
$uri .= (isset($parsed['user'])) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:'').'@':''; |
---|
300 |
$uri .= (isset($parsed['host'])) ? $parsed['host'] : ''; |
---|
301 |
$uri .= (isset($parsed['port'])) ? ':'.$parsed['port'] : ''; |
---|
302 |
$uri .= (isset($parsed['path'])) ? $parsed['path'] : ''; |
---|
303 |
$uri .= (isset($parsed['query'])) ? '?'.$parsed['query'] : ''; |
---|
304 |
$uri .= (isset($parsed['fragment'])) ? '#'.$parsed['fragment'] : ''; |
---|
305 |
return $uri; |
---|
306 |
} |
---|
307 |
|
---|
308 |
|
---|
309 |
|
---|
310 |
function processCubeWerxGML( $oXMLObj ) |
---|
311 |
{ |
---|
312 |
$aResults = array(); |
---|
313 |
|
---|
314 |
foreach($oXMLObj->children as $oMember) |
---|
315 |
{ |
---|
316 |
if (strcasecmp($oMember->name, "featureMember") != 0) |
---|
317 |
continue; |
---|
318 |
|
---|
319 |
$nFeatureMembers ++; |
---|
320 |
|
---|
321 |
$nFeatures = 0; |
---|
322 |
foreach( $oMember->children as $oFeature ) |
---|
323 |
{ |
---|
324 |
if (strcasecmp($oFeature->name, "feature" ) != 0) |
---|
325 |
continue; |
---|
326 |
|
---|
327 |
$aSingleResult = array(); |
---|
328 |
|
---|
329 |
foreach( $oFeature->children as $oProperty ) |
---|
330 |
{ |
---|
331 |
if (strcasecmp($oProperty->name, "property") != 0) |
---|
332 |
continue; |
---|
333 |
|
---|
334 |
$szTypeName = trim((isset($oProperty->typename)) ? |
---|
335 |
$oProperty->typename : trim($oMLT->get("6", "missing typename"))); |
---|
336 |
$szValue = trim((isset($oProperty->value)) ? $oProperty->value : trim($oMLT->get("9", "no value")) ); |
---|
337 |
|
---|
338 |
$aSingleResult[$szTypeName] = $szValue; |
---|
339 |
} |
---|
340 |
$aResults[] = $aSingleResult; |
---|
341 |
} |
---|
342 |
} |
---|
343 |
return $aResults; |
---|
344 |
} |
---|
345 |
|
---|
346 |
|
---|
347 |
|
---|
348 |
|
---|
349 |
function processMapServerGML( $oXMLObj ) |
---|
350 |
{ |
---|
351 |
$aResults = array(); |
---|
352 |
foreach($oXMLObj->children as $oLayer) |
---|
353 |
{ |
---|
354 |
$aSingleResult = array(); |
---|
355 |
foreach( $oLayer->children as $oFeature ) |
---|
356 |
{ |
---|
357 |
foreach( $oFeature->children as $oProperty ) |
---|
358 |
{ |
---|
359 |
$szAttributeName = trim($oProperty->name); |
---|
360 |
$szValue = trim($oProperty->value); |
---|
361 |
$aSingleResult[$szAttributeName] = $szValue; |
---|
362 |
} |
---|
363 |
} |
---|
364 |
$aResults[] = $aSingleResult; |
---|
365 |
} |
---|
366 |
return $aResults; |
---|
367 |
} |
---|
368 |
?> |
---|