Issue #109: improve negative value warnings.

Add alternative approach and examples.
This commit is contained in:
Sergey Vartanov 2022-02-09 09:16:17 +03:00
parent f487f75f42
commit 7ce9a495d9
2 changed files with 21 additions and 9 deletions

View file

@ -173,10 +173,10 @@ will download OSM data to `cache/2.284,48.860,2.290,48.865.osm` and write an out
|---|---|
| <span style="white-space: nowrap;">`-i`</span>, <span style="white-space: nowrap;">`--input`</span> `<path>` | input XML file name or names (if not specified, file will be downloaded using 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;">`--boundary-box`</span> `<lon1>,<lat1>,<lon2>,<lat2>` | geo boundary box; if the first value is negative, enclose the value with quotes and use space before `-` |
| <span style="white-space: nowrap;">`-b`</span>, <span style="white-space: nowrap;">`--boundary-box`</span> `<lon1>,<lat1>,<lon2>,<lat2>` | geo boundary box; if the first value is negative, use `=` sign or enclose the value with quotes and use space before `-`, e.g. `-b=-84.752,39.504,-84.749,39.508` or `-b " -84.752,39.504,-84.749,39.508"` |
| <span style="white-space: nowrap;">`--cache`</span> `<path>` | 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 inside the tile |
| <span style="white-space: nowrap;">`-c`</span>, <span style="white-space: nowrap;">`--coordinates`</span> `<latitude>,<longitude>` | coordinates of any location inside the tile; if the first value is negative, use `=` sign or enclose the value with quotes and use space before `-`, e.g. `-c=-84.752,39.504` or `-c " -84.752,39.504"` |
| <span style="white-space: nowrap;">`-s`</span>, <span style="white-space: nowrap;">`--size`</span> `<width>,<height>` | resulted image size |
plus [map configuration options](#map-options)
@ -188,10 +188,10 @@ Command `tile` is used to generate PNG tiles for [slippy maps](https://wiki.open
| Option | Description |
|---|---|
| <span style="white-space: nowrap;">`-c`</span>, <span style="white-space: nowrap;">`--coordinates`</span> `<latitude>,<longitude>` | coordinates of any location inside the tile |
| <span style="white-space: nowrap;">`-c`</span>, <span style="white-space: nowrap;">`--coordinates`</span> `<latitude>,<longitude>` | coordinates of any location inside the tile; if the first value is negative, use `=` sign or enclose the value with quotes and use space before `-`, e.g. `-c=-84.752,39.504` or `-c " -84.752,39.504"` |
| <span style="white-space: nowrap;">`-t`</span>, <span style="white-space: nowrap;">`--tile`</span> `<zoom level>/<x>/<y>` | tile specification |
| <span style="white-space: nowrap;">`--cache`</span> `<path>` | path for temporary OSM files, default value: `cache` |
| <span style="white-space: nowrap;">`-b`</span>, <span style="white-space: nowrap;">`--boundary-box`</span> `<lon1>,<lat1>,<lon2>,<lat2>` | construct the minimum amount of tiles that cover the requested boundary box |
| <span style="white-space: nowrap;">`-b`</span>, <span style="white-space: nowrap;">`--boundary-box`</span> `<lon1>,<lat1>,<lon2>,<lat2>` | construct the minimum amount of tiles that cover the requested boundary box; if the first value is negative, use `=` sign or enclose the value with quotes and use space before `-`, e.g. `-b=-84.752,39.504,-84.749,39.508` or `-b " -84.752,39.504,-84.749,39.508"` |
| <span style="white-space: nowrap;">`-z`</span>, <span style="white-space: nowrap;">`--zoom`</span> `<range>` | OSM zoom levels; can be list of numbers or ranges, e.g. `16-18`, `16,17,18`, or `16,18-20`, default value: `18` |
| <span style="white-space: nowrap;">`-i`</span>, <span style="white-space: nowrap;">`--input`</span> `<path>` | input OSM XML file name (if not specified, the file will be downloaded using OpenStreetMap API) |

View file

@ -37,6 +37,17 @@ COMMANDS: list[str] = [
"taginfo",
]
BOUNDARY_BOX_WARNING: str = (
"if the first value is negative, use `=` sign or enclose the value with "
"quotes and use space before `-`, e.g. `-b=-84.752,39.504,-84.749,39.508` "
'or `-b " -84.752,39.504,-84.749,39.508"`'
)
COORDINATES_WARNING: str = (
"if the first value is negative, use `=` sign or enclose the value with "
"quotes and use space before `-`, e.g. `-c=-84.752,39.504` or `-c "
'" -84.752,39.504"`'
)
def parse_arguments(args: list[str]) -> argparse.Namespace:
"""Parse Map Machine command-line arguments."""
@ -191,7 +202,8 @@ def add_tile_arguments(parser: argparse.ArgumentParser) -> None:
"-c",
"--coordinates",
metavar="<latitude>,<longitude>",
help="coordinates of any location inside the tile",
help="coordinates of any location inside the tile; "
+ COORDINATES_WARNING,
)
parser.add_argument(
"-t",
@ -209,7 +221,7 @@ def add_tile_arguments(parser: argparse.ArgumentParser) -> None:
"-b",
"--boundary-box",
help="construct the minimum amount of tiles that cover the requested "
"boundary box",
"boundary box; " + BOUNDARY_BOX_WARNING,
metavar="<lon1>,<lat1>,<lon2>,<lat2>",
)
parser.add_argument(
@ -278,8 +290,7 @@ def add_render_arguments(parser: argparse.ArgumentParser) -> None:
"-b",
"--boundary-box",
metavar="<lon1>,<lat1>,<lon2>,<lat2>",
help="geo boundary box; if the first value is negative, enclose the "
"value with quotes and use space before `-`",
help="geo boundary box; " + BOUNDARY_BOX_WARNING,
)
parser.add_argument(
"--cache",
@ -299,7 +310,8 @@ def add_render_arguments(parser: argparse.ArgumentParser) -> None:
"-c",
"--coordinates",
metavar="<latitude>,<longitude>",
help="coordinates of any location inside the tile",
help="coordinates of any location inside the tile; "
+ COORDINATES_WARNING,
)
parser.add_argument(
"-s",