1 # Copyright 2023 highstreet technologies GmbH
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 A collection of TypeDefinitions for a geographical location
20 class IGeoLocationData:
21 def __init__(self, latitude: float, longitude: float, aboveMeanSeaLevel: float):
22 self.latitude = latitude
23 self.longitude = longitude
24 self.aboveMeanSeaLevel = aboveMeanSeaLevel
27 def __init__(self, latitude: float = 0, longitude: float = 0, aboveMeanSeaLevel: float = 0):
28 self.latitude = latitude
29 self.longitude = longitude
30 self.aboveMeanSeaLevel = aboveMeanSeaLevel
33 return f'lat : {self.latitude} : lon : {self.longitude} : amsl : {self.aboveMeanSeaLevel}'
36 class GeoLocation(IGeoLocation):
37 _equatorialRadius = 6378137 # meters
38 _polarRadius = 6356752 # meters
40 def __init__(self, geoLocation: IGeoLocationData = None):
42 geoLocation.latitude if geoLocation else 0,
43 geoLocation.longitude if geoLocation else 0,
44 geoLocation.aboveMeanSeaLevel if geoLocation else 0
48 def equatorialRadius(self):
49 return GeoLocation._equatorialRadius
52 def polarRadius(self):
53 return GeoLocation._polarRadius
55 def set_latitude(self, value: float):
56 if not (-90 <= value <= 90):
57 raise ValueError('Invalid latitude. Latitude must be between -90 and 90.')
60 def set_longitude(self, value: float):
61 if not (-180 <= value <= 180):
62 raise ValueError('Invalid longitude. Longitude must be between -180 and 180.')
63 self.longitude = value
67 "latitude": self.latitude,
68 "longitude": self.longitude,
69 "aboveMeanSeaLevel": self.aboveMeanSeaLevel,
73 return str(self.json())