X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=code%2Fnetwork-generator%2Fmodel%2Fpython%2Fgeo_location.py;h=0dd344bac7730406b1e3e4576740960854f070da;hb=eb61f78711dc62a2c230602ea49f72e9e4a10978;hp=67d098ebe38e2e30fd1175a663e600d0f6be4ddc;hpb=9ea4e241e3ec0c9dffd3db7fd7ab5a2cf3d13e7d;p=oam.git diff --git a/code/network-generator/model/python/geo_location.py b/code/network-generator/model/python/geo_location.py index 67d098e..0dd344b 100644 --- a/code/network-generator/model/python/geo_location.py +++ b/code/network-generator/model/python/geo_location.py @@ -17,19 +17,25 @@ """ A collection of TypeDefinitions for a geographical location """ +import math +from model.python.point 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 self.aboveMeanSeaLevel = aboveMeanSeaLevel - def __str__(self): + def __str__(self)-> str: return f'lat : {self.latitude} : lon : {self.longitude} : amsl : {self.aboveMeanSeaLevel}' @@ -39,17 +45,17 @@ 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 - def equatorialRadius(self): + def equatorialRadius(self) -> int: return GeoLocation._equatorialRadius @property - def polarRadius(self): + def polarRadius(self)-> int: return GeoLocation._polarRadius def set_latitude(self, value: float): @@ -62,12 +68,30 @@ class GeoLocation(IGeoLocation): raise ValueError('Invalid longitude. Longitude must be between -180 and 180.') self.longitude = value - def json(self): + def json(self) -> dict[str, float]: return { "latitude": self.latitude, "longitude": self.longitude, "aboveMeanSeaLevel": self.aboveMeanSeaLevel, } - def __str__(self): - return str(self.json()) \ No newline at end of file + def __str__(self) -> str: + 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