Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 20, 2023
1 parent 1fa7fef commit 6e33bb1
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/container-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- id: string
- id: string
uses: ASzc/change-string-case-action@v5
with:
string: XCSoar
Expand Down
34 changes: 17 additions & 17 deletions .project
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>XCSoar MapGen</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>XCSoar MapGen</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
6 changes: 3 additions & 3 deletions .settings/org.eclipse.core.runtime.prefs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Thu Sep 23 17:28:59 CEST 2010
eclipse.preferences.version=1
line.separator=\n
#Thu Sep 23 17:28:59 CEST 2010
eclipse.preferences.version=1
line.separator=\n
24 changes: 12 additions & 12 deletions COPYING
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Preamble
Preamble

The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Expand Down Expand Up @@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE

GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. This License applies to any program or other work which contains
Expand Down Expand Up @@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
Expand Down Expand Up @@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
Expand Down Expand Up @@ -225,7 +225,7 @@ impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
Expand Down Expand Up @@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

NO WARRANTY
NO WARRANTY

11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
Expand All @@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
Expand Down
1 change: 1 addition & 0 deletions lib/xcsoar/mapgen/terrain/srtm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import os
import math
import subprocess
Expand Down
121 changes: 78 additions & 43 deletions lib/xcsoar/mapgen/topology/shapefiles.py
Original file line number Diff line number Diff line change
@@ -1,100 +1,135 @@
# -*- coding: utf-8 -*-
import os
import subprocess

from xcsoar.mapgen.georect import GeoRect
from xcsoar.mapgen.filelist import FileList

__cmd_ogr2ogr = 'ogr2ogr'
__cmd_shptree = 'shptree'
__cmd_ogr2ogr = "ogr2ogr"
__cmd_shptree = "shptree"


def __filter_datasets(bounds, datasets):
return [
dataset
for dataset in datasets
if bounds.intersects(GeoRect(*dataset['bounds']))
if bounds.intersects(GeoRect(*dataset["bounds"]))
]


def __create_layer_from_dataset(bounds, layer, dataset, append, downloader, dir_temp):
if not isinstance(bounds, GeoRect):
raise TypeError

data_dir = downloader.retrieve_extracted(dataset['name'] + '.7z')
data_dir = downloader.retrieve_extracted(dataset["name"] + ".7z")

print(('Reading dataset {} ...'.format(dataset['name'])))
arg = [__cmd_ogr2ogr, '-skipfailures']
print(("Reading dataset {} ...".format(dataset["name"])))
arg = [__cmd_ogr2ogr, "-skipfailures"]

if append:
arg.append("-update")
arg.append("-append")
else:
arg.extend(["-select", layer['label'] if 'label' in layer else ''])
arg.extend(["-select", layer["label"] if "label" in layer else ""])

if 'where' in layer:
arg.extend(["-where", layer['where']])
if "where" in layer:
arg.extend(["-where", layer["where"]])


arg.extend(["-spat",
str(bounds.left),
str(bounds.bottom),
str(bounds.right),
str(bounds.top)])
arg.extend(
[
"-spat",
str(bounds.left),
str(bounds.bottom),
str(bounds.right),
str(bounds.top),
]
)

arg.append(dir_temp)
arg.append(data_dir)

arg.append(layer['layer'])
arg.extend(['-nln', layer['name']])
arg.append(layer["layer"])
arg.extend(["-nln", layer["name"]])

subprocess.check_call(arg)


def __create_layer_index(layer, dir_temp):
print(('Generating index file for layer {} ...'.format(layer['name'])))
subprocess.check_call([__cmd_shptree, os.path.join(dir_temp, layer['name'] + ".shp")])
print(("Generating index file for layer {} ...".format(layer["name"])))
subprocess.check_call(
[__cmd_shptree, os.path.join(dir_temp, layer["name"] + ".shp")]
)

def __create_layer(bounds, layer, datasets, downloader, dir_temp, files, index, compressed=False):
print(('Creating topology layer {} ...'.format(layer['name'])))

def __create_layer(
bounds, layer, datasets, downloader, dir_temp, files, index, compressed=False
):
print(("Creating topology layer {} ...".format(layer["name"])))

datasets = __filter_datasets(bounds, datasets)
for i in range(len(datasets)):
__create_layer_from_dataset(bounds, layer, datasets[i],
i != 0, downloader, dir_temp)
__create_layer_from_dataset(
bounds, layer, datasets[i], i != 0, downloader, dir_temp
)

if os.path.exists(os.path.join(dir_temp, layer['name'] + '.shp')):
if os.path.exists(os.path.join(dir_temp, layer["name"] + ".shp")):
__create_layer_index(layer, dir_temp)

files.add(os.path.join(dir_temp, layer['name'] + '.shp'), compressed)
files.add(os.path.join(dir_temp, layer['name'] + '.shx'), compressed)
files.add(os.path.join(dir_temp, layer['name'] + '.dbf'), compressed)
files.add(os.path.join(dir_temp, layer['name'] + '.prj'), compressed)
files.add(os.path.join(dir_temp, layer['name'] + '.qix'), compressed)
files.add(os.path.join(dir_temp, layer["name"] + ".shp"), compressed)
files.add(os.path.join(dir_temp, layer["name"] + ".shx"), compressed)
files.add(os.path.join(dir_temp, layer["name"] + ".dbf"), compressed)
files.add(os.path.join(dir_temp, layer["name"] + ".prj"), compressed)
files.add(os.path.join(dir_temp, layer["name"] + ".qix"), compressed)
index.append(layer)


def __create_index_file(dir_temp, index):
file = open(os.path.join(dir_temp, 'topology.tpl'), 'w')
file = open(os.path.join(dir_temp, "topology.tpl"), "w")
try:
file.write("* filename, range, icon, label_index, r, g, b, pen_width, label_range, label_important_range\n")
file.write(
"* filename, range, icon, label_index, r, g, b, pen_width, label_range, label_important_range\n"
)
for layer in index:
file.write(layer['name'] + ',' +
str(layer['range']) + ',,' +
('1' if 'label' in layer else '') + ',' +
layer['color'] + ',' +
str(layer.get('pen_width', 1)) + ',' +
str(layer.get('label_range', layer['range'])) + ',' +
str(layer.get('label_important_range', 0)) + "\n")
file.write(
layer["name"]
+ ","
+ str(layer["range"])
+ ",,"
+ ("1" if "label" in layer else "")
+ ","
+ layer["color"]
+ ","
+ str(layer.get("pen_width", 1))
+ ","
+ str(layer.get("label_range", layer["range"]))
+ ","
+ str(layer.get("label_important_range", 0))
+ "\n"
)
finally:
file.close()
return os.path.join(dir_temp, "topology.tpl")


def create(bounds, downloader, dir_temp, compressed=False, level_of_detail=3):
topology = downloader.manifest()['topology']
layers = topology['layers']
datasets = topology['datasets']
topology = downloader.manifest()["topology"]
layers = topology["layers"]
datasets = topology["datasets"]

files = FileList()
index = []
for layer in layers:
if layer['level_of_detail'] <= level_of_detail:
__create_layer(bounds, layer, datasets[layer['dataset']], downloader, dir_temp, files, index, compressed)
if layer["level_of_detail"] <= level_of_detail:
__create_layer(
bounds,
layer,
datasets[layer["dataset"]],
downloader,
dir_temp,
files,
index,
compressed,
)

files.add(__create_index_file(dir_temp, index), True)
return files
1 change: 1 addition & 0 deletions lib/xcsoar/mapgen/waypoints/list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from xcsoar.mapgen.waypoints.waypoint import Waypoint
from xcsoar.mapgen.georect import GeoRect

Expand Down
11 changes: 7 additions & 4 deletions lib/xcsoar/mapgen/waypoints/parser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# -*- coding: utf-8 -*-
from xcsoar.mapgen.waypoints.seeyou_reader import parse_seeyou_waypoints
from xcsoar.mapgen.waypoints.winpilot_reader import parse_winpilot_waypoints


def parse_waypoint_file(filename, file=None):
if not file:
file = open(filename, 'r')
file = open(filename, "r")

if filename.lower().endswith('.xcw') or filename.lower().endswith('.dat'):
if filename.lower().endswith(".xcw") or filename.lower().endswith(".dat"):
return parse_winpilot_waypoints(file)
elif filename.lower().endswith('.cup'):
elif filename.lower().endswith(".cup"):
return parse_seeyou_waypoints(file)
else:
raise RuntimeError('Waypoint file {} has an unsupported format.'.format(filename))
raise RuntimeError(
"Waypoint file {} has an unsupported format.".format(filename)
)
1 change: 1 addition & 0 deletions lib/xcsoar/mapgen/waypoints/seeyou_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from xcsoar.mapgen.waypoints.waypoint import Waypoint
from xcsoar.mapgen.waypoints.list import WaypointList

Expand Down
1 change: 1 addition & 0 deletions lib/xcsoar/mapgen/waypoints/seeyou_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from xcsoar.mapgen.waypoints.list import WaypointList


Expand Down
18 changes: 9 additions & 9 deletions lib/xcsoar/mapgen/waypoints/waypoint.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from xcsoar.mapgen.geopoint import GeoPoint


class Waypoint(GeoPoint):
def __init__(self):
self.altitude = None
self.name = ''
self.short_name = ''
self.icao = ''
self.country_code = ''
self.name = ""
self.short_name = ""
self.icao = ""
self.country_code = ""
self.surface = None
self.runway_len = None
self.runway_dir = None
Expand All @@ -16,8 +18,6 @@ def __init__(self):
self.comment = None

def __str__(self):
return '{}, {}, {}, {}'.format(self.name,
super(Waypoint, self).__str__(),
self.altitude,
self.type)

return "{}, {}, {}, {}".format(
self.name, super(Waypoint, self).__str__(), self.altitude, self.type
)
1 change: 1 addition & 0 deletions lib/xcsoar/mapgen/waypoints/welt2000.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import os
import subprocess

Expand Down
1 change: 1 addition & 0 deletions lib/xcsoar/mapgen/waypoints/welt2000_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import re

from xcsoar.mapgen.waypoints.waypoint import Waypoint
Expand Down
Loading

0 comments on commit 6e33bb1

Please sign in to comment.