-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
1fa7fef
commit 6e33bb1
Showing
15 changed files
with
146 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import math | ||
import subprocess | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from xcsoar.mapgen.waypoints.list import WaypointList | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import subprocess | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.