python-awips/awips/dataaccess/PyGeometryData.py

64 lines
2 KiB
Python
Raw Permalink Normal View History

2015-06-12 11:57:06 -06:00
##
##
#
# Implements IGeometryData for use by native Python clients to the Data Access
# Framework.
2016-03-16 16:32:17 -05:00
#
#
2015-06-12 11:57:06 -06:00
# SOFTWARE HISTORY
2016-03-16 16:32:17 -05:00
#
2015-06-12 11:57:06 -06:00
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 06/03/13 dgilling Initial Creation.
2017-01-06 12:00:14 -07:00
# 01/06/14 2537 bsteffen Share geometry WKT.
# 03/19/14 2882 dgilling Raise an exception when getNumber()
2016-03-16 16:32:17 -05:00
# is called for data that is not a
2015-06-12 11:57:06 -06:00
# numeric Type.
2017-01-06 12:00:14 -07:00
# 06/09/16 5574 mapeters Handle 'SHORT' type in getNumber().
2016-03-16 16:32:17 -05:00
#
2015-06-12 11:57:06 -06:00
#
2016-03-11 15:05:01 -07:00
from awips.dataaccess import IGeometryData
from awips.dataaccess import PyData
2015-06-12 11:57:06 -06:00
class PyGeometryData(IGeometryData, PyData.PyData):
2016-03-16 16:32:17 -05:00
2015-06-12 11:57:06 -06:00
def __init__(self, geoDataRecord, geometry):
PyData.PyData.__init__(self, geoDataRecord)
self.__geometry = geometry
self.__dataMap = {}
tempDataMap = geoDataRecord.getDataMap()
2016-04-16 17:00:50 -06:00
for key, value in list(tempDataMap.items()):
2015-06-12 11:57:06 -06:00
self.__dataMap[key] = (value[0], value[1], value[2])
def getGeometry(self):
return self.__geometry
2016-03-16 16:32:17 -05:00
def getParameters(self):
2016-04-16 17:00:50 -06:00
return list(self.__dataMap.keys())
2016-03-16 16:32:17 -05:00
2015-06-12 11:57:06 -06:00
def getString(self, param):
value = self.__dataMap[param][0]
2017-04-06 12:14:01 -06:00
return value
2016-03-16 16:32:17 -05:00
def getNumber(self, param):
2015-06-12 11:57:06 -06:00
value = self.__dataMap[param][0]
2016-03-16 16:32:17 -05:00
t = self.getType(param)
2017-01-06 12:00:14 -07:00
if t == 'INT' or t == 'SHORT':
2015-06-12 11:57:06 -06:00
return int(value)
elif t == 'LONG':
2016-04-16 17:00:50 -06:00
return int(value)
2015-06-12 11:57:06 -06:00
elif t == 'FLOAT':
return float(value)
elif t == 'DOUBLE':
return float(value)
else:
raise TypeError("Data for parameter " + param + " is not a numeric type.")
2016-03-16 16:32:17 -05:00
2015-06-12 11:57:06 -06:00
def getUnit(self, param):
return self.__dataMap[param][2]
2016-03-16 16:32:17 -05:00
2015-06-12 11:57:06 -06:00
def getType(self, param):
return self.__dataMap[param][1]