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
22 from network_generation.model.python.point import Point
25 class IGeoLocationData:
27 self, latitude: float, longitude: float, aboveMeanSeaLevel: float
29 self.latitude = latitude
30 self.longitude = longitude
31 self.aboveMeanSeaLevel = aboveMeanSeaLevel
39 aboveMeanSeaLevel: float = 0,
41 self.latitude = latitude
42 self.longitude = longitude
43 self.aboveMeanSeaLevel = aboveMeanSeaLevel
45 def __str__(self) -> str:
46 return f"lat : {self.latitude} : lon : {self.longitude} : amsl : {self.aboveMeanSeaLevel}"
49 class GeoLocation(IGeoLocation):
50 _equatorialRadius = 6378137 # meters
51 _polarRadius = 6356752 # meters
53 def __init__(self, geoLocation: IGeoLocationData = None):
55 geoLocation["latitude"] if geoLocation else 0,
56 geoLocation["longitude"] if geoLocation else 0,
57 geoLocation["aboveMeanSeaLevel"] if geoLocation else 0,
61 def equatorialRadius(self) -> int:
62 return GeoLocation._equatorialRadius
65 def polarRadius(self) -> int:
66 return GeoLocation._polarRadius
68 def set_latitude(self, value: float):
69 if not (-90 <= value <= 90):
71 "Invalid latitude. Latitude must be between -90 and 90."
75 def set_longitude(self, value: float):
76 if not (-180 <= value <= 180):
78 "Invalid longitude. Longitude must be between -180 and 180."
80 self.longitude = value
82 def json(self) -> dict[str, float]:
84 "latitude": self.latitude,
85 "longitude": self.longitude,
86 "aboveMeanSeaLevel": self.aboveMeanSeaLevel,
89 def __str__(self) -> str:
90 return str(self.json())
92 def point_to_geo_location(self, point: Point):
94 A static function which converts a point in pixels into a geographical location
95 when the self is represented as Point(0,0)
96 @param point : The point to be converted
97 returns The converted GeoLocation object.
99 equatorialRadius = 6378137 # meters
100 new_lat = self.latitude + (point.y / equatorialRadius) * (
103 new_lon = self.longitude + (point.x / equatorialRadius) * (
105 ) / math.cos(self.latitude * math.pi / 180)
107 geo_location: IGeoLocationData = {
108 "longitude": new_lon,
110 "aboveMeanSeaLevel": self.aboveMeanSeaLevel,
112 return GeoLocation(geo_location)