maps4fs 0.7.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.
- maps4fs-0.7.8/LICENSE.md +21 -0
- maps4fs-0.7.8/PKG-INFO +218 -0
- maps4fs-0.7.8/README.md +198 -0
- maps4fs-0.7.8/maps4fs/__init__.py +4 -0
- maps4fs-0.7.8/maps4fs/generator/__init__.py +1 -0
- maps4fs-0.7.8/maps4fs/generator/component.py +101 -0
- maps4fs-0.7.8/maps4fs/generator/config.py +55 -0
- maps4fs-0.7.8/maps4fs/generator/dem.py +291 -0
- maps4fs-0.7.8/maps4fs/generator/game.py +191 -0
- maps4fs-0.7.8/maps4fs/generator/map.py +115 -0
- maps4fs-0.7.8/maps4fs/generator/texture.py +434 -0
- maps4fs-0.7.8/maps4fs/logger.py +46 -0
- maps4fs-0.7.8/maps4fs.egg-info/PKG-INFO +218 -0
- maps4fs-0.7.8/maps4fs.egg-info/SOURCES.txt +18 -0
- maps4fs-0.7.8/maps4fs.egg-info/dependency_links.txt +1 -0
- maps4fs-0.7.8/maps4fs.egg-info/requires.txt +4 -0
- maps4fs-0.7.8/maps4fs.egg-info/top_level.txt +1 -0
- maps4fs-0.7.8/pyproject.toml +33 -0
- maps4fs-0.7.8/setup.cfg +4 -0
- maps4fs-0.7.8/tests/test_generator.py +167 -0
maps4fs-0.7.8/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright © [2024] [iwatkot]
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
maps4fs-0.7.8/PKG-INFO
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: maps4fs
|
3
|
+
Version: 0.7.8
|
4
|
+
Summary: Generate map templates for Farming Simulator from real places.
|
5
|
+
Author-email: iwatkot <iwatkot@gmail.com>
|
6
|
+
License: MIT License
|
7
|
+
Project-URL: Homepage, https://github.com/iwatkot/maps4fs
|
8
|
+
Project-URL: Repository, https://github.com/iwatkot/maps4fs
|
9
|
+
Keywords: farmingsimulator,fs,farmingsimulator22,farmingsimulator25,fs22,fs25
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
13
|
+
Classifier: Operating System :: OS Independent
|
14
|
+
Description-Content-Type: text/markdown
|
15
|
+
License-File: LICENSE.md
|
16
|
+
Requires-Dist: opencv-python
|
17
|
+
Requires-Dist: osmnx<2.0.0
|
18
|
+
Requires-Dist: rasterio
|
19
|
+
Requires-Dist: tqdm
|
20
|
+
|
21
|
+
<div align="center" markdown>
|
22
|
+
<img src="https://github.com/iwatkot/maps4fs/assets/118521851/ffd7f0a3-e317-4c3f-911f-2c2fb736fbfa">
|
23
|
+
|
24
|
+
<p align="center">
|
25
|
+
<a href="#Quick-Start">Quick Start</a> •
|
26
|
+
<a href="#Overview">Overview</a> •
|
27
|
+
<a href="#How-To-Run">How-To-Run</a> •
|
28
|
+
<a href="#Supported-objects">Supported objects</a> •
|
29
|
+
<a href="#For-advanced-users">For advanced users</a> •
|
30
|
+
<a href="#Bugs-and-feature-requests">Bugs and feature requests</a>
|
31
|
+
</p>
|
32
|
+
|
33
|
+
|
34
|
+
[](https://github.com/iwatkot/maps4fs/releases)
|
35
|
+
[](https://pypi.org/project/maps4fs)
|
36
|
+
[](https://hub.docker.com/repository/docker/iwatkot/maps4fs/general)
|
37
|
+
[](https://github.com/iwatkot/maps4fs/issues)
|
38
|
+
[](https://codeclimate.com/github/iwatkot/maps4fs/maintainability)<br>
|
39
|
+
[](https://mypy-lang.org/)
|
40
|
+
[](https://github.com/iwatkot/maps4fs/actions)
|
41
|
+
[](https://codeclimate.com/github/iwatkot/maps4fs/test_coverage)
|
42
|
+
[](https://github.com/iwatkot/maps4fs/stargazers)
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
🗺️ Supports 2x2, 4x4, 8x8, 16x16 and any custom size maps<br>
|
47
|
+
🌍 Based on real-world data from OpenStreetMap<br>
|
48
|
+
🏞️ Generates height using SRTM dataset<br>
|
49
|
+
📦 Provides a ready-to-use map template for the Giants Editor<br>
|
50
|
+
🚜 Supports Farming Simulator 22 and 25<br>
|
51
|
+
|
52
|
+
## Quick Start
|
53
|
+
There are several ways to use the tool. You obviously need the **first one**, but you can choose any of the others depending on your needs.<br>
|
54
|
+
### 🚜 For most users
|
55
|
+
**Option 1:** open the [maps4fs](https://maps4fs.streamlit.app) on StreamLit and generate a map template in a few clicks.<br>
|
56
|
+
|
57
|
+
### 😎 For advanced users
|
58
|
+
**Option 2:** run the Docker version in your browser. Launch the following command in your terminal:
|
59
|
+
```bash
|
60
|
+
docker run -d -p 8501:8501 iwatkot/maps4fs
|
61
|
+
```
|
62
|
+
And open [http://localhost:8501](http://localhost:8501) in your browser.<br>
|
63
|
+
If you don't know how to use Docker, navigate to the [Docker version](#option-2-docker-version), it's really simple.<br>
|
64
|
+
|
65
|
+
### 🤯 For developers
|
66
|
+
**Option 3:** Python package. Install the package using the following command:
|
67
|
+
```bash
|
68
|
+
pip install maps4fs
|
69
|
+
```
|
70
|
+
And refer to the [Python package](#option-3-python-package) section to learn how to use it.<br>
|
71
|
+
|
72
|
+
## Overview
|
73
|
+
The core idea is coming from the awesome [maps4cim](https://github.com/klamann/maps4cim) project.<br>
|
74
|
+
|
75
|
+
The main goal of this project is to generate map templates, based on real-world data, for the Farming Simulator. It's important to mention that **templates are not maps**. They are just a starting point for creating a map. This tool just uses built-in textures to highlight different types of terrain and buildings with correct shapes and scales and to generate a height map. The rest of the work is up to you. So if you thought that you could just run this tool and get a playable map, then I'm sorry to disappoint you. But if you are a map maker, then this tool will save you a lot of time.<br>
|
76
|
+
So, if you're new to map making, here's a quick overview of the process:
|
77
|
+
1. Generate a map template using this tool.
|
78
|
+
2. Download the Giants Editor.
|
79
|
+
3. Open the map template in the Giants Editor.
|
80
|
+
4. Now you can start creating your map (adding roads, fields, buildings, etc.).
|
81
|
+
|
82
|
+
### Previews
|
83
|
+
|
84
|
+
The generator also creates a multiple previews of the map. Here's the list of them:
|
85
|
+
1. General preview - merging all the layers into one image with different colors.
|
86
|
+
2. Grayscale DEM preview - a grayscale image of the height map (as it is).
|
87
|
+
3. Colored DEM preview - a colored image of the height map (from blue to red). The blue color represents the lowest point, and the red color represents the highest point.
|
88
|
+
|
89
|
+
<br>
|
90
|
+
*Preview of a 16 km map with a 500-meter mountain in the middle of it.*<br>
|
91
|
+
|
92
|
+
Parameters:
|
93
|
+
- coordinates: 45.15, 19.71
|
94
|
+
- size: 16 x 16 km
|
95
|
+
|
96
|
+
## How-To-Run
|
97
|
+
|
98
|
+
You'll find detailed instructions on how to run the project below. But if you prefer video tutorials, here's one for you:
|
99
|
+
<a href="https://www.youtube.com/watch?v=ujwWKHVKsw8" target="_blank"><img src="https://github.com/user-attachments/assets/6dbbbc71-d04f-40b2-9fba-81e5e4857407"/></a>
|
100
|
+
<i>Video tutorial: How to generate a Farming Simulator 22 map from real-world data.</i>
|
101
|
+
|
102
|
+
### Option 1: StreamLit
|
103
|
+
🟢 Recommended for all users, you don't need to install anything.<br>
|
104
|
+
Using the [StreamLit](https://maps4fs.streamlit.app) version of the tool is the easiest way to generate a map template. Just open the link and follow the instructions.
|
105
|
+
Note: due to CPU and RAM limitations of the hosting, the generation may take some time. If you need faster processing, use the [Docker version](#option-2-docker-version).<br>
|
106
|
+
|
107
|
+
Using it is easy and doesn't require any guides. Enjoy!
|
108
|
+
|
109
|
+
### Option 2: Docker version
|
110
|
+
🟠 Recommended for users who want faster processing, very simple installation.<br>
|
111
|
+
You can launch the project with minimalistic UI in your browser using Docker. Follow these steps:
|
112
|
+
|
113
|
+
1. Install [Docker](https://docs.docker.com/get-docker/) for your OS.
|
114
|
+
2. Run the following command in your terminal:
|
115
|
+
```bash
|
116
|
+
docker run -d -p 8501:8501 iwatkot/maps4fs
|
117
|
+
```
|
118
|
+
3. Open your browser and go to [http://localhost:8501](http://localhost:8501).
|
119
|
+
4. Fill in the required fields and click on the `Generate` button.
|
120
|
+
5. When the map is generated click on the `Download` button to get the map.
|
121
|
+
|
122
|
+

|
123
|
+
|
124
|
+
### Option 3: Python package
|
125
|
+
🔴 Recommended for developers.<br>
|
126
|
+
You can use the Python package to generate maps. Follow these steps:
|
127
|
+
|
128
|
+
1. Install the package from PyPI:
|
129
|
+
```bash
|
130
|
+
pip install maps4fs
|
131
|
+
```
|
132
|
+
2. Import the Game class and create an instance of it:
|
133
|
+
```python
|
134
|
+
import maps4fs as mfs
|
135
|
+
|
136
|
+
game = mfs.Game.from_code("FS25")
|
137
|
+
```
|
138
|
+
In this case the library will use the default templates, which should be present in the `data` directory, which should be placed in the current working directory.<br>
|
139
|
+
Structure example:<br>
|
140
|
+
|
141
|
+
```text
|
142
|
+
📁 data
|
143
|
+
┣ 📄 fs22-map-template.zip
|
144
|
+
┗ 📄 fs22-texture-schema.json
|
145
|
+
```
|
146
|
+
|
147
|
+
So it's recommended to download the `data` directory from the repository and place it in the root of your project.<br>
|
148
|
+
|
149
|
+
3. Create an instance of the Map class:
|
150
|
+
```python
|
151
|
+
import maps4fs as mfs
|
152
|
+
|
153
|
+
map = mfs.Map(
|
154
|
+
game,
|
155
|
+
(52.5200, 13.4050), # Latitude and longitude of the map center.
|
156
|
+
height=1024, # The height of the map in meters.
|
157
|
+
width=1024, # The width of the map in meters.
|
158
|
+
map_directory="path/to/your/map/directory", # The directory where the map will be saved.
|
159
|
+
)
|
160
|
+
```
|
161
|
+
|
162
|
+
4. Generate the map:
|
163
|
+
```python
|
164
|
+
map.generate()
|
165
|
+
```
|
166
|
+
|
167
|
+
The map will be saved in the `map_directory` directory.
|
168
|
+
|
169
|
+
## Supported objects
|
170
|
+
The project is based on the [OpenStreetMap](https://www.openstreetmap.org/) data. So, refer to [this page](https://wiki.openstreetmap.org/wiki/Map_Features) to understand the list below.
|
171
|
+
- "building": True
|
172
|
+
- "highway": ["motorway", "trunk", "primary"]
|
173
|
+
- "highway": ["secondary", "tertiary", "road", "service"]
|
174
|
+
- "highway": ["unclassified", "residential", "track"]
|
175
|
+
- "natural": ["grassland", "scrub"]
|
176
|
+
- "landuse": "farmland"
|
177
|
+
- "natural": ["water"]
|
178
|
+
- "waterway": True
|
179
|
+
- "natural": ["wood", "tree_row"]
|
180
|
+
- "railway": True
|
181
|
+
|
182
|
+
The list will be updated as the project develops.
|
183
|
+
|
184
|
+
## Info sequence
|
185
|
+
The script will also generate the `generation_info.json` file in the `output` folder. It contains the following keys: <br>
|
186
|
+
`"coordinates"` - the coordinates of the map center which you entered,<br>
|
187
|
+
`"bbox"` - the bounding box of the map in lat and lon,<br>
|
188
|
+
`"map_height"` - the height of the map in meters (this one is from the user input, e.g. 2048 and so on),<br>
|
189
|
+
`"map_width"` - the width of the map in meters (same as above),<br>
|
190
|
+
`"minimum_x"` - the minimum x coordinate of the map (UTM projection),<br>
|
191
|
+
`"minimum_y"` - the minimum y coordinate of the map (UTM projection),<br>
|
192
|
+
`"maximum_x"` - the maximum x coordinate of the map (UTM projection),<br>
|
193
|
+
`"maximum_y"` - the maximum y coordinate of the map (UTM projection),<br>
|
194
|
+
`"height"` - the height of the map in meters (it won't be equal to the parameters above since the Earth is not flat, sorry flat-earthers),<br>
|
195
|
+
`"width"` - the width of the map in meters (same as above),<br>
|
196
|
+
`"height_coef"` - since we need a texture of exact size, the height of the map is multiplied by this coefficient,<br>
|
197
|
+
`"width_coef"` - same as above but for the width,<br>
|
198
|
+
`"tile_name"` - the name of the SRTM tile which was used to generate the height map, e.g. "N52E013"<br>
|
199
|
+
|
200
|
+
You can use this information to adjust some other sources of data to the map, e.g. textures, height maps, etc.
|
201
|
+
|
202
|
+
## For advanced users
|
203
|
+
The tool supports the custom size of the map. To use this feature select `Custom` in the `Map size` dropdown and enter the desired size. The tool will generate a map with the size you entered.<br>
|
204
|
+
|
205
|
+
⛔️ Do not use this feature, if you don't know what you're doing. In most cases the Giants Editor will just crash on opening the file, because you need to enter a specific values for the map size.<br><br>
|
206
|
+
|
207
|
+

|
208
|
+
|
209
|
+
You can also apply some advanced settings to the map generation process. Note that they're ADVANCED, so you don't need to use them if you're not sure what they do.<br>
|
210
|
+
|
211
|
+
Here's the list of the advanced settings:
|
212
|
+
|
213
|
+
- DEM multiplier: the height of the map is multiplied by this value. So the DEM map is just a 16-bit grayscale image, which means that the maximum avaiable value there is 65535, while the actual difference between the deepest and the highest point on Earth is about 20 km. So, by default this value is set to 3. Just note that this setting mostly does not matter, because you can always adjust it in the Giants Editor, learn more about the [heightScale](https://www.farming-simulator.org/19/terrain-heightscale.php) parameter on the [PMC Farming Simulator](https://www.farming-simulator.org/) website.
|
214
|
+
|
215
|
+
- DEM Blur radius: the radius of the Gaussian blur filter applied to the DEM map. By default, it's set to 21. This filter just makes the DEM map smoother, so the height transitions will be more natural. You can set it to 1 to disable the filter, but it will result as a Minecraft-like map.
|
216
|
+
|
217
|
+
## Bugs and feature requests
|
218
|
+
If you find a bug or have an idea for a new feature, please create an issue [here](https://github.com/iwatkot/maps4fs/issues) or contact me directly on [Telegram](https://t.me/iwatkot).<br>
|
maps4fs-0.7.8/README.md
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
<div align="center" markdown>
|
2
|
+
<img src="https://github.com/iwatkot/maps4fs/assets/118521851/ffd7f0a3-e317-4c3f-911f-2c2fb736fbfa">
|
3
|
+
|
4
|
+
<p align="center">
|
5
|
+
<a href="#Quick-Start">Quick Start</a> •
|
6
|
+
<a href="#Overview">Overview</a> •
|
7
|
+
<a href="#How-To-Run">How-To-Run</a> •
|
8
|
+
<a href="#Supported-objects">Supported objects</a> •
|
9
|
+
<a href="#For-advanced-users">For advanced users</a> •
|
10
|
+
<a href="#Bugs-and-feature-requests">Bugs and feature requests</a>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
|
14
|
+
[](https://github.com/iwatkot/maps4fs/releases)
|
15
|
+
[](https://pypi.org/project/maps4fs)
|
16
|
+
[](https://hub.docker.com/repository/docker/iwatkot/maps4fs/general)
|
17
|
+
[](https://github.com/iwatkot/maps4fs/issues)
|
18
|
+
[](https://codeclimate.com/github/iwatkot/maps4fs/maintainability)<br>
|
19
|
+
[](https://mypy-lang.org/)
|
20
|
+
[](https://github.com/iwatkot/maps4fs/actions)
|
21
|
+
[](https://codeclimate.com/github/iwatkot/maps4fs/test_coverage)
|
22
|
+
[](https://github.com/iwatkot/maps4fs/stargazers)
|
23
|
+
|
24
|
+
</div>
|
25
|
+
|
26
|
+
🗺️ Supports 2x2, 4x4, 8x8, 16x16 and any custom size maps<br>
|
27
|
+
🌍 Based on real-world data from OpenStreetMap<br>
|
28
|
+
🏞️ Generates height using SRTM dataset<br>
|
29
|
+
📦 Provides a ready-to-use map template for the Giants Editor<br>
|
30
|
+
🚜 Supports Farming Simulator 22 and 25<br>
|
31
|
+
|
32
|
+
## Quick Start
|
33
|
+
There are several ways to use the tool. You obviously need the **first one**, but you can choose any of the others depending on your needs.<br>
|
34
|
+
### 🚜 For most users
|
35
|
+
**Option 1:** open the [maps4fs](https://maps4fs.streamlit.app) on StreamLit and generate a map template in a few clicks.<br>
|
36
|
+
|
37
|
+
### 😎 For advanced users
|
38
|
+
**Option 2:** run the Docker version in your browser. Launch the following command in your terminal:
|
39
|
+
```bash
|
40
|
+
docker run -d -p 8501:8501 iwatkot/maps4fs
|
41
|
+
```
|
42
|
+
And open [http://localhost:8501](http://localhost:8501) in your browser.<br>
|
43
|
+
If you don't know how to use Docker, navigate to the [Docker version](#option-2-docker-version), it's really simple.<br>
|
44
|
+
|
45
|
+
### 🤯 For developers
|
46
|
+
**Option 3:** Python package. Install the package using the following command:
|
47
|
+
```bash
|
48
|
+
pip install maps4fs
|
49
|
+
```
|
50
|
+
And refer to the [Python package](#option-3-python-package) section to learn how to use it.<br>
|
51
|
+
|
52
|
+
## Overview
|
53
|
+
The core idea is coming from the awesome [maps4cim](https://github.com/klamann/maps4cim) project.<br>
|
54
|
+
|
55
|
+
The main goal of this project is to generate map templates, based on real-world data, for the Farming Simulator. It's important to mention that **templates are not maps**. They are just a starting point for creating a map. This tool just uses built-in textures to highlight different types of terrain and buildings with correct shapes and scales and to generate a height map. The rest of the work is up to you. So if you thought that you could just run this tool and get a playable map, then I'm sorry to disappoint you. But if you are a map maker, then this tool will save you a lot of time.<br>
|
56
|
+
So, if you're new to map making, here's a quick overview of the process:
|
57
|
+
1. Generate a map template using this tool.
|
58
|
+
2. Download the Giants Editor.
|
59
|
+
3. Open the map template in the Giants Editor.
|
60
|
+
4. Now you can start creating your map (adding roads, fields, buildings, etc.).
|
61
|
+
|
62
|
+
### Previews
|
63
|
+
|
64
|
+
The generator also creates a multiple previews of the map. Here's the list of them:
|
65
|
+
1. General preview - merging all the layers into one image with different colors.
|
66
|
+
2. Grayscale DEM preview - a grayscale image of the height map (as it is).
|
67
|
+
3. Colored DEM preview - a colored image of the height map (from blue to red). The blue color represents the lowest point, and the red color represents the highest point.
|
68
|
+
|
69
|
+
<br>
|
70
|
+
*Preview of a 16 km map with a 500-meter mountain in the middle of it.*<br>
|
71
|
+
|
72
|
+
Parameters:
|
73
|
+
- coordinates: 45.15, 19.71
|
74
|
+
- size: 16 x 16 km
|
75
|
+
|
76
|
+
## How-To-Run
|
77
|
+
|
78
|
+
You'll find detailed instructions on how to run the project below. But if you prefer video tutorials, here's one for you:
|
79
|
+
<a href="https://www.youtube.com/watch?v=ujwWKHVKsw8" target="_blank"><img src="https://github.com/user-attachments/assets/6dbbbc71-d04f-40b2-9fba-81e5e4857407"/></a>
|
80
|
+
<i>Video tutorial: How to generate a Farming Simulator 22 map from real-world data.</i>
|
81
|
+
|
82
|
+
### Option 1: StreamLit
|
83
|
+
🟢 Recommended for all users, you don't need to install anything.<br>
|
84
|
+
Using the [StreamLit](https://maps4fs.streamlit.app) version of the tool is the easiest way to generate a map template. Just open the link and follow the instructions.
|
85
|
+
Note: due to CPU and RAM limitations of the hosting, the generation may take some time. If you need faster processing, use the [Docker version](#option-2-docker-version).<br>
|
86
|
+
|
87
|
+
Using it is easy and doesn't require any guides. Enjoy!
|
88
|
+
|
89
|
+
### Option 2: Docker version
|
90
|
+
🟠 Recommended for users who want faster processing, very simple installation.<br>
|
91
|
+
You can launch the project with minimalistic UI in your browser using Docker. Follow these steps:
|
92
|
+
|
93
|
+
1. Install [Docker](https://docs.docker.com/get-docker/) for your OS.
|
94
|
+
2. Run the following command in your terminal:
|
95
|
+
```bash
|
96
|
+
docker run -d -p 8501:8501 iwatkot/maps4fs
|
97
|
+
```
|
98
|
+
3. Open your browser and go to [http://localhost:8501](http://localhost:8501).
|
99
|
+
4. Fill in the required fields and click on the `Generate` button.
|
100
|
+
5. When the map is generated click on the `Download` button to get the map.
|
101
|
+
|
102
|
+

|
103
|
+
|
104
|
+
### Option 3: Python package
|
105
|
+
🔴 Recommended for developers.<br>
|
106
|
+
You can use the Python package to generate maps. Follow these steps:
|
107
|
+
|
108
|
+
1. Install the package from PyPI:
|
109
|
+
```bash
|
110
|
+
pip install maps4fs
|
111
|
+
```
|
112
|
+
2. Import the Game class and create an instance of it:
|
113
|
+
```python
|
114
|
+
import maps4fs as mfs
|
115
|
+
|
116
|
+
game = mfs.Game.from_code("FS25")
|
117
|
+
```
|
118
|
+
In this case the library will use the default templates, which should be present in the `data` directory, which should be placed in the current working directory.<br>
|
119
|
+
Structure example:<br>
|
120
|
+
|
121
|
+
```text
|
122
|
+
📁 data
|
123
|
+
┣ 📄 fs22-map-template.zip
|
124
|
+
┗ 📄 fs22-texture-schema.json
|
125
|
+
```
|
126
|
+
|
127
|
+
So it's recommended to download the `data` directory from the repository and place it in the root of your project.<br>
|
128
|
+
|
129
|
+
3. Create an instance of the Map class:
|
130
|
+
```python
|
131
|
+
import maps4fs as mfs
|
132
|
+
|
133
|
+
map = mfs.Map(
|
134
|
+
game,
|
135
|
+
(52.5200, 13.4050), # Latitude and longitude of the map center.
|
136
|
+
height=1024, # The height of the map in meters.
|
137
|
+
width=1024, # The width of the map in meters.
|
138
|
+
map_directory="path/to/your/map/directory", # The directory where the map will be saved.
|
139
|
+
)
|
140
|
+
```
|
141
|
+
|
142
|
+
4. Generate the map:
|
143
|
+
```python
|
144
|
+
map.generate()
|
145
|
+
```
|
146
|
+
|
147
|
+
The map will be saved in the `map_directory` directory.
|
148
|
+
|
149
|
+
## Supported objects
|
150
|
+
The project is based on the [OpenStreetMap](https://www.openstreetmap.org/) data. So, refer to [this page](https://wiki.openstreetmap.org/wiki/Map_Features) to understand the list below.
|
151
|
+
- "building": True
|
152
|
+
- "highway": ["motorway", "trunk", "primary"]
|
153
|
+
- "highway": ["secondary", "tertiary", "road", "service"]
|
154
|
+
- "highway": ["unclassified", "residential", "track"]
|
155
|
+
- "natural": ["grassland", "scrub"]
|
156
|
+
- "landuse": "farmland"
|
157
|
+
- "natural": ["water"]
|
158
|
+
- "waterway": True
|
159
|
+
- "natural": ["wood", "tree_row"]
|
160
|
+
- "railway": True
|
161
|
+
|
162
|
+
The list will be updated as the project develops.
|
163
|
+
|
164
|
+
## Info sequence
|
165
|
+
The script will also generate the `generation_info.json` file in the `output` folder. It contains the following keys: <br>
|
166
|
+
`"coordinates"` - the coordinates of the map center which you entered,<br>
|
167
|
+
`"bbox"` - the bounding box of the map in lat and lon,<br>
|
168
|
+
`"map_height"` - the height of the map in meters (this one is from the user input, e.g. 2048 and so on),<br>
|
169
|
+
`"map_width"` - the width of the map in meters (same as above),<br>
|
170
|
+
`"minimum_x"` - the minimum x coordinate of the map (UTM projection),<br>
|
171
|
+
`"minimum_y"` - the minimum y coordinate of the map (UTM projection),<br>
|
172
|
+
`"maximum_x"` - the maximum x coordinate of the map (UTM projection),<br>
|
173
|
+
`"maximum_y"` - the maximum y coordinate of the map (UTM projection),<br>
|
174
|
+
`"height"` - the height of the map in meters (it won't be equal to the parameters above since the Earth is not flat, sorry flat-earthers),<br>
|
175
|
+
`"width"` - the width of the map in meters (same as above),<br>
|
176
|
+
`"height_coef"` - since we need a texture of exact size, the height of the map is multiplied by this coefficient,<br>
|
177
|
+
`"width_coef"` - same as above but for the width,<br>
|
178
|
+
`"tile_name"` - the name of the SRTM tile which was used to generate the height map, e.g. "N52E013"<br>
|
179
|
+
|
180
|
+
You can use this information to adjust some other sources of data to the map, e.g. textures, height maps, etc.
|
181
|
+
|
182
|
+
## For advanced users
|
183
|
+
The tool supports the custom size of the map. To use this feature select `Custom` in the `Map size` dropdown and enter the desired size. The tool will generate a map with the size you entered.<br>
|
184
|
+
|
185
|
+
⛔️ Do not use this feature, if you don't know what you're doing. In most cases the Giants Editor will just crash on opening the file, because you need to enter a specific values for the map size.<br><br>
|
186
|
+
|
187
|
+

|
188
|
+
|
189
|
+
You can also apply some advanced settings to the map generation process. Note that they're ADVANCED, so you don't need to use them if you're not sure what they do.<br>
|
190
|
+
|
191
|
+
Here's the list of the advanced settings:
|
192
|
+
|
193
|
+
- DEM multiplier: the height of the map is multiplied by this value. So the DEM map is just a 16-bit grayscale image, which means that the maximum avaiable value there is 65535, while the actual difference between the deepest and the highest point on Earth is about 20 km. So, by default this value is set to 3. Just note that this setting mostly does not matter, because you can always adjust it in the Giants Editor, learn more about the [heightScale](https://www.farming-simulator.org/19/terrain-heightscale.php) parameter on the [PMC Farming Simulator](https://www.farming-simulator.org/) website.
|
194
|
+
|
195
|
+
- DEM Blur radius: the radius of the Gaussian blur filter applied to the DEM map. By default, it's set to 21. This filter just makes the DEM map smoother, so the height transitions will be more natural. You can set it to 1 to disable the filter, but it will result as a Minecraft-like map.
|
196
|
+
|
197
|
+
## Bugs and feature requests
|
198
|
+
If you find a bug or have an idea for a new feature, please create an issue [here](https://github.com/iwatkot/maps4fs/issues) or contact me directly on [Telegram](https://t.me/iwatkot).<br>
|
@@ -0,0 +1 @@
|
|
1
|
+
# pylint: disable=missing-module-docstring
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"""This module contains the base class for all map generation components."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
from typing import TYPE_CHECKING, Any
|
6
|
+
|
7
|
+
import osmnx as ox # type: ignore
|
8
|
+
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from maps4fs.generator.game import Game
|
11
|
+
|
12
|
+
|
13
|
+
# pylint: disable=R0801, R0903, R0902
|
14
|
+
class Component:
|
15
|
+
"""Base class for all map generation components.
|
16
|
+
|
17
|
+
Args:
|
18
|
+
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
19
|
+
map_height (int): The height of the map in pixels.
|
20
|
+
map_width (int): The width of the map in pixels.
|
21
|
+
map_directory (str): The directory where the map files are stored.
|
22
|
+
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
23
|
+
info, warning. If not provided, default logging will be used.
|
24
|
+
"""
|
25
|
+
|
26
|
+
def __init__(
|
27
|
+
self,
|
28
|
+
game: Game,
|
29
|
+
coordinates: tuple[float, float],
|
30
|
+
map_height: int,
|
31
|
+
map_width: int,
|
32
|
+
map_directory: str,
|
33
|
+
logger: Any = None,
|
34
|
+
**kwargs, # pylint: disable=W0613, R0913, R0917
|
35
|
+
):
|
36
|
+
self.game = game
|
37
|
+
self.coordinates = coordinates
|
38
|
+
self.map_height = map_height
|
39
|
+
self.map_width = map_width
|
40
|
+
self.map_directory = map_directory
|
41
|
+
self.logger = logger
|
42
|
+
self.kwargs = kwargs
|
43
|
+
|
44
|
+
self.save_bbox()
|
45
|
+
self.preprocess()
|
46
|
+
|
47
|
+
def preprocess(self) -> None:
|
48
|
+
"""Prepares the component for processing. Must be implemented in the child class.
|
49
|
+
|
50
|
+
Raises:
|
51
|
+
NotImplementedError: If the method is not implemented in the child class.
|
52
|
+
"""
|
53
|
+
raise NotImplementedError
|
54
|
+
|
55
|
+
def process(self) -> None:
|
56
|
+
"""Launches the component processing. Must be implemented in the child class.
|
57
|
+
|
58
|
+
Raises:
|
59
|
+
NotImplementedError: If the method is not implemented in the child class.
|
60
|
+
"""
|
61
|
+
raise NotImplementedError
|
62
|
+
|
63
|
+
def previews(self) -> list[str]:
|
64
|
+
"""Returns a list of paths to the preview images. Must be implemented in the child class.
|
65
|
+
|
66
|
+
Raises:
|
67
|
+
NotImplementedError: If the method is not implemented in the child class.
|
68
|
+
"""
|
69
|
+
raise NotImplementedError
|
70
|
+
|
71
|
+
def get_bbox(self, project_utm: bool = False) -> tuple[int, int, int, int]:
|
72
|
+
"""Calculates the bounding box of the map from the coordinates and the height and
|
73
|
+
width of the map.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
project_utm (bool, optional): Whether to project the bounding box to UTM.
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
tuple[int, int, int, int]: The bounding box of the map.
|
80
|
+
"""
|
81
|
+
north, south, _, _ = ox.utils_geo.bbox_from_point(
|
82
|
+
self.coordinates, dist=self.map_height / 2, project_utm=project_utm
|
83
|
+
)
|
84
|
+
_, _, east, west = ox.utils_geo.bbox_from_point(
|
85
|
+
self.coordinates, dist=self.map_width / 2, project_utm=project_utm
|
86
|
+
)
|
87
|
+
bbox = north, south, east, west
|
88
|
+
self.logger.debug(
|
89
|
+
"Calculated bounding box for component: %s: %s, project_utm: %s",
|
90
|
+
self.__class__.__name__,
|
91
|
+
bbox,
|
92
|
+
project_utm,
|
93
|
+
)
|
94
|
+
return bbox
|
95
|
+
|
96
|
+
def save_bbox(self) -> None:
|
97
|
+
"""Saves the bounding box of the map to the component instance from the coordinates and the
|
98
|
+
height and width of the map.
|
99
|
+
"""
|
100
|
+
self.bbox = self.get_bbox(project_utm=False)
|
101
|
+
self.logger.debug("Saved bounding box: %s", self.bbox)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"""This module contains the Config class for map settings and configuration."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
import os
|
6
|
+
from xml.etree import ElementTree as ET
|
7
|
+
|
8
|
+
from maps4fs.generator.component import Component
|
9
|
+
|
10
|
+
|
11
|
+
# pylint: disable=R0903
|
12
|
+
class Config(Component):
|
13
|
+
"""Component for map settings and configuration.
|
14
|
+
|
15
|
+
Args:
|
16
|
+
coordinates (tuple[float, float]): The latitude and longitude of the center of the map.
|
17
|
+
map_height (int): The height of the map in pixels.
|
18
|
+
map_width (int): The width of the map in pixels.
|
19
|
+
map_directory (str): The directory where the map files are stored.
|
20
|
+
logger (Any, optional): The logger to use. Must have at least three basic methods: debug,
|
21
|
+
info, warning. If not provided, default logging will be used.
|
22
|
+
"""
|
23
|
+
|
24
|
+
def preprocess(self) -> None:
|
25
|
+
self._map_xml_path = self.game.map_xml_path(self.map_directory)
|
26
|
+
self.logger.debug("Map XML path: %s.", self._map_xml_path)
|
27
|
+
|
28
|
+
def process(self):
|
29
|
+
self._set_map_size()
|
30
|
+
|
31
|
+
def _set_map_size(self):
|
32
|
+
"""Edits map.xml file to set correct map size."""
|
33
|
+
if not os.path.isfile(self._map_xml_path):
|
34
|
+
self.logger.warning("Map XML file not found: %s.", self._map_xml_path)
|
35
|
+
return
|
36
|
+
tree = ET.parse(self._map_xml_path)
|
37
|
+
self.logger.debug("Map XML file loaded from: %s.", self._map_xml_path)
|
38
|
+
root = tree.getroot()
|
39
|
+
for map_elem in root.iter("map"):
|
40
|
+
map_elem.set("width", str(self.map_width))
|
41
|
+
map_elem.set("height", str(self.map_height))
|
42
|
+
self.logger.debug(
|
43
|
+
"Map size set to %sx%s in Map XML file.", self.map_width, self.map_height
|
44
|
+
)
|
45
|
+
tree.write(self._map_xml_path)
|
46
|
+
self.logger.debug("Map XML file saved to: %s.", self._map_xml_path)
|
47
|
+
|
48
|
+
def previews(self) -> list[str]:
|
49
|
+
"""Returns a list of paths to the preview images (empty list).
|
50
|
+
The component does not generate any preview images so it returns an empty list.
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
list[str]: An empty list.
|
54
|
+
"""
|
55
|
+
return []
|