1 | # |
||
2 | # Implements IGeometryData for use by native Python clients to the Data Access |
||
3 | # Framework. |
||
4 | # |
||
5 | # |
||
6 | # SOFTWARE HISTORY |
||
7 | # |
||
8 | # Date Ticket# Engineer Description |
||
9 | # ------------ ---------- ----------- -------------------------- |
||
10 | # 06/03/13 dgilling Initial Creation. |
||
11 | # 01/06/14 2537 bsteffen Share geometry WKT. |
||
12 | # 03/19/14 2882 dgilling Raise an exception when getNumber() |
||
13 | # is called for data that is not a |
||
14 | # numeric Type. |
||
15 | # 06/09/16 5574 mapeters Handle 'SHORT' type in getNumber(). |
||
16 | # 10/05/18 mjames@ucar Encode/decode string, number val, and type |
||
17 | # |
||
18 | # |
||
19 | |||
20 | from awips.dataaccess import IGeometryData |
||
21 | from awips.dataaccess import PyData |
||
22 | import six |
||
23 | |||
24 | |||
25 | View Code Duplication | class PyGeometryData(IGeometryData, PyData.PyData): |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
26 | |||
27 | def __init__(self, geoDataRecord, geometry): |
||
28 | PyData.PyData.__init__(self, geoDataRecord) |
||
29 | self.__geometry = geometry |
||
30 | self.__dataMap = {} |
||
31 | tempDataMap = geoDataRecord.getDataMap() |
||
32 | for key, value in list(tempDataMap.items()): |
||
33 | self.__dataMap[key] = (value[0], value[1], value[2]) |
||
34 | |||
35 | def getGeometry(self): |
||
36 | return self.__geometry |
||
37 | |||
38 | def getParameters(self): |
||
39 | if six.PY2: |
||
40 | return list(self.__dataMap.keys()) |
||
41 | else: |
||
42 | return [x.decode('utf-8') for x in list(self.__dataMap.keys())] |
||
43 | |||
44 | def getString(self, param): |
||
45 | if six.PY2: |
||
46 | return self.__dataMap[param][0] |
||
47 | value = self.__dataMap[param.encode('utf-8')][0] |
||
48 | if isinstance(value, bytes): |
||
49 | return str(value.decode('utf-8')) |
||
50 | return str(value) |
||
51 | |||
52 | def getNumber(self, param): |
||
53 | t = self.getType(param) |
||
54 | if six.PY2: |
||
55 | value = self.__dataMap[param][0] |
||
56 | else: |
||
57 | value = self.__dataMap[param.encode('utf-8')][0] |
||
58 | if t == 'INT' or t == 'SHORT' or t == 'LONG': |
||
59 | return int(value) |
||
60 | elif t == 'FLOAT': |
||
61 | return float(value) |
||
62 | elif t == 'DOUBLE': |
||
63 | return float(value) |
||
64 | else: |
||
65 | raise TypeError("Data for parameter " + param + " is not a numeric type.") |
||
66 | |||
67 | def getUnit(self, param): |
||
68 | if six.PY2: |
||
69 | return self.__dataMap[param][2] |
||
70 | unit = self.__dataMap[param.encode('utf-8')][2] |
||
71 | if unit is not None: |
||
72 | return unit.decode('utf-8') |
||
73 | return unit |
||
74 | |||
75 | def getType(self, param): |
||
76 | if six.PY2: |
||
77 | return self.__dataMap[param][1] |
||
78 | datatype = self.__dataMap[param.encode('utf-8')][1] |
||
79 | if datatype is not None: |
||
80 | return datatype.decode('utf-8') |
||
81 | return datatype |
||
82 |