Create concrete classes for O-RAN Nodes 36/11936/1
authorMartin Skorupski <martin.skorupski@highstreet-technologies.com>
Wed, 18 Oct 2023 13:24:24 +0000 (15:24 +0200)
committerMartin Skorupski <martin.skorupski@highstreet-technologies.com>
Wed, 18 Oct 2023 13:24:30 +0000 (15:24 +0200)
- a function added to convert a Point(x,y) into a new
  geographical location where 'self' is represented as Point(0,0)

Issue-ID: OAM-368
Change-Id: I7df2e1319d6d5c38c290b02b711c1213e2319f8f
Signed-off-by: Martin Skorupski <martin.skorupski@highstreet-technologies.com>
code/network-generator/model/python/geo_location.py

index 67d098e..6d60fc0 100644 (file)
 """
 A collection of TypeDefinitions for a geographical location
 """
+import math
+from model.python.hexagon import Point
+
+
 class IGeoLocationData:
+
     def __init__(self, latitude: float, longitude: float, aboveMeanSeaLevel: float):
         self.latitude = latitude
         self.longitude = longitude
         self.aboveMeanSeaLevel = aboveMeanSeaLevel
 
 class IGeoLocation:
+
     def __init__(self, latitude: float = 0, longitude: float = 0, aboveMeanSeaLevel: float = 0):
         self.latitude = latitude
         self.longitude = longitude
@@ -39,9 +45,9 @@ class GeoLocation(IGeoLocation):
 
     def __init__(self, geoLocation: IGeoLocationData = None):
         super().__init__(
-            geoLocation.latitude if geoLocation else 0,
-            geoLocation.longitude if geoLocation else 0,
-            geoLocation.aboveMeanSeaLevel if geoLocation else 0
+            geoLocation['latitude'] if geoLocation else 0,
+            geoLocation['longitude'] if geoLocation else 0,
+            geoLocation['aboveMeanSeaLevel'] if geoLocation else 0
         )
 
     @property
@@ -70,4 +76,22 @@ class GeoLocation(IGeoLocation):
         }
     
     def __str__(self):
-        return str(self.json())
\ No newline at end of file
+        return str(self.json())
+    
+    def point_to_geo_location(self, point:Point):
+        """
+        A static function which converts a point in pixels into a geographical location
+        when the self is represented as Point(0,0)
+        @param point : The point to be converted
+        returns The converted GeoLocation object.
+        """
+        equatorialRadius = 6378137  # meters
+        new_lat = self.latitude + (point.y / equatorialRadius) * (180 / math.pi)
+        new_lon = self.longitude + (point.x / equatorialRadius) * (180 / math.pi) / math.cos(self.latitude * math.pi / 180)
+
+        geo_location: IGeoLocationData = {
+            "longitude": new_lon,
+            "latitude": new_lat,
+            "aboveMeanSeaLevel": self.aboveMeanSeaLevel
+        }
+        return GeoLocation(geo_location)
\ No newline at end of file