Use python file name conventions
[oam.git] / code / network-generator / model / python / geo_location.py
1 # Copyright 2023 highstreet technologies GmbH
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 #!/usr/bin/python
16
17 """
18 A collection of TypeDefinitions for a geographical location
19 """
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
25
26 class IGeoLocation:
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
31
32     def __str__(self):
33         return f'lat : {self.latitude} : lon : {self.longitude} : amsl : {self.aboveMeanSeaLevel}'
34
35
36 class GeoLocation(IGeoLocation):
37     _equatorialRadius = 6378137  # meters
38     _polarRadius = 6356752  # meters
39
40     def __init__(self, geoLocation: IGeoLocationData = None):
41         super().__init__(
42             geoLocation.latitude if geoLocation else 0,
43             geoLocation.longitude if geoLocation else 0,
44             geoLocation.aboveMeanSeaLevel if geoLocation else 0
45         )
46
47     @property
48     def equatorialRadius(self):
49         return GeoLocation._equatorialRadius
50
51     @property
52     def polarRadius(self):
53         return GeoLocation._polarRadius
54
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.')
58         self.latitude = value
59
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
64
65     def json(self):
66         return {
67             "latitude": self.latitude, 
68             "longitude": self.longitude, 
69             "aboveMeanSeaLevel": self.aboveMeanSeaLevel,      
70         }
71     
72     def __str__(self):
73         return str(self.json())