maps4fs 1.7.3__py3-none-any.whl → 1.7.4__py3-none-any.whl

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.
@@ -0,0 +1,67 @@
1
+ """This module contains functions to work with custom OSM files."""
2
+
3
+ import json
4
+ from xml.etree import ElementTree as ET
5
+
6
+ import osmnx as ox
7
+ from osmnx._errors import InsufficientResponseError
8
+
9
+ from maps4fs.generator.game import FS25
10
+
11
+
12
+ def check_osm_file(file_path: str) -> bool:
13
+ """Tries to read the OSM file using OSMnx and returns True if the file is valid,
14
+ False otherwise.
15
+
16
+ Arguments:
17
+ file_path (str): Path to the OSM file.
18
+
19
+ Returns:
20
+ bool: True if the file is valid, False otherwise.
21
+ """
22
+ with open(FS25().texture_schema, encoding="utf-8") as f:
23
+ schema = json.load(f)
24
+
25
+ tags = []
26
+ for element in schema:
27
+ element_tags = element.get("tags")
28
+ if element_tags:
29
+ tags.append(element_tags)
30
+
31
+ for tag in tags:
32
+ try:
33
+ ox.features_from_xml(file_path, tags=tag)
34
+ except InsufficientResponseError:
35
+ continue
36
+ except Exception: # pylint: disable=W0718
37
+ return False
38
+ return True
39
+
40
+
41
+ def fix_osm_file(input_file_path: str, output_file_path: str) -> tuple[bool, int]:
42
+ """Fixes the OSM file by removing all the <relation> nodes and all the nodes with
43
+ action='delete'.
44
+
45
+ Arguments:
46
+ input_file_path (str): Path to the input OSM file.
47
+ output_file_path (str): Path to the output OSM file.
48
+
49
+ Returns:
50
+ tuple[bool, int]: A tuple containing the result of the check_osm_file function
51
+ and the number of fixed errors.
52
+ """
53
+ broken_entries = ["relation", ".//*[@action='delete']"]
54
+
55
+ tree = ET.parse(input_file_path)
56
+ root = tree.getroot()
57
+
58
+ fixed_errors = 0
59
+ for entry in broken_entries:
60
+ for element in root.findall(entry):
61
+ root.remove(element)
62
+ fixed_errors += 1
63
+
64
+ tree.write(output_file_path)
65
+ result = check_osm_file(output_file_path)
66
+
67
+ return result, fixed_errors
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: maps4fs
3
- Version: 1.7.3
3
+ Version: 1.7.4
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
@@ -292,6 +292,9 @@ Tools are divided into categories, which are listed below.
292
292
  - **Texture Schema Editor** - allows you to view all the supported textures and edit their parameters, such as priority, OSM tags and so on. After editing, you should click the Show updated schema button and copy the JSON schema to the clipboard. Then you can use it in the Expert settings to generate the map with the updated textures.
293
293
 
294
294
  #### For Textures and DEM
295
+
296
+ - **Fix custom OSM file** - this tool fixes the most common errors in the custom OSM file, but it can not guarantee that the file will be fixed completely if some non-common errors are present.
297
+
295
298
  - **GeoTIFF windowing** - allows you to upload your GeoTIFF file and select the region of interest to extract it from the image. It's useful when you have high-resolution DEM data and want to create a height map using it.
296
299
 
297
300
  #### For Background terrain
@@ -20,9 +20,10 @@ maps4fs/generator/dtm/srtm.py,sha256=RsvVa7ErajPwXoetG7mO_rldji9GR97HFaazH-PkdHw
20
20
  maps4fs/generator/dtm/usgs.py,sha256=fWFR_kO_uLVjAJAL43YFvBaHwsXWI-00jMlp23Ue7Wo,5450
21
21
  maps4fs/toolbox/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
22
22
  maps4fs/toolbox/background.py,sha256=9BXWNqs_n3HgqDiPztWylgYk_QM4YgBpe6_ZNQAWtSc,2154
23
+ maps4fs/toolbox/custom_osm.py,sha256=X6ZlPqiOhNjkmdD_qVroIfdOl9Rb90cDwVSLDVYgx80,1892
23
24
  maps4fs/toolbox/dem.py,sha256=z9IPFNmYbjiigb3t02ZenI3Mo8odd19c5MZbjDEovTo,3525
24
- maps4fs-1.7.3.dist-info/LICENSE.md,sha256=pTKD_oUexcn-yccFCTrMeLkZy0ifLRa-VNcDLqLZaIw,10749
25
- maps4fs-1.7.3.dist-info/METADATA,sha256=3oaI3MI_V8Vf-qZi3r3bS1Qn-Y806sDHE7g1JqV9YDI,40240
26
- maps4fs-1.7.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
27
- maps4fs-1.7.3.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
28
- maps4fs-1.7.3.dist-info/RECORD,,
25
+ maps4fs-1.7.4.dist-info/LICENSE.md,sha256=pTKD_oUexcn-yccFCTrMeLkZy0ifLRa-VNcDLqLZaIw,10749
26
+ maps4fs-1.7.4.dist-info/METADATA,sha256=RqMBGBQBs4zhyn8fnpnNwXl6Fm_zhPBaNuxo1-TVQUg,40436
27
+ maps4fs-1.7.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
28
+ maps4fs-1.7.4.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
29
+ maps4fs-1.7.4.dist-info/RECORD,,