35 from .
import locationevent_pb2
41 self.
_event = locationevent_pb2.LocationEvent()
56 location = self.
_event.locations.add()
58 location.nemId = nemId
61 for (name,value)
in list(kwargs.items()):
63 if name ==
'latitude':
64 if isinstance(value,int)
or \
65 isinstance(value,float):
67 location.position.latitudeDegrees = value
69 raise ValueError(
"latitude must be numeric")
71 elif name ==
'longitude':
72 if isinstance(value,int)
or \
73 isinstance(value,float):
75 location.position.longitudeDegrees = value
77 raise ValueError(
"longitude must be numeric")
79 elif name ==
'altitude':
80 if isinstance(value,int)
or \
81 isinstance(value,float):
83 location.position.altitudeMeters = value
85 raise ValueError(
"altitude must be numeric")
87 elif name ==
'azimuth':
88 if isinstance(value,int)
or \
89 isinstance(value,float):
91 location.velocity.azimuthDegrees = value
93 raise ValueError(
"azimuth must be numeric")
95 elif name ==
'elevation':
96 if isinstance(value,int)
or \
97 isinstance(value,float):
99 location.velocity.elevationDegrees = value
101 raise ValueError(
"elevation must be numeric")
103 elif name ==
'magnitude':
104 if isinstance(value,int)
or \
105 isinstance(value,float):
107 location.velocity.magnitudeMetersPerSecond = value
109 raise ValueError(
"magnitude must be numeric")
112 if isinstance(value,int)
or \
113 isinstance(value,float):
115 location.orientation.rollDegrees = value
117 raise ValueError(
"roll must be numeric")
119 elif name ==
'pitch':
120 if isinstance(value,int)
or \
121 isinstance(value,float):
123 location.orientation.pitchDegrees = value
125 raise ValueError(
"pitch must be numeric")
128 if isinstance(value,int)
or \
129 isinstance(value,float):
131 location.orientation.yawDegrees = value
133 raise ValueError(
"yaw must be numeric")
136 raise KeyError(
"unknown parameter: %s" % name)
138 if not (hasLatitude
and hasLongitude
and hasAltitude):
139 raise KeyError(
"must specify latitude, longitude and altitude")
141 if (hasAzimuth
and not (hasElevation
and hasMagnitude))
or \
142 (hasElevation
and not (hasAzimuth
and hasMagnitude))
or \
143 (hasMagnitude
and not (hasAzimuth
and hasElevation)):
144 raise KeyError(
"must specify azimuth, elevation and magnitude when specifing velocity")
146 if (hasRoll
and not (hasPitch
and hasYaw))
or \
147 (hasPitch
and not (hasRoll
and hasYaw))
or \
148 (hasYaw
and not (hasRoll
and hasPitch)):
149 raise KeyError(
"must specify roll, pitch and yaw when specifing orientation")
152 return self.
_event.SerializeToString()
155 self.
_event.ParseFromString(data)
158 for location
in self.
_event.locations:
159 kwargs = {
'latitude':location.position.latitudeDegrees,
160 'longitude' : location.position.longitudeDegrees,
161 'altitude' : location.position.altitudeMeters}
163 if location.HasField(
'velocity'):
164 kwargs[
'azimuth'] = location.velocity.azimuthDegrees
165 kwargs[
'elevation'] = location.velocity.elevationDegrees
166 kwargs[
'magnitude'] = location.velocity.magnitudeMetersPerSecond
168 if location.HasField(
'orientation'):
169 kwargs[
'roll'] = location.orientation.rollDegrees
170 kwargs[
'pitch'] = location.orientation.pitchDegrees
171 kwargs[
'yaw'] = location.orientation.yawDegrees
174 yield (location.nemId,kwargs)
def append(self, nemId, kwargs)