Ensure that only Cells cover a geographical area
[oam.git] / code / network-generator / model / python / nr_cell_du.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 Class representing a 3GPP new radio cell du (NrCellDu)
19 """
20 from model.python.o_ran_object import IORanObject
21 from model.python.o_ran_node import ORanNode
22 import model.python.hexagon as Hexagon
23 from model.python.point import Point
24 from model.python.geo_location import GeoLocation
25 import xml.etree.ElementTree as ET
26
27
28 # Define the "INrCellDu" interface
29 class INrCellDu(IORanObject):
30     def __init__(self, cell_angel: int, azimuth: int, **kwargs):
31         super().__init__(**kwargs)
32         self._cell_angle = cell_angle
33         self._azimuth = azimuth
34
35
36 # Define an abstract O-RAN Node class
37 class NrCellDu(ORanNode, INrCellDu):
38     def __init__(self, cell_data: INrCellDu = None, **kwargs):
39         super().__init__(cell_data, **kwargs)
40         self._cell_angle = (
41             cell_data["cellAngle"] if cell_data and "cellAngle" in cell_data else 120
42         )
43         self._azimuth = (
44             cell_data["azimuth"] if cell_data and "azimuth" in cell_data else 0
45         )
46
47     def toKml(self) -> ET.Element:
48         placemark: ET.Element = ET.Element("Placemark")
49         name: ET.Element = ET.SubElement(placemark, "name")
50         name.text = self.name
51         style: ET.Element = ET.SubElement(placemark, "styleUrl")
52         style.text = "#" + self.__class__.__name__
53         multi_geometry: ET.Element = ET.SubElement(placemark, "MultiGeometry")
54         polygon: ET.Element = ET.SubElement(multi_geometry, "Polygon")
55         outer_boundary: ET.Element = ET.SubElement(polygon, "outerBoundaryIs")
56         linear_ring: ET.Element = ET.SubElement(outer_boundary, "LinearRing")
57         coordinates: ET.Element = ET.SubElement(linear_ring, "coordinates")
58
59         points: list[Point] = Hexagon.polygon_corners(self.layout, self.position)
60         method = GeoLocation(
61             self.parent.parent.parent.parent.parent.parent.geoLocation
62         ).point_to_geo_location
63         geo_locations: list[GeoLocation] = list(map(method, points))
64         text: list[str] = []
65
66
67         index: int = 1 + int(self._azimuth/self._cell_angle) 
68         network_center:GeoLocation =  GeoLocation(self.parent.parent.parent.parent.parent.parent.geoLocation)
69
70         intersect1: Point = Point(
71             (points[(2 * index +1) % 6].x + points[(2 * index +2) % 6].x) / 2,
72             (points[(2 * index +1) % 6].y + points[(2 * index +2) % 6].y) / 2,
73         )
74         intersect_geo_location1: GeoLocation = network_center.point_to_geo_location(intersect1)
75         
76         intersect2: Point = Point(
77             (points[(2 * index +3) % 6].x + points[(2 * index +4) % 6].x) / 2,
78             (points[(2 * index +3) % 6].y + points[(2 * index +4) % 6].y) / 2,
79         )
80         intersect_geo_location2: GeoLocation = network_center.point_to_geo_location(intersect2)
81
82         tower:GeoLocation =  GeoLocation(self.geoLocation)
83
84         cell_polygon: list[GeoLocation] = []
85         cell_polygon.append(tower)
86         cell_polygon.append(intersect_geo_location1)
87         cell_polygon.append(geo_locations[(2 * index + 2) % 6])
88         cell_polygon.append(geo_locations[(2 * index + 3) % 6])
89         cell_polygon.append(intersect_geo_location2)
90         # close polygon
91         cell_polygon.append(tower)
92         
93         for geo_location in cell_polygon:
94             text.append(
95                 f"{'%.6f' % geo_location.longitude},{'%.6f' % geo_location.latitude},{'%.6f' % geo_location.aboveMeanSeaLevel}"
96             )
97         coordinates.text = " ".join(text)
98
99         return placemark
100
101     def toSvg(self) -> None:
102         return None