Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ will download OSM data to `cache/2.284,48.860,2.290,48.865.osm` and render an SV

| Option | Description |
|---|---|
| <span style="white-space: nowrap;">`--no-overpass`</span> | do not use Overpass API to download complete data for incomplete relations |
| <span style="white-space: nowrap;">`--overpass-query`</span> `<path>` | path to a custom Overpass query file; use {{bbox}} as a placeholder for the bounding box |
| <span style="white-space: nowrap;">`-i`</span>, <span style="white-space: nowrap;">`--input`</span> `<path>` | input XML file name or names (if not specified, files will be downloaded using the OpenStreetMap API) |
| <span style="white-space: nowrap;">`-o`</span>, <span style="white-space: nowrap;">`--output`</span> `<path>` | output SVG file name, default value: `out/map.svg` |
| <span style="white-space: nowrap;">`-b`</span>, <span style="white-space: nowrap;">`--bounding-box`</span>, <span style="white-space: nowrap;">`--boundary-box`</span> `<lon1>,<lat1>,<lon2>,<lat2>` | geographic bounding box |
| <span style="white-space: nowrap;">`--cache`</span> `<path>` | directory path for temporary OSM files, default value: `cache` |
| <span style="white-space: nowrap;">`-z`</span>, <span style="white-space: nowrap;">`--zoom`</span> `<float>` | OSM zoom level, default value: 18.0 |
| <span style="white-space: nowrap;">`-c`</span>, <span style="white-space: nowrap;">`--coordinates`</span> `<latitude>,<longitude>` | coordinates of any location within the tile |
| <span style="white-space: nowrap;">`-s`</span>, <span style="white-space: nowrap;">`--size`</span> `<width>,<height>` | resulting image size |
| <span style="white-space: nowrap;">`--no-overpass`</span> | do not use Overpass API to download complete data for incomplete relations |
| <span style="white-space: nowrap;">`--overpass-query`</span> `<path>` | path to a custom Overpass query file; use {{bbox}} as a placeholder for the bounding box |
| <span style="white-space: nowrap;">`--gpx`</span> `<path>` | path to a GPX file to draw as a track overlay |
| <span style="white-space: nowrap;">`--track-color`</span> `<color>` | track stroke color (default: #FF0000), default value: `#FF0000` |
| <span style="white-space: nowrap;">`--track-width`</span> `<float>` | track stroke width in pixels (default: 3.0), default value: 3.0 |
Expand Down
5 changes: 1 addition & 4 deletions map_machine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
PYTHON_MAJOR_VERSION: int = 3
PYTHON_MINOR_VERSION: int = 9

if (
sys.version_info.major < PYTHON_MAJOR_VERSION
or sys.version_info.minor < PYTHON_MINOR_VERSION
):
if sys.version_info < (PYTHON_MAJOR_VERSION, PYTHON_MINOR_VERSION):
sys.exit(1)

main()
52 changes: 27 additions & 25 deletions map_machine/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def construct_ways(self) -> None:
# Coastline is handled by `CoastlineProcessor`.
continue

if not way.nodes:
continue

if not self._should_crop() or not self._crop_bounding_box:
self.construct_line(way, [], [way.nodes])
continue
Expand Down Expand Up @@ -279,7 +282,8 @@ def construct_line(

line_styles: list[LineStyle] = self.scheme.get_style(line.tags)

for line_style in line_styles:
if line_styles:
line_style = line_styles[-1]
new_line_style: LineStyle = line_style
if recolor is not None:
new_style: dict[str, float | int | str] = dict(line_style.style)
Expand All @@ -294,7 +298,7 @@ def construct_line(
StyledFigure(line.tags, inners, outers, new_line_style)
)

if not (
if (
line.get_tag("area") == "yes"
or line.get_tag("type") == "multipolygon"
or (
Expand All @@ -303,30 +307,28 @@ def construct_line(
and self.scheme.is_area(line.tags)
)
):
continue

priority: int
icon_set: IconSet | None
icon_set, priority = self.configuration.get_icon(
line.tags, processed
)
if icon_set is not None:
labels: list[Label] = self.text_constructor.construct_text(
line.tags,
processed,
self.configuration.label_mode,
priority: int
icon_set: IconSet | None
icon_set, priority = self.configuration.get_icon(
line.tags, processed
)
point: Point = Point(
icon_set,
labels,
line.tags,
processed,
center_point,
is_for_node=False,
priority=priority,
add_tooltips=self.configuration.show_tooltips,
)
self.points.append(point)
if icon_set is not None:
labels: list[Label] = self.text_constructor.construct_text(
line.tags,
processed,
self.configuration.label_mode,
)
point: Point = Point(
icon_set,
labels,
line.tags,
processed,
center_point,
is_for_node=False,
priority=priority,
add_tooltips=self.configuration.show_tooltips,
)
self.points.append(point)

# TODO(enzet): probably we may want to skip the next part if
# `line_styles` are not empty.
Expand Down
10 changes: 7 additions & 3 deletions map_machine/element/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ def draw_area(tags: Tags, path: Path) -> None:

def draw_element(options: argparse.Namespace) -> None:
"""Entry point for element drawing."""
tags_description: Tags = {
x.split("=")[0]: x.split("=")[1] for x in options.tags.split(",")
}
tags_description: Tags = {}
for x in options.tags.split(","):
parts: list[str] = x.split("=", 1)
if len(parts) != 2:
logger.fatal(f"Invalid tag `{x}`, expected `key=value` format.")
sys.exit(1)
tags_description[parts[0]] = parts[1]
if options.type == "node":
draw_node(tags_description, Path(options.output_file))
elif options.type == "way":
Expand Down
1 change: 1 addition & 0 deletions map_machine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def main() -> None:

if not arguments.command:
logging.fatal("No command provided. See --help.")
sys.exit(1)

elif arguments.command == "render":
from map_machine import mapper # noqa: PLC0415
Expand Down
4 changes: 2 additions & 2 deletions map_machine/osm/osm_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_osm(
message = "Cannot download data."
raise NetworkError(message)

with cache_file_path.open("bw+") as output_file:
with cache_file_path.open("wb") as output_file:
output_file.write(content)

return content.decode("utf-8")
Expand Down Expand Up @@ -226,7 +226,7 @@ def get_osm_overpass(
message = "Unexpected Overpass API response."
raise NetworkError(message)

with cache_file_path.open("bw+") as output_file:
with cache_file_path.open("wb") as output_file:
output_file.write(content)

return content.decode("utf-8")
2 changes: 2 additions & 0 deletions map_machine/osm/osm_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

def is_cycle(nodes: list[OSMNode]) -> bool:
"""Check whether the way is a cycle or an area boundary."""
if not nodes:
return False
return nodes[0] == nodes[-1]


Expand Down
2 changes: 2 additions & 0 deletions map_machine/scheme/carto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ variables:
# ford_color
foot_border_color: white
foot_border_width: 3.0
foot_border_opacity: 0.4
foot_color-noaccess: "#bbbbbb"
foot_color: salmon
foot_dasharray: 3,3
Expand Down Expand Up @@ -144,6 +145,7 @@ variables:
place_of_worship_border_color: {color: "#d0d0d0", darken: 0.3}
place_of_worship_border_width: 0.3
power_color: {color: $industrial_color, darken: 0.05}
power_opacity: $industrial_opacity
power_border_color: {color: $industrial_border_color, darken: 0.05}
societal_amenities_color: "#ffffe5"
societal_amenities_border_color: {color: "#ffffe5", darken: 0.35}
Expand Down
6 changes: 5 additions & 1 deletion map_machine/scheme/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ variables:
embankment_color: "#666666"
ford_color: "#88BBFF"
foot_border_color: "#FFFFFF"
foot_border_width: 3.0
foot_border_width: 0.0
foot_border_opacity: 1.0
# foot_color-noaccess
foot_color: "#B89A74"
foot_dasharray: 7.0,3.0
motorway_border_color: "#CC8800"
motorway_color: "#FFAA33"
trunk_border_color: "#CC8800"
trunk_color: "#FFAA33"
primary_border_color: "#AA8800"
primary_color: "#FFDD66"
secondary_border_color: "#BB9911"
Expand Down Expand Up @@ -248,6 +251,7 @@ variables:
playground_color: "#FFDDCC"
power_color: $industrial_color
power_border_color: $industrial_border_color
power_opacity: $industrial_opacity
prison_color: "#888888"
prison_opacity: 0.1
prison_border_color: "#888888"
Expand Down
2 changes: 1 addition & 1 deletion map_machine/scheme/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ nodes:
location_restrictions: {include: [jp]}
shapes: [{shape: japan_fire_station, color: $emergency_color}]
- tags: {amenity: courthouse}
shapes: [gavel]
shapes: [{shape: gavel, color: $amenity_brown_color}]
- tags: {amenity: police}
location_restrictions: {include: [jp]}
shapes: [japan_police_station]
Expand Down
8 changes: 4 additions & 4 deletions map_machine/scheme/roads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ roads:
priority: 41.8
- tags: {highway: trunk}
default_width: 7.0
border_color: $motorway_border_color
color: $motorway_color
border_color: $trunk_border_color
color: $trunk_color
priority: 41.0
- tags: {highway: trunk_link}
default_width: 7.0
border_color: $motorway_border_color
color: $motorway_color
border_color: $trunk_border_color
color: $trunk_color
priority: 41.0
- tags: {highway: primary}
default_width: 7.0
Expand Down
6 changes: 5 additions & 1 deletion map_machine/scheme/ways.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ ways:
stroke-linecap: butt
- tags: {highway: path}
style:
stroke-width: 3.0
stroke-width: $foot_border_width
stroke: $foot_border_color
opacity: $foot_border_opacity
priority: $priority_road_3

- tags: {highway: footway}
Expand Down Expand Up @@ -607,18 +608,21 @@ ways:
- tags: {power: substation}
style:
fill: $power_color
opacity: $power_opacity
stroke: $power_border_color
stroke-width: 0.5
priority: $priority_landuse_1
- tags: {power: plant}
style:
fill: $power_color
opacity: $power_opacity
stroke: $power_border_color
stroke-width: 0.5
priority: $priority_landuse_1
- tags: {power: generator}
style:
fill: $power_color
opacity: $power_opacity
stroke: $power_border_color
stroke-width: 0.5
priority: $priority_landuse_1
Expand Down
Loading