Skip to content

Commit

Permalink
Minor code updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Jan 8, 2025
1 parent 195ba6f commit 3573877
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
17 changes: 4 additions & 13 deletions maps4fs/generator/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def get_bbox(
self,
coordinates: tuple[float, float] | None = None,
distance: int | None = None,
project_utm: bool = False,
) -> tuple[int, int, int, int]:
"""Calculates the bounding box of the map from the coordinates and the height and
width of the map.
Expand All @@ -199,7 +198,6 @@ def get_bbox(
of the map. Defaults to None.
distance (int, optional): The distance from the center of the map to the edge of the
map in all directions. Defaults to None.
project_utm (bool, optional): Whether to project the bounding box to UTM.
Returns:
tuple[int, int, int, int]: The bounding box of the map.
Expand All @@ -208,15 +206,15 @@ def get_bbox(
distance = distance or int(self.map_rotated_size / 2)

west, south, east, north = ox.utils_geo.bbox_from_point( # type: ignore
coordinates, dist=distance, project_utm=project_utm
coordinates,
dist=distance,
)

bbox = north, south, east, west
self.logger.debug(
"Calculated bounding box for component: %s: %s, project_utm: %s, distance: %s",
"Calculated bounding box for component: %s: %s, distance: %s",
self.__class__.__name__,
bbox,
project_utm,
distance,
)
return bbox
Expand All @@ -225,7 +223,7 @@ def save_bbox(self) -> None:
"""Saves the bounding box of the map to the component instance from the coordinates and the
height and width of the map.
"""
self.bbox = self.get_bbox(project_utm=False)
self.bbox = self.get_bbox()
self.logger.debug("Saved bounding box: %s", self.bbox)

@property
Expand Down Expand Up @@ -544,17 +542,10 @@ def get_z_scaling_factor(self) -> float:
"""

scaling_factor = 1 / self.map.dem_settings.multiplier
self.logger.debug("Z scaling factor including DEM multiplier: %s", scaling_factor)

if self.map.shared_settings.height_scale_multiplier:
scaling_factor *= self.map.shared_settings.height_scale_multiplier
self.logger.debug(
"Z scaling factor including height scale multiplier: %s", scaling_factor
)
if self.map.shared_settings.mesh_z_scaling_factor:
scaling_factor *= 1 / self.map.shared_settings.mesh_z_scaling_factor
self.logger.debug(
"Z scaling factor including mesh z scaling factor: %s", scaling_factor
)

return scaling_factor
14 changes: 7 additions & 7 deletions maps4fs/generator/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def rotate_textures(self) -> None:
# pylint: disable=W0201
def _read_parameters(self) -> None:
"""Reads map parameters from OSM data, such as:
- minimum and maximum coordinates in UTM format
- minimum and maximum coordinates
- map dimensions in meters
- map coefficients (meters per pixel)
"""
Expand Down Expand Up @@ -727,36 +727,36 @@ def objects_generator(
yield from method(objects, width, is_fieds)

def linestrings_generator(
self, objects_utm: pd.core.frame.DataFrame, *args, **kwargs
self, objects: pd.core.frame.DataFrame, *args, **kwargs
) -> Generator[list[tuple[int, int]], None, None]:
"""Generator which yields lists of point coordinates which represent LineStrings from OSM.
Arguments:
objects_utm (pd.core.frame.DataFrame): Dataframe with OSM objects in UTM format.
objects (pd.core.frame.DataFrame): Dataframe with OSM objects.
Yields:
Generator[list[tuple[int, int]], None, None]: List of point coordinates.
"""
for _, obj in objects_utm.iterrows():
for _, obj in objects.iterrows():
geometry = obj["geometry"]
if isinstance(geometry, shapely.geometry.linestring.LineString):
points = [self.latlon_to_pixel(x, y) for y, x in geometry.coords]
yield points

def polygons_generator(
self, objects_utm: pd.core.frame.DataFrame, width: int | None, is_fieds: bool
self, objects: pd.core.frame.DataFrame, width: int | None, is_fieds: bool
) -> Generator[np.ndarray, None, None]:
"""Generator which yields numpy arrays of polygons from OSM data.
Arguments:
objects_utm (pd.core.frame.DataFrame): Dataframe with OSM objects in UTM format.
objects (pd.core.frame.DataFrame): Dataframe with OSM objects.
width (int | None): Width of the polygon in meters (only for LineString).
is_fieds (bool): Flag to determine if the fields should be padded.
Yields:
Generator[np.ndarray, None, None]: Numpy array of polygon points.
"""
for _, obj in objects_utm.iterrows():
for _, obj in objects.iterrows():
try:
polygon = self._to_polygon(obj, width)
except Exception as e: # pylint: disable=W0703
Expand Down

0 comments on commit 3573877

Please sign in to comment.