Commit 95e8cb83 authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

Added param SCENERY_PATH_OPT to be able to make overlap checks against e.g. Project3000.

parent f8852ea8
......@@ -1206,14 +1206,18 @@ def _parse_ac_file_name(xml_string: str) -> str:
return ac_file_name
def _extract_boundary(ac_filename: str) -> shg.Polygon:
def _extract_boundary(ac_filename: str, alternative_ac_filename: str=None) -> shg.Polygon:
"""Reads an ac-file and constructs a convex hull as a proxy to the real boundary.
No attempt is made to follow rotations and translations.
Returns a tuple (x_min, y_min, x_max, y_max) in meters."""
Returns a tuple (x_min, y_min, x_max, y_max) in meters.
An alternative path is tried, if the first path is not successful"""
numvert = 0
points = list()
with open(ac_filename, 'r') as my_file:
checked_filename = ac_filename
if not os.path.isfile(checked_filename) and alternative_ac_filename is not None:
checked_filename = alternative_ac_filename
with open(checked_filename, 'r') as my_file:
for my_line in my_file:
if 0 == my_line.find("numvert"):
numvert = int(my_line.split()[1])
......@@ -1229,15 +1233,33 @@ def _extract_boundary(ac_filename: str) -> shg.Polygon:
return hull_polygon
def _extract_ac_from_xml(xml_filename: str, alternative_xml_filename: str=None) -> str:
"""Reads the *.ac filename out of an xml-file"""
checked_filename = xml_filename
if not os.path.isfile(checked_filename) and alternative_xml_filename is not None:
checked_filename = alternative_xml_filename
with open(checked_filename, 'r') as f:
xml_data =
ac_filename = _parse_ac_file_name(xml_data)
return ac_filename
def _create_static_obj_boundaries(my_coord_transformation: Transformation) -> Dict[str, shg.Polygon]:
Finds all static objects referenced in stg-files within the scenery boundaries and returns them as a list of
Shapely polygon objects (convex hull of all points in ac-files) in the local x/y coordinate system.
boundaries = dict()
stg_files = calc_tile.get_stg_files_in_boundary(parameters.BOUNDARY_WEST, parameters.BOUNDARY_SOUTH
, parameters.BOUNDARY_EAST, parameters.BOUNDARY_NORTH
, parameters.PATH_TO_SCENERY)
stg_files = calc_tile.get_stg_files_in_boundary(parameters.BOUNDARY_WEST, parameters.BOUNDARY_SOUTH,
parameters.BOUNDARY_EAST, parameters.BOUNDARY_NORTH,
if parameters.PATH_TO_SCENERY_OPT is not None:
stg_files_opt = calc_tile.get_stg_files_in_boundary(parameters.BOUNDARY_WEST, parameters.BOUNDARY_SOUTH,
parameters.BOUNDARY_EAST, parameters.BOUNDARY_NORTH,
for filename in stg_files:
stg_entries = read_stg_entries(filename, parameters.OVERLAP_CHECK_CONSIDER_SHARED)
for entry in stg_entries:
......@@ -1245,13 +1267,12 @@ def _create_static_obj_boundaries(my_coord_transformation: Transformation) -> Di
ac_filename = entry.obj_filename
if ac_filename.endswith(".xml"):
with open(entry.get_obj_path_and_name(), 'r') as f:
xml_data =
ac_filename = _parse_ac_file_name(xml_data)
boundary_polygon = _extract_boundary(entry.get_obj_path_and_name())
boundary_polygon = _extract_boundary(entry.get_obj_path_and_name(),
rotated_polygon = affinity.rotate(boundary_polygon, entry.hdg - 90, (0, 0))
x_y_point = my_coord_transformation.toLocal(Vec2d(entry.lon,
x_y_point = my_coord_transformation.toLocal((entry.lon,
translated_polygon = affinity.translate(rotated_polygon, x_y_point[0], x_y_point[1])
if entry.verb_type is STGVerbType.object_static and parameters.OVERLAP_CHECK_CH_BUFFER_STATIC > 0.01:
boundaries[ac_filename] = translated_polygon.buffer(
......@@ -52,7 +52,11 @@ PREFIX String n/a Name of the
PATH_TO_SCENERY Path n/a Full path to the scenery folder without trailing slash. This is where we will
probe elevation and check for overlap with static objects. Most likely you'll
want to use your TerraSync path here.
want to use your TerraSync path here.
PATH_TO_SCENERY_OPT Path None Optional additional path to a scenery folder (e.g. for `Project3000`_).
Only used for overlap checking for buildings against static and shared
PATH_TO_OUTPUT Path n/a The generated scenery (.stg, .ac, .xml) will be written to this path. If empty
then the correct location in PATH_TO_SCENERY is used. Note that if you use
......@@ -90,6 +94,8 @@ FG_ELEV String n/a Points to t
.. _chapter-parameters-lod-label:
.. _`Project3000`:
.. _`OSM Extended API`:
Level of Details
......@@ -55,6 +55,10 @@ IGNORE_PKL_OVERWRITE = True # -- Ignore overwriting of Cache File
# likely you'll want to use your TerraSync path here.
PATH_TO_SCENERY = "/home/user/fgfs/scenery/TerraSync"
# Optional additional path to a scenery folder (e.g. project3000).
# Only used for overlap checking for buildings against static and shared objects
# -- The generated scenery (.stg, .ac, .xml) will be written to this path.
# If empty, we'll use the correct location in PATH_TO_SCENERY. Note that
# if you use TerraSync for PATH_TO_SCENERY, you MUST choose a different
......@@ -132,9 +132,3 @@ def get_apt_dat_blocked_areas(coords_transform: coordinates.Transformation,
for airport in airports:
return blocked_areas
if __name__ == "__main__":
7.0, 46.0, 10.0, 49.0)
......@@ -2,8 +2,10 @@
shamelessly translated from
import os
from math import floor
import os
from typing import List
import numpy as np
......@@ -139,7 +141,7 @@ def calc_y(lat):
def get_stg_files_in_boundary(boundary_west: float, boundary_south: float, boundary_east: float, boundary_north: float,
path_to_scenery: str):
path_to_scenery: str) -> List[str]:
"""Based on boundary rectangle returns a list of stg-files (incl. full path) to be found within the boundary of
the scenery"""
stg_files = []
......@@ -19,6 +19,7 @@ from typing import List, Optional
from utils import calc_tile
from utils.vec2d import Vec2d
from utils.utilities import assert_trailing_slash
......@@ -224,8 +225,13 @@ class STGEntry(object):
chosen_index = max([slash_index, backslash_index])
self.obj_filename = self.obj_filename[:chosen_index + 1] + new_name
def get_obj_path_and_name(self) -> str:
def get_obj_path_and_name(self, scenery_path: str=None) -> str:
"""Parameter scenery_path is most probably parameters.SCENERY_PATH.
It can be useful to try a different path for shared_objects, which might be from Terrasync."""
if self.verb_type is STGVerbType.object_shared:
if scenery_path is not None:
return assert_trailing_slash(scenery_path) + self.obj_filename
p = os.path.abspath(self.stg_path + os.sep + '..' + os.sep + '..' + os.sep + '..')
return os.path.abspath(p + os.sep + self.obj_filename)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment