maps4fs 1.3.7__tar.gz → 1.3.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of maps4fs might be problematic. Click here for more details.

Files changed (27) hide show
  1. {maps4fs-1.3.7 → maps4fs-1.3.8}/PKG-INFO +1 -1
  2. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/texture.py +65 -6
  3. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs.egg-info/PKG-INFO +1 -1
  4. {maps4fs-1.3.7 → maps4fs-1.3.8}/pyproject.toml +1 -1
  5. {maps4fs-1.3.7 → maps4fs-1.3.8}/LICENSE.md +0 -0
  6. {maps4fs-1.3.7 → maps4fs-1.3.8}/README.md +0 -0
  7. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/__init__.py +0 -0
  8. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/__init__.py +0 -0
  9. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/background.py +0 -0
  10. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/component.py +0 -0
  11. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/config.py +0 -0
  12. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/dem.py +0 -0
  13. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/game.py +0 -0
  14. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/grle.py +0 -0
  15. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/i3d.py +0 -0
  16. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/map.py +0 -0
  17. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/generator/qgis.py +0 -0
  18. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/logger.py +0 -0
  19. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/toolbox/__init__.py +0 -0
  20. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/toolbox/background.py +0 -0
  21. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs/toolbox/dem.py +0 -0
  22. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs.egg-info/SOURCES.txt +0 -0
  23. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs.egg-info/dependency_links.txt +0 -0
  24. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs.egg-info/requires.txt +0 -0
  25. {maps4fs-1.3.7 → maps4fs-1.3.8}/maps4fs.egg-info/top_level.txt +0 -0
  26. {maps4fs-1.3.7 → maps4fs-1.3.8}/setup.cfg +0 -0
  27. {maps4fs-1.3.7 → maps4fs-1.3.8}/tests/test_generator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maps4fs
3
- Version: 1.3.7
3
+ Version: 1.3.8
4
4
  Summary: Generate map templates for Farming Simulator from real places.
5
5
  Author-email: iwatkot <iwatkot@gmail.com>
6
6
  License: MIT License
@@ -372,7 +372,7 @@ class Texture(Component):
372
372
  ),
373
373
  )
374
374
 
375
- # pylint: disable=no-member
375
+ # pylint: disable=no-member, R0912
376
376
  def draw(self) -> None:
377
377
  """Iterates over layers and fills them with polygons from OSM data."""
378
378
  layers = self.layers_by_priority()
@@ -409,11 +409,23 @@ class Texture(Component):
409
409
 
410
410
  mask = cv2.bitwise_not(cumulative_image)
411
411
 
412
- for polygon in self.polygons(layer.tags, layer.width, layer.info_layer): # type: ignore
412
+ for polygon in self.objects_generator( # type: ignore
413
+ layer.tags, layer.width, layer.info_layer
414
+ ):
413
415
  if layer.info_layer:
414
- info_layer_data[layer.info_layer].append(self.np_to_polygon_points(polygon))
416
+ info_layer_data[layer.info_layer].append(
417
+ self.np_to_polygon_points(polygon) # type: ignore
418
+ )
415
419
  cv2.fillPoly(layer_image, [polygon], color=255) # type: ignore
416
420
 
421
+ if layer.info_layer == "roads":
422
+ for linestring in self.objects_generator(
423
+ layer.tags, layer.width, layer.info_layer, yield_linestrings=True
424
+ ):
425
+ info_layer_data[f"{layer.info_layer}_polylines"].append(
426
+ linestring # type: ignore
427
+ )
428
+
417
429
  output_image = cv2.bitwise_and(layer_image, mask)
418
430
 
419
431
  cumulative_image = cv2.bitwise_or(cumulative_image, output_image)
@@ -422,8 +434,16 @@ class Texture(Component):
422
434
  self.logger.debug("Texture %s saved.", layer_path)
423
435
 
424
436
  # Save info layer data.
437
+ if os.path.isfile(self.info_layer_path):
438
+ self.logger.debug(
439
+ "File %s already exists, will update to avoid overwriting.", self.info_layer_path
440
+ )
441
+ with open(self.info_layer_path, "r", encoding="utf-8") as f:
442
+ info_layer_data.update(json.load(f))
443
+
425
444
  with open(self.info_layer_path, "w", encoding="utf-8") as f:
426
445
  json.dump(info_layer_data, f, ensure_ascii=False, indent=4)
446
+ self.logger.debug("Info layer data saved to %s.", self.info_layer_path)
427
447
 
428
448
  if cumulative_image is not None:
429
449
  self.draw_base_layer(cumulative_image)
@@ -617,21 +637,24 @@ class Texture(Component):
617
637
  converters = {"Polygon": self._skip, "LineString": self._sequence, "Point": self._sequence}
618
638
  return converters.get(geom_type) # type: ignore
619
639
 
620
- def polygons(
640
+ def objects_generator(
621
641
  self,
622
642
  tags: dict[str, str | list[str] | bool],
623
643
  width: int | None,
624
644
  info_layer: str | None = None,
625
- ) -> Generator[np.ndarray, None, None]:
645
+ yield_linestrings: bool = False,
646
+ ) -> Generator[np.ndarray, None, None] | Generator[list[tuple[int, int]], None, None]:
626
647
  """Generator which yields numpy arrays of polygons from OSM data.
627
648
 
628
649
  Arguments:
629
650
  tags (dict[str, str | list[str]]): Dictionary of tags to search for.
630
651
  width (int | None): Width of the polygon in meters (only for LineString).
631
652
  info_layer (str | None): Name of the corresponding info layer.
653
+ yield_linestrings (bool): Flag to determine if the LineStrings should be yielded.
632
654
 
633
655
  Yields:
634
- Generator[np.ndarray, None, None]: Numpy array of polygon points.
656
+ Generator[np.ndarray, None, None] | Generator[list[tuple[int, int]], None, None]:
657
+ Numpy array of polygon points or list of point coordinates.
635
658
  """
636
659
  is_fieds = info_layer == "fields"
637
660
  try:
@@ -645,6 +668,42 @@ class Texture(Component):
645
668
  objects_utm = ox.projection.project_gdf(objects, to_latlong=False)
646
669
  self.logger.debug("Fetched %s elements for tags: %s.", len(objects_utm), tags)
647
670
 
671
+ method = self.linestrings_generator if yield_linestrings else self.polygons_generator
672
+
673
+ yield from method(objects_utm, width, is_fieds)
674
+
675
+ def linestrings_generator(
676
+ self, objects_utm: pd.core.frame.DataFrame, *args, **kwargs
677
+ ) -> Generator[list[tuple[int, int]], None, None]:
678
+ """Generator which yields lists of point coordinates which represent LineStrings from OSM.
679
+
680
+ Arguments:
681
+ objects_utm (pd.core.frame.DataFrame): Dataframe with OSM objects in UTM format.
682
+
683
+ Yields:
684
+ Generator[list[tuple[int, int]], None, None]: List of point coordinates.
685
+ """
686
+ for _, obj in objects_utm.iterrows():
687
+ geometry = obj["geometry"]
688
+ if isinstance(geometry, shapely.geometry.linestring.LineString):
689
+ points = [
690
+ (self.get_relative_x(x), self.get_relative_y(y)) for x, y in geometry.coords
691
+ ]
692
+ yield points
693
+
694
+ def polygons_generator(
695
+ self, objects_utm: pd.core.frame.DataFrame, width: int | None, is_fieds: bool
696
+ ) -> Generator[np.ndarray, None, None]:
697
+ """Generator which yields numpy arrays of polygons from OSM data.
698
+
699
+ Arguments:
700
+ objects_utm (pd.core.frame.DataFrame): Dataframe with OSM objects in UTM format.
701
+ width (int | None): Width of the polygon in meters (only for LineString).
702
+ is_fieds (bool): Flag to determine if the fields should be padded.
703
+
704
+ Yields:
705
+ Generator[np.ndarray, None, None]: Numpy array of polygon points.
706
+ """
648
707
  for _, obj in objects_utm.iterrows():
649
708
  polygon = self._to_polygon(obj, width)
650
709
  if polygon is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maps4fs
3
- Version: 1.3.7
3
+ Version: 1.3.8
4
4
  Summary: Generate map templates for Farming Simulator from real places.
5
5
  Author-email: iwatkot <iwatkot@gmail.com>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maps4fs"
7
- version = "1.3.7"
7
+ version = "1.3.8"
8
8
  description = "Generate map templates for Farming Simulator from real places."
9
9
  authors = [{name = "iwatkot", email = "iwatkot@gmail.com"}]
10
10
  license = {text = "MIT License"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes