Change scale argument to OSM zoom level.

Use OSM zoom level as specification of the map scale.
This commit is contained in:
Sergey Vartanov 2020-09-19 03:33:25 +03:00
parent 9e14093854
commit 54b88f05d2
3 changed files with 37 additions and 47 deletions

View file

@ -1,4 +1,4 @@
**Röntgen** is a **Röntgen** is a
* simple Python [OpenStreetMap](http://openstreetmap.org) renderer, * simple Python [OpenStreetMap](http://openstreetmap.org) renderer,
* set of icons, * set of icons,
* and map styles. * and map styles.
@ -6,13 +6,13 @@
[![Build Status](https://travis-ci.org/enzet/Roentgen.svg?branch=master) [![Build Status](https://travis-ci.org/enzet/Roentgen.svg?branch=master)
](https://travis-ci.org/enzet/Roentgen) ](https://travis-ci.org/enzet/Roentgen)
The idea behind Röntgen project is to have a possibility to *display every The idea behind Röntgen project is to have a possibility to *display any map
map feature* represented by OpenStreetMap data tags by means of colors, shapes, feature* represented by OpenStreetMap data tags by means of colors, shapes, and
and icons. icons.
Röntgen is primarily created for OpenStreetMap contributors. Suppose, you spent Röntgen is primarily created for OpenStreetMap contributors. Suppose, you spent
time adding colors for building walls, benches and shelters for bus stops but time adding colors for building walls, benches and shelters for bus stops but
they are not represented on the standard tile layer. Röntgen helps to display they are not represented on the standard tile layer. Röntgen helps to display
all changes you made. all changes you made.
Nevertheless, Röntgen map generator can generate precise but messy maps for OSM Nevertheless, Röntgen map generator can generate precise but messy maps for OSM
@ -43,16 +43,16 @@ Visualize `direction` tag for `tourism=viewpoint` and `camera:direction` for
Icon set Icon set
-------- --------
If tag is drawable it is displayed using icon combination and colors. All icons If tag is drawable it is displayed using icon combination and colors. All icons
are under [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/) license. So, are under [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/) license. So,
do whatever you want but give appropriate credit. Icon set is heavily inspired do whatever you want but give appropriate credit. Icon set is heavily inspired
by [Osmic](https://github.com/gmgeo/osmic) icon set. by [Osmic](https://github.com/gmgeo/osmic) icon set.
![Icons](doc/grid.png) ![Icons](doc/grid.png)
Feel free to request new icons via issues for whatever you want to see on the Feel free to request new icons via issues for whatever you want to see on the
map. No matter how frequently the tag is used in OpenStreetMap since final goal map. No matter how frequently the tag is used in OpenStreetMap since final goal
is to cover all tags. However, common used tags have priority, other things is to cover all tags. However, common used tags have priority, other things
being equal. being equal.
Draw icon grid: `python3 run.py grid`. Draw icon grid: `python3 run.py grid`.
@ -104,51 +104,29 @@ You can run it using:
python3 run.py \ python3 run.py \
-b ${LONGITUDE_1},${LATITUDE_1},${LONGITUDE_2},${LATITUDE_2} \ -b ${LONGITUDE_1},${LATITUDE_1},${LONGITUDE_2},${LATITUDE_2} \
-o ${OUTPUT_FILE_NAME} \ -o ${OUTPUT_FILE_NAME} \
-s ${WIDTH},${HEIGHT} -s ${OSM_ZOOM_LEVEL}
``` ```
Example: Example:
```bash ```bash
python3 run.py -b 2.284,48.86,2.29,48.865 -o map.svg -s 1000,1000 python3 run.py -b 2.284,48.86,2.29,48.865
``` ```
### Main arguments ### ### Main arguments ###
#### Required #### #### Required ####
<table> * `--boundary-box` or `-b`: boundary box to draw. Value:
<tr><td>Option</td><td>Value</td><td>Description</td></tr> `<longitude 1>,<latitude 1>,<longitude 2>,<latitude 2>`. Use space before
<tr> first `-` to escape negative values.
<td><tt>-b</tt>, <tt>--boundary-box</tt></td>
<td>
<tt>&lt;longitude 1&gt;,&lt;latitude 1&gt;,&lt;longitude
2&gt;,&lt;latitude 2&gt;</tt>
</td>
<td>Boundary box to draw.</td>
</tr>
<tr>
<td><tt>-s</tt>, <tt>--size</tt></td>
<td><tt>&lt;width&gt;,&lt;height&gt;</tt></td>
<td>Result image size in pixels.</td>
</tr>
<tr>
<td><tt>-o</tt></td>
<td><tt>&lt;path&gt;</tt></td>
<td>Path to output SVG file name.</td>
</tr>
</table>
#### Optional #### #### Optional ####
<table> * `--scale` or `-s`: OSM zoom level. See
<tr><td>Option</td><td>Value</td><td>Description</td></tr> [OSM wiki](https://wiki.openstreetmap.org/wiki/Zoom_levels). Default is 18.
<tr> * `-o`: path to output SVG file name. Default is <tt>map.svg</tt>.</td>
<td><tt>-i</tt></td> * `-i`: path to input XML file name. If this argument is not set, XML file
<td><tt>&lt;path&gt;</tt></td> will be downloaded through OpenStreetMap API.
<td>Path to input XML file name. If this argument is not set, XML file
will be downloaded through OpenStreetMap API.</td>
</tr>
</table>
Check all arguments with `python3 run.py --help`. Check all arguments with `python3 run.py --help`.

View file

@ -21,20 +21,31 @@ def pseudo_mercator(coordinates: np.array) -> np.array:
np.tan(np.pi / 4 + coordinates[0] * (np.pi / 180) / 2)))) np.tan(np.pi / 4 + coordinates[0] * (np.pi / 180) / 2))))
def osm_zoom_level_to_pixels_per_meter(zoom_level: float):
"""
Convert OSM zoom level (see https://wiki.openstreetmap.org/wiki/Zoom_levels)
to pixels per meter on Equator.
"""
return 2 ** zoom_level / 156415
class Flinger: class Flinger:
""" """
Convert geo coordinates into SVG position points. Convert geo coordinates into SVG position points.
""" """
def __init__(self, geo_boundaries: MinMax, ratio: float = 1000): def __init__(self, geo_boundaries: MinMax, scale: float = 1000):
""" """
:param geo_boundaries: minimum and maximum latitude and longitude :param geo_boundaries: minimum and maximum latitude and longitude
:param scale: OSM zoom level
""" """
self.geo_boundaries: MinMax = geo_boundaries self.geo_boundaries: MinMax = geo_boundaries
self.ratio: float = ratio self.ratio: float = (
osm_zoom_level_to_pixels_per_meter(scale) *
EQUATOR_LENGTH / 360)
self.size: np.array = self.ratio * ( self.size: np.array = self.ratio * (
pseudo_mercator(self.geo_boundaries.max_) - pseudo_mercator(self.geo_boundaries.max_) -
pseudo_mercator(self.geo_boundaries.min_)) pseudo_mercator(self.geo_boundaries.min_))
self.pixels_per_meter = 360 / EQUATOR_LENGTH * self.ratio self.pixels_per_meter = osm_zoom_level_to_pixels_per_meter(scale)
self.size: np.array = self.size.astype(int).astype(float) self.size: np.array = self.size.astype(int).astype(float)

View file

@ -38,7 +38,8 @@ def parse_options(args):
parser.add_argument( parser.add_argument(
"-s", "--scale", "-s", "--scale",
metavar="<float>", metavar="<float>",
help="map scale", help="OSM zoom level (may not be integer, default is 18)",
default=18,
dest="scale", dest="scale",
type=float, type=float,
required=True) required=True)