mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-21 21:16:24 +02:00
Change scale argument to OSM zoom level.
Use OSM zoom level as specification of the map scale.
This commit is contained in:
parent
9e14093854
commit
54b88f05d2
3 changed files with 37 additions and 47 deletions
62
readme.md
62
readme.md
|
@ -6,13 +6,13 @@
|
|||
[
|
||||
](https://travis-ci.org/enzet/Roentgen)
|
||||
|
||||
The idea behind Röntgen project is to have a possibility to *display every
|
||||
map feature* represented by OpenStreetMap data tags by means of colors, shapes,
|
||||
and icons.
|
||||
The idea behind Röntgen project is to have a possibility to *display any map
|
||||
feature* represented by OpenStreetMap data tags by means of colors, shapes, and
|
||||
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
|
||||
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.
|
||||
|
||||
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
|
||||
--------
|
||||
|
||||
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,
|
||||
do whatever you want but give appropriate credit. Icon set is heavily inspired
|
||||
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,
|
||||
do whatever you want but give appropriate credit. Icon set is heavily inspired
|
||||
by [Osmic](https://github.com/gmgeo/osmic) icon set.
|
||||
|
||||

|
||||
|
||||
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
|
||||
is to cover all tags. However, common used tags have priority, other things
|
||||
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
|
||||
being equal.
|
||||
|
||||
Draw icon grid: `python3 run.py grid`.
|
||||
|
@ -104,51 +104,29 @@ You can run it using:
|
|||
python3 run.py \
|
||||
-b ${LONGITUDE_1},${LATITUDE_1},${LONGITUDE_2},${LATITUDE_2} \
|
||||
-o ${OUTPUT_FILE_NAME} \
|
||||
-s ${WIDTH},${HEIGHT}
|
||||
-s ${OSM_ZOOM_LEVEL}
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```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 ###
|
||||
|
||||
#### Required ####
|
||||
|
||||
<table>
|
||||
<tr><td>Option</td><td>Value</td><td>Description</td></tr>
|
||||
<tr>
|
||||
<td><tt>-b</tt>, <tt>--boundary-box</tt></td>
|
||||
<td>
|
||||
<tt><longitude 1>,<latitude 1>,<longitude
|
||||
2>,<latitude 2></tt>
|
||||
</td>
|
||||
<td>Boundary box to draw.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>-s</tt>, <tt>--size</tt></td>
|
||||
<td><tt><width>,<height></tt></td>
|
||||
<td>Result image size in pixels.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>-o</tt></td>
|
||||
<td><tt><path></tt></td>
|
||||
<td>Path to output SVG file name.</td>
|
||||
</tr>
|
||||
</table>
|
||||
* `--boundary-box` or `-b`: boundary box to draw. Value:
|
||||
`<longitude 1>,<latitude 1>,<longitude 2>,<latitude 2>`. Use space before
|
||||
first `-` to escape negative values.
|
||||
|
||||
#### Optional ####
|
||||
|
||||
<table>
|
||||
<tr><td>Option</td><td>Value</td><td>Description</td></tr>
|
||||
<tr>
|
||||
<td><tt>-i</tt></td>
|
||||
<td><tt><path></tt></td>
|
||||
<td>Path to input XML file name. If this argument is not set, XML file
|
||||
will be downloaded through OpenStreetMap API.</td>
|
||||
</tr>
|
||||
</table>
|
||||
* `--scale` or `-s`: OSM zoom level. See
|
||||
[OSM wiki](https://wiki.openstreetmap.org/wiki/Zoom_levels). Default is 18.
|
||||
* `-o`: path to output SVG file name. Default is <tt>map.svg</tt>.</td>
|
||||
* `-i`: path to input XML file name. If this argument is not set, XML file
|
||||
will be downloaded through OpenStreetMap API.
|
||||
|
||||
Check all arguments with `python3 run.py --help`.
|
||||
|
|
|
@ -21,20 +21,31 @@ def pseudo_mercator(coordinates: np.array) -> np.array:
|
|||
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:
|
||||
"""
|
||||
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 scale: OSM zoom level
|
||||
"""
|
||||
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 * (
|
||||
pseudo_mercator(self.geo_boundaries.max_) -
|
||||
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)
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ def parse_options(args):
|
|||
parser.add_argument(
|
||||
"-s", "--scale",
|
||||
metavar="<float>",
|
||||
help="map scale",
|
||||
help="OSM zoom level (may not be integer, default is 18)",
|
||||
default=18,
|
||||
dest="scale",
|
||||
type=float,
|
||||
required=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue