2018-09-05 15:52:38 -06:00
|
|
|
#
|
|
|
|
# Implements IGeometryData for use by native Python clients to the Data Access
|
|
|
|
# Framework.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# SOFTWARE HISTORY
|
|
|
|
#
|
|
|
|
# Date Ticket# Engineer Description
|
|
|
|
# ------------ ---------- ----------- --------------------------
|
|
|
|
# 06/03/13 dgilling Initial Creation.
|
|
|
|
# 01/06/14 2537 bsteffen Share geometry WKT.
|
|
|
|
# 03/19/14 2882 dgilling Raise an exception when getNumber()
|
|
|
|
# is called for data that is not a
|
|
|
|
# numeric Type.
|
|
|
|
# 06/09/16 5574 mapeters Handle 'SHORT' type in getNumber().
|
2018-10-05 17:11:49 -06:00
|
|
|
# 10/05/18 mjames@ucar Encode/decode string, number val, and type
|
2018-09-05 15:52:38 -06:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
from awips.dataaccess import IGeometryData
|
|
|
|
from awips.dataaccess import PyData
|
2018-10-09 14:24:43 -06:00
|
|
|
import six
|
2018-09-05 15:52:38 -06:00
|
|
|
|
2018-10-16 12:35:18 -06:00
|
|
|
|
2018-09-05 15:52:38 -06:00
|
|
|
class PyGeometryData(IGeometryData, PyData.PyData):
|
|
|
|
|
|
|
|
def __init__(self, geoDataRecord, geometry):
|
|
|
|
PyData.PyData.__init__(self, geoDataRecord)
|
|
|
|
self.__geometry = geometry
|
|
|
|
self.__dataMap = {}
|
|
|
|
tempDataMap = geoDataRecord.getDataMap()
|
2018-09-06 12:11:36 -06:00
|
|
|
for key, value in list(tempDataMap.items()):
|
2018-09-05 15:52:38 -06:00
|
|
|
self.__dataMap[key] = (value[0], value[1], value[2])
|
|
|
|
|
|
|
|
def getGeometry(self):
|
|
|
|
return self.__geometry
|
|
|
|
|
|
|
|
def getParameters(self):
|
2018-10-09 14:24:43 -06:00
|
|
|
if six.PY2:
|
|
|
|
return list(self.__dataMap.keys())
|
|
|
|
else:
|
|
|
|
return [x.decode('utf-8') for x in list(self.__dataMap.keys())]
|
2018-09-05 15:52:38 -06:00
|
|
|
|
|
|
|
def getString(self, param):
|
2018-10-09 14:24:43 -06:00
|
|
|
if six.PY2:
|
2018-10-15 08:19:21 -06:00
|
|
|
return self.__dataMap[param][0]
|
|
|
|
value = self.__dataMap[param.encode('utf-8')][0]
|
2018-10-16 22:27:46 -06:00
|
|
|
if isinstance(value, bytes):
|
2018-10-15 08:09:09 -06:00
|
|
|
return str(value.decode('utf-8'))
|
2018-10-16 22:27:46 -06:00
|
|
|
return str(value)
|
2018-09-05 15:52:38 -06:00
|
|
|
|
|
|
|
def getNumber(self, param):
|
|
|
|
t = self.getType(param)
|
2018-10-09 15:04:11 -06:00
|
|
|
if six.PY2:
|
|
|
|
value = self.__dataMap[param][0]
|
|
|
|
else:
|
|
|
|
value = self.__dataMap[param.encode('utf-8')][0]
|
2018-10-05 17:11:49 -06:00
|
|
|
if t == 'INT' or t == 'SHORT' or t == 'LONG':
|
2018-09-06 12:11:36 -06:00
|
|
|
return int(value)
|
2018-09-05 15:52:38 -06:00
|
|
|
elif t == 'FLOAT':
|
|
|
|
return float(value)
|
|
|
|
elif t == 'DOUBLE':
|
|
|
|
return float(value)
|
|
|
|
else:
|
2018-10-09 09:33:28 -06:00
|
|
|
raise TypeError("Data for parameter " + param + " is not a numeric type.")
|
2018-09-05 15:52:38 -06:00
|
|
|
|
|
|
|
def getUnit(self, param):
|
2018-10-09 14:24:43 -06:00
|
|
|
if six.PY2:
|
2018-10-15 16:27:32 -06:00
|
|
|
return self.__dataMap[param][2]
|
|
|
|
unit = self.__dataMap[param.encode('utf-8')][2]
|
2018-10-09 14:24:43 -06:00
|
|
|
if unit is not None:
|
|
|
|
return unit.decode('utf-8')
|
2018-10-09 09:33:28 -06:00
|
|
|
return unit
|
2018-09-05 15:52:38 -06:00
|
|
|
|
|
|
|
def getType(self, param):
|
2018-10-09 14:24:43 -06:00
|
|
|
if six.PY2:
|
|
|
|
return self.__dataMap[param][1]
|
2018-10-16 12:35:18 -06:00
|
|
|
datatype = self.__dataMap[param.encode('utf-8')][1]
|
|
|
|
if datatype is not None:
|
|
|
|
return datatype.decode('utf-8')
|
|
|
|
return datatype
|