maps4fs 1.6.7__py3-none-any.whl → 1.6.9__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.
maps4fs/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  # pylint: disable=missing-module-docstring
2
2
  from maps4fs.generator.dtm.dtm import DTMProvider
3
3
  from maps4fs.generator.dtm.srtm import SRTM30Provider
4
- from maps4fs.generator.dtm.usgs import USGS1mProvider
4
+ from maps4fs.generator.dtm.usgs import USGSProvider
5
5
  from maps4fs.generator.game import Game
6
6
  from maps4fs.generator.map import Map
7
7
  from maps4fs.generator.settings import (
@@ -4,6 +4,7 @@ and specific settings for downloading and processing the data."""
4
4
 
5
5
  from __future__ import annotations
6
6
 
7
+ from abc import ABC, abstractmethod
7
8
  import os
8
9
  from typing import TYPE_CHECKING, Type
9
10
 
@@ -23,19 +24,22 @@ class DTMProviderSettings(BaseModel):
23
24
  """Base class for DTM provider settings models."""
24
25
 
25
26
 
26
- class DTMProvider:
27
+ # pylint: disable=too-many-public-methods
28
+ class DTMProvider(ABC):
27
29
  """Base class for DTM providers."""
28
30
 
29
31
  _code: str | None = None
30
32
  _name: str | None = None
31
33
  _region: str | None = None
32
34
  _icon: str | None = None
33
- _resolution: float | None = None
35
+ _resolution: float | str | None = None
34
36
 
35
37
  _url: str | None = None
36
38
 
37
39
  _author: str | None = None
40
+ _contributors: str | None = None
38
41
  _is_community: bool = False
42
+ _is_base: bool = False
39
43
  _settings: Type[DTMProviderSettings] | None = None
40
44
 
41
45
  _instructions: str | None = None
@@ -120,6 +124,24 @@ class DTMProvider:
120
124
  """
121
125
  return cls._author
122
126
 
127
+ @classmethod
128
+ def contributors(cls) -> str | None:
129
+ """Contributors of the provider.
130
+
131
+ Returns:
132
+ str: Contributors of the provider.
133
+ """
134
+ return cls._contributors
135
+
136
+ @classmethod
137
+ def is_base(cls) -> bool:
138
+ """Is the provider a base provider.
139
+
140
+ Returns:
141
+ bool: True if the provider is a base provider, False otherwise.
142
+ """
143
+ return cls._is_base
144
+
123
145
  @classmethod
124
146
  def is_community(cls) -> bool:
125
147
  """Is the provider a community-driven project.
@@ -190,7 +212,8 @@ class DTMProvider:
190
212
  """
191
213
  providers = {}
192
214
  for provider in cls.__subclasses__():
193
- providers[provider._code] = provider.description() # pylint: disable=W0212
215
+ if not provider.is_base():
216
+ providers[provider._code] = provider.description() # pylint: disable=W0212
194
217
  return providers # type: ignore
195
218
 
196
219
  def download_tile(self, output_path: str, **kwargs) -> bool:
@@ -235,6 +258,7 @@ class DTMProvider:
235
258
  """
236
259
  raise NotImplementedError
237
260
 
261
+ @abstractmethod
238
262
  def get_numpy(self) -> np.ndarray:
239
263
  """Get numpy array of the tile.
240
264
  Resulting array must be 16 bit (signed or unsigned) integer and it should be already
@@ -1,37 +1,47 @@
1
- """This module contains provider of USGS 1m data."""
1
+ """This module contains provider of USGS data."""
2
2
 
3
3
  import os
4
4
  from datetime import datetime
5
+ from zipfile import ZipFile
5
6
 
6
7
  import numpy as np
7
- import rasterio # type: ignore
8
+ import rasterio
8
9
  import requests
9
- from rasterio._warp import Resampling # type: ignore # pylint: disable=E0611
10
- from rasterio.merge import merge # type: ignore
11
- from rasterio.warp import calculate_default_transform, reproject # type: ignore
12
- from rasterio.windows import from_bounds # type: ignore
10
+ from rasterio.enums import Resampling
11
+ from rasterio.merge import merge
12
+ from rasterio.warp import calculate_default_transform, reproject
13
+ from rasterio.windows import from_bounds
13
14
 
14
15
  from maps4fs.generator.dtm.dtm import DTMProvider, DTMProviderSettings
15
16
 
16
17
 
17
- class USGS1mProviderSettings(DTMProviderSettings):
18
- """Settings for the USGS 1m provider."""
18
+ class USGSProviderSettings(DTMProviderSettings):
19
+ """Settings for the USGS provider."""
19
20
 
20
21
  max_local_elevation: int = 255
22
+ dataset: tuple | str = (
23
+ 'Digital Elevation Model (DEM) 1 meter',
24
+ 'Alaska IFSAR 5 meter DEM',
25
+ 'National Elevation Dataset (NED) 1/9 arc-second',
26
+ 'National Elevation Dataset (NED) 1/3 arc-second',
27
+ 'National Elevation Dataset (NED) 1 arc-second',
28
+ 'National Elevation Dataset (NED) Alaska 2 arc-second',
29
+ 'Original Product Resolution (OPR) Digital Elevation Model (DEM)',
30
+ )
21
31
 
22
32
 
23
- # pylint: disable=W0223
24
- class USGS1mProvider(DTMProvider):
33
+ class USGSProvider(DTMProvider):
25
34
  """Provider of USGS."""
26
35
 
27
- _code = "USGS1m"
28
- _name = "USGS 1m"
36
+ _code = "USGS"
37
+ _name = "USGS"
29
38
  _region = "USA"
30
39
  _icon = "🇺🇸"
31
- _resolution = 1
40
+ _resolution = 'variable'
32
41
  _data: np.ndarray | None = None
33
- _settings = USGS1mProviderSettings
42
+ _settings = USGSProviderSettings
34
43
  _author = "[ZenJakey](https://github.com/ZenJakey)"
44
+ _contributors = "[kbrandwijk](https://github.com/kbrandwijk)"
35
45
  _is_community = True
36
46
  _instructions = (
37
47
  "ℹ️ Set the max local elevation to approx the local max elevation for your area in"
@@ -40,8 +50,8 @@ class USGS1mProvider(DTMProvider):
40
50
  )
41
51
 
42
52
  _url = (
43
- "https://tnmaccess.nationalmap.gov/api/v1/products?prodFormats=GeoTIFF,IMG&prodExtents="
44
- "10000 x 10000 meter&datasets=Digital Elevation Model (DEM) 1 meter&polygon="
53
+ "https://tnmaccess.nationalmap.gov/api/v1/products?prodFormats=GeoTIFF,IMG"
54
+
45
55
  )
46
56
 
47
57
  def __init__(self, *args, **kwargs):
@@ -64,7 +74,8 @@ class USGS1mProvider(DTMProvider):
64
74
  (north, south, east, west) = self.get_bbox()
65
75
  response = requests.get( # pylint: disable=W3101
66
76
  self.url # type: ignore
67
- + f"{west} {south},{east} {south},{east} {north},{west} {north},{west} {south}&="
77
+ + f"&datasets={self.user_settings.dataset}" # type: ignore
78
+ + f"&bbox={west},{north},{east},{south}"
68
79
  )
69
80
  self.logger.debug("Getting file locations from USGS...")
70
81
 
@@ -75,7 +86,7 @@ class USGS1mProvider(DTMProvider):
75
86
  items = json_data["items"]
76
87
  for item in items:
77
88
  urls.append(item["downloadURL"])
78
- self.download_tif_files(urls)
89
+ # self.download_tif_files(urls)
79
90
  else:
80
91
  self.logger.error("Failed to get data. HTTP Status Code: %s", response.status_code)
81
92
  except requests.exceptions.RequestException as e:
@@ -108,12 +119,24 @@ class USGS1mProvider(DTMProvider):
108
119
  for chunk in response.iter_content(chunk_size=8192): # Download in chunks
109
120
  file.write(chunk)
110
121
  self.logger.info("File downloaded successfully: %s", file_path)
122
+ if file_name.endswith('.zip'):
123
+ with ZipFile(file_path, "r") as f_in:
124
+ f_in.extract(file_name.replace('.zip', '.img'), self.shared_tiff_path)
125
+ tif_files.append(file_path.replace('.zip', '.img'))
126
+ else:
127
+ tif_files.append(file_path)
111
128
  except requests.exceptions.RequestException as e:
112
129
  self.logger.error("Failed to download file: %s", e)
113
130
  else:
114
131
  self.logger.debug("File already exists: %s", file_name)
132
+ if file_name.endswith('.zip'):
133
+ if not os.path.exists(file_path.replace('.zip', '.img')):
134
+ with ZipFile(file_path, "r") as f_in:
135
+ f_in.extract(file_name.replace('.zip', '.img'), self.shared_tiff_path)
136
+ tif_files.append(file_path.replace('.zip', '.img'))
137
+ else:
138
+ tif_files.append(file_path)
115
139
 
116
- tif_files.append(file_path)
117
140
  return tif_files
118
141
 
119
142
  def merge_geotiff(self, input_files: list[str], output_file: str) -> None:
maps4fs/generator/map.py CHANGED
@@ -146,6 +146,7 @@ class Map:
146
146
 
147
147
  self.tree_custom_schema = kwargs.get("tree_custom_schema", None)
148
148
  if self.tree_custom_schema:
149
+ self.logger.info("Custom tree schema contains %s trees", len(self.tree_custom_schema))
149
150
  save_path = os.path.join(self.map_directory, "tree_custom_schema.json")
150
151
  with open(save_path, "w", encoding="utf-8") as file:
151
152
  json.dump(self.tree_custom_schema, file, indent=4)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maps4fs
3
- Version: 1.6.7
3
+ Version: 1.6.9
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
@@ -255,6 +255,10 @@ The tool now has a Modder Toolbox, which is a set of tools to help you with vari
255
255
 
256
256
  ### Tool Categories
257
257
  Tools are divided into categories, which are listed below.
258
+
259
+ #### For custom schemas
260
+ - **Tree Schema Editor** - allows you to view all the supported trees models and select the ones you need on your map. After it, 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 selected trees.
261
+
258
262
  #### For Textures and DEM
259
263
  - **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.
260
264
 
@@ -594,3 +598,4 @@ But also, I want to thank the people who helped me with the project in some way,
594
598
  - [Lucandia](https://github.com/Lucandia) - for the awesome StreamLit [widget to preview STL files](https://github.com/Lucandia/streamlit_stl).
595
599
  - [H4rdB4se](https://github.com/H4rdB4se) - for investigating the issue with custom OSM files and finding a proper way to work with the files in JOSM.
596
600
  - [kbrandwijk](https://github.com/kbrandwijk) - for providing [awesome tool](https://github.com/Paint-a-Farm/satmap_downloader) to download the satellite images from the Google Maps and giving a permission to modify it and create a Python Package.
601
+ - [Maaslandmods](https://github.com/Maaslandmods) - for the awesome idea to edit the tree schema in UI, images and code snippets on how to do it.
@@ -1,4 +1,4 @@
1
- maps4fs/__init__.py,sha256=WbT36EzJ_74GN0RUUrLIYECdSdtRiZaxKl17KUt7pjA,492
1
+ maps4fs/__init__.py,sha256=LrWSsyWaU28Dzcs7sRycywO_LvM-j34UvtafyBhvdx4,490
2
2
  maps4fs/logger.py,sha256=B-NEYpMjPAAqlV4VpfTi6nbBFnEABVtQOaYe6nMpidg,1489
3
3
  maps4fs/generator/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
4
4
  maps4fs/generator/background.py,sha256=tV4UXvtkNN-OSvv6ujp4jFWRU1xGBgEvSakVGZ1H4nc,24877
@@ -8,20 +8,20 @@ maps4fs/generator/dem.py,sha256=20gx0dzX0LyO6ipvDitst-BwGfcKogFqgQf9Q2qMH5U,1093
8
8
  maps4fs/generator/game.py,sha256=Nf5r2ubV4YVAVHGzJyhbF2GnOC0qV3HlHYIZBCWciHs,7992
9
9
  maps4fs/generator/grle.py,sha256=hcbVBJ4j_Zr2QvEVo2cYNh2jARVXp_X3onifBtp9Zxs,20922
10
10
  maps4fs/generator/i3d.py,sha256=pUyHKWKcw43xVCf3Y8iabtbQba05LYxMHi8vziGksIA,24843
11
- maps4fs/generator/map.py,sha256=P8wHrCLhLcv2W5zJmMGjpM1TAMR8c7yVFzm_n-5ZTHQ,10084
11
+ maps4fs/generator/map.py,sha256=a50KQEr1XZKjS_WKXywGwh4OC3gyjY6M8FTc0eNcxpg,10183
12
12
  maps4fs/generator/qgis.py,sha256=Es8hLuqN_KH8lDfnJE6He2rWYbAKJ3RGPn-o87S6CPI,6116
13
13
  maps4fs/generator/satellite.py,sha256=_7RcuNmR1mjxEJWMDsjnzKUIqWxnGUn50XtjB7HmSPg,3661
14
14
  maps4fs/generator/settings.py,sha256=3ASf3hW1nkGt8_3IOvKIKNUd6XAHYTAA8FquuhpSUlU,5668
15
15
  maps4fs/generator/texture.py,sha256=gIXCHU1vT3evbkaXAV9gLUrgI1wH3xJLgWAtZgFruj0,34013
16
16
  maps4fs/generator/dtm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- maps4fs/generator/dtm/dtm.py,sha256=azy-RWsc5PgenKDtgG0lrddMwWEw1hYzdng9V8zphMk,9167
17
+ maps4fs/generator/dtm/dtm.py,sha256=nCQKQygARLxaz4HkREQQd0Yb03oKOf1Iav5_VoZsFWI,9819
18
18
  maps4fs/generator/dtm/srtm.py,sha256=2-pX6bWrJX6gr8IM7ueX6mm_PW7_UQ58MtdzDHae2OQ,9030
19
- maps4fs/generator/dtm/usgs.py,sha256=ZTi10RNDA3EBrsVg2ZoYrdN4uqiG1Jvk7FzdcKdgNkU,13408
19
+ maps4fs/generator/dtm/usgs.py,sha256=hwVjoSNTNRU6hwnfwJ2d3rOdtOjadCmx2QESA2REn6s,14493
20
20
  maps4fs/toolbox/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
21
21
  maps4fs/toolbox/background.py,sha256=9BXWNqs_n3HgqDiPztWylgYk_QM4YgBpe6_ZNQAWtSc,2154
22
22
  maps4fs/toolbox/dem.py,sha256=z9IPFNmYbjiigb3t02ZenI3Mo8odd19c5MZbjDEovTo,3525
23
- maps4fs-1.6.7.dist-info/LICENSE.md,sha256=pTKD_oUexcn-yccFCTrMeLkZy0ifLRa-VNcDLqLZaIw,10749
24
- maps4fs-1.6.7.dist-info/METADATA,sha256=uNK0tEiWExntm4F61lyfM4q4qY-qw4naYg7iFE6Kb5M,38680
25
- maps4fs-1.6.7.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
26
- maps4fs-1.6.7.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
27
- maps4fs-1.6.7.dist-info/RECORD,,
23
+ maps4fs-1.6.9.dist-info/LICENSE.md,sha256=pTKD_oUexcn-yccFCTrMeLkZy0ifLRa-VNcDLqLZaIw,10749
24
+ maps4fs-1.6.9.dist-info/METADATA,sha256=S88e8c-JM845kgEPu9QGWuFhNXYkU6yCqsSqq980np8,39160
25
+ maps4fs-1.6.9.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
26
+ maps4fs-1.6.9.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
27
+ maps4fs-1.6.9.dist-info/RECORD,,