mirror of
https://github.com/enzet/map-machine.git
synced 2025-08-06 10:09:52 +02:00
Issue #76: make equator length a parameter.
This commit is contained in:
parent
902956b1b3
commit
7fcfc85d44
1 changed files with 10 additions and 5 deletions
|
@ -10,8 +10,6 @@ from roentgen.boundary_box import BoundaryBox
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
|
||||||
EQUATOR_LENGTH: float = 40_075_017 # meters
|
|
||||||
|
|
||||||
|
|
||||||
def pseudo_mercator(coordinates: np.ndarray) -> np.ndarray:
|
def pseudo_mercator(coordinates: np.ndarray) -> np.ndarray:
|
||||||
"""
|
"""
|
||||||
|
@ -27,15 +25,19 @@ def pseudo_mercator(coordinates: np.ndarray) -> np.ndarray:
|
||||||
return np.array((coordinates[1], y))
|
return np.array((coordinates[1], y))
|
||||||
|
|
||||||
|
|
||||||
def osm_zoom_level_to_pixels_per_meter(zoom_level: float) -> float:
|
def osm_zoom_level_to_pixels_per_meter(
|
||||||
|
zoom_level: float, equator_length: float = 40_075_017.0
|
||||||
|
) -> float:
|
||||||
"""
|
"""
|
||||||
Convert OSM zoom level to pixels per meter on Equator. See
|
Convert OSM zoom level to pixels per meter on Equator. See
|
||||||
https://wiki.openstreetmap.org/wiki/Zoom_levels
|
https://wiki.openstreetmap.org/wiki/Zoom_levels
|
||||||
|
|
||||||
:param zoom_level: integer number usually not bigger than 20, but this
|
:param zoom_level: integer number usually not bigger than 20, but this
|
||||||
function allows any non-negative float value
|
function allows any non-negative float value
|
||||||
|
:param equator_length: celestial body equator length in meters, default
|
||||||
|
value is set for Earth
|
||||||
"""
|
"""
|
||||||
return 2 ** zoom_level / EQUATOR_LENGTH * 256
|
return 2 ** zoom_level / equator_length * 256
|
||||||
|
|
||||||
|
|
||||||
class Flinger:
|
class Flinger:
|
||||||
|
@ -48,17 +50,20 @@ class Flinger:
|
||||||
geo_boundaries: BoundaryBox,
|
geo_boundaries: BoundaryBox,
|
||||||
zoom_level: float = 18,
|
zoom_level: float = 18,
|
||||||
border: np.ndarray = np.array((0, 0)),
|
border: np.ndarray = np.array((0, 0)),
|
||||||
|
equator_length: float = 40_075_017.0,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
:param geo_boundaries: minimum and maximum latitude and longitude
|
:param geo_boundaries: minimum and maximum latitude and longitude
|
||||||
:param zoom_level: zoom level in OpenStreetMap terminology
|
:param zoom_level: zoom level in OpenStreetMap terminology
|
||||||
:param border: size of padding in pixels
|
:param border: size of padding in pixels
|
||||||
|
:param equator_length: celestial body equator length in meters, default
|
||||||
|
value is set for Earth
|
||||||
"""
|
"""
|
||||||
self.geo_boundaries: BoundaryBox = geo_boundaries
|
self.geo_boundaries: BoundaryBox = geo_boundaries
|
||||||
self.border: np.ndarray = border
|
self.border: np.ndarray = border
|
||||||
self.ratio: float = (
|
self.ratio: float = (
|
||||||
osm_zoom_level_to_pixels_per_meter(zoom_level)
|
osm_zoom_level_to_pixels_per_meter(zoom_level)
|
||||||
* EQUATOR_LENGTH
|
* equator_length
|
||||||
/ 360
|
/ 360
|
||||||
)
|
)
|
||||||
self.size: np.ndarray = border * 2 + self.ratio * (
|
self.size: np.ndarray = border * 2 + self.ratio * (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue