|
2 | 2 | import cgi |
3 | 3 | from urllib import urlencode |
4 | 4 | from urllib2 import HTTPError |
5 | | -from xml.etree.ElementTree import XML |
| 5 | +from xml.etree.ElementTree import fromstring |
| 6 | +from owslib.swe.sensor.sml import SensorML |
| 7 | +import requests |
6 | 8 |
|
7 | 9 | from django.conf import settings |
8 | 10 |
|
@@ -71,6 +73,25 @@ def get_sensors(self, full=False): |
71 | 73 | #ds['description'] = ds['describe_sensor'].sensor_ml.members[0].description |
72 | 74 | ds['description'] = ds['describe_sensor'].sensor_ml.members[0].description if ds['describe_sensor'].sensor_ml.members[0].description else ds['describe_sensor'].sensor_ml.members[0].identifiers['long name'].value |
73 | 75 | ds['isvalid'] = True |
| 76 | + # for output content in the SensorML |
| 77 | + r = requests.get(sensor_id) |
| 78 | + root = fromstring(r.content) |
| 79 | + ns = {'sml': 'http://www.opengis.net/sensorML/1.0.1', 'swe': 'http://www.opengis.net/swe/1.0.1'} |
| 80 | + outputLen = len(root.findall(".//sml:output", ns)) |
| 81 | + outputs = [] |
| 82 | + for i in range(outputLen): |
| 83 | + if root.findall(".//sml:output[@name]", ns)[i].attrib["name"] != 'phenomenonTime': |
| 84 | + oo = {} |
| 85 | + oo["definition"] = root.findall(".//sml:output/swe:Quantity[@definition]", ns)[i-1].attrib["definition"] |
| 86 | + oo["name"] = root.findall(".//sml:output[@name]", ns)[i].attrib["name"] |
| 87 | + try: |
| 88 | + oo["uom"] = root.findall(".//sml:output/swe:Quantity/swe:uom[@code]", ns)[i-1].attrib["code"] |
| 89 | + except: |
| 90 | + oo["uom"] = "" |
| 91 | + outputs.append(oo) |
| 92 | + # outputs.append([root.findall(".//sml:output/swe:Quantity[@definition]", ns)[i-1].attrib["definition"], root.findall(".//sml:output[@name]", ns)[i].attrib["name"]]) |
| 93 | + ds['outputs'] = outputs |
| 94 | + # end output content in the SensorML |
74 | 95 | except: #(AttributeError, IndexError, HTTPError): |
75 | 96 | ds['description'] = 'Invalid Sensor' |
76 | 97 | ds['isvalid'] = False |
|
0 commit comments