@@ -178,6 +178,29 @@ def query(self, identity, origin, service_name, layers, params):
178178 info_response = '<body><html>{layer_infos}</body></html>' .format (layer_infos = "" .join (layer_infos ))
179179 elif output_info_format == 'text/plain' :
180180 info_response = "" .join (layer_infos )
181+ elif output_info_format == 'application/json' :
182+ bbox = list (filter (lambda entry : entry and entry .get ('bbox' ), layer_infos ))
183+ if bbox :
184+ bbox = bbox [0 ]['bbox' ]
185+ for feature in layer_infos :
186+ if feature ['bbox' ]:
187+ bbox = [
188+ min (feature ['bbox' ][0 ], bbox [0 ]),
189+ min (feature ['bbox' ][1 ], bbox [1 ]),
190+ max (feature ['bbox' ][2 ], bbox [2 ]),
191+ max (feature ['bbox' ][3 ], bbox [3 ])
192+ ]
193+ else :
194+ bbox = None
195+ info_response = json .dumps ({
196+ "type" : "FeatureCollection" ,
197+ "bbox" : bbox ,
198+ "crs" :{
199+ "type" : "name" ,
200+ "properties" : {"name" :"urn:ogc:def:crs:%s" % crs .replace (":" , "::" )}
201+ },
202+ "features" : list (filter (bool , layer_infos ))
203+ })
181204 else :
182205 info_response = (
183206 "<GetFeatureInfoResponse>%s</GetFeatureInfoResponse>" %
@@ -433,6 +456,8 @@ def get_layer_info(self, identity, origin, service_name, layer, style, x, y, crs
433456 return ""
434457 elif output_info_format == "text/html" :
435458 return ""
459+ elif output_info_format == "application/json" :
460+ return None
436461 else :
437462 return layer_template .render (
438463 layer_name = layer , layer_title = layer_title ,
@@ -527,6 +552,15 @@ def get_layer_info(self, identity, origin, service_name, layer, style, x, y, crs
527552 for feature in features :
528553 output += "<h2><i>Feature</i>: {fid}</h2>\n {plain_html}\n " .format (fid = feature ['fid' ], plain_html = feature ['plain_html' ])
529554 return "<h1><i>Layer</i>: {layer_title}</h1>\n {output}\n <br />\n " .format (layer_title = layer_title , output = output )
555+ elif output_info_format == 'application/json' :
556+ return {
557+ "type" : "Feature" ,
558+ "layerName" : layer_title ,
559+ "id" : fid ,
560+ "bbox" : bbox ,
561+ "geometry" : wkt .loads (geometry .upper ().replace ('Z' ,'' )),
562+ "properties" : dict (map (lambda entry : (entry ['name' ], entry ['value' ]), attributes ))
563+ }
530564 else :
531565 # render layer template
532566 return layer_template .render (
0 commit comments