Metadata-Version: 2.1
Name: osmroutescreenlib
Version: 0.0.7
Summary: Open Street Map route screenshot
Home-page: UNKNOWN
Author: Aleksandr Krasnov
Author-email: akrasnov87@gmail.com
License: UNKNOWN
Keywords: osm route screenshot
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: geopy
Requires-Dist: mercantile
Requires-Dist: pycairo

## Описание

Библиотека для создания скриншотов маршрута в Open Street Map

`pip install OsmRouteScreenLib`

Написана на основе статьи: https://smyt.ru/blog/statc-osm-map-with-python/

### Использование

<pre>
import OsmRouteScreenLib.startup as st
import OsmRouteScreenLib.options as o

options = o.make_options('http://tile-server.domain.com/{zoom}/{x}/{y}.png',
               'https://route.domain.com/route/v1/driving/{startPoint};{endPoint}?overview=full&geometries=geojson')

st.get_route_screen_by_points((47.232565,56.141757), (47.220063,56.139836), options)
</pre>

Доступны следующие опции:

* url_tile: str - путь к тайловому серверу;
* url_routing: str - путь к серверу для получения маршрута;
* padding: float - отступ карты от краёв маршрута в процентах от 0 до 1;
* zoom: int - zoom карты;
* output: str - путь к выходному файлу;
* line_width: int - ширина линии;
* marker_text: str - метки;
* show_geodesic: bool - отображать метку с пройденной дистанцией (км);
* split_line: bool - цветовое разделение маршрута.

#### Получение расстояния между координатами

<pre>
import OsmRouteScreenLib.startup as st
import OsmRouteScreenLib.options as o

options = o.make_options('http://tile-server.domain.com/{zoom}/{x}/{y}.png',
               'https://route.domain.com/route/v1/driving/{startPoint};{endPoint}?overview=full&geometries=geojson')

distance, duration = st.get_distance((47.212137, 56.140760), (47.229151, 56.141994), options=options)
print(distance)
</pre>

По умолчанию дистанция будет получена для марштура с автотранспортом (__driving__), если требуется узнать расстояние (или время) пешком, то указать __walking__ (https://osm.server.com/route/v1/walking).

#### Получение координат по адресу

<pre>
import OsmRouteScreenLib.startup as st
import OsmRouteScreenLib.options as o
import json

# Создаем опции (можно использовать стандартные URL для геокодинга)
options = o.make_options(
    url_geocode="https://osm.server.com/search?q={address}&format=json&addressdetails=1&limit={limit}",
    url_reverse_geocode="https://osm.server.com/reverse?lat={lat}&lon={lon}&format=json&addressdetails=1"
)

# Устанавливаем User-Agent для Nominatim
options.user_agent = "MyApp/1.0 (contact@example.com)"

# Поиск по адресу
result = st.geocode_address("Москва", options, limit=1)
print(json.dumps(result, indent=2, ensure_ascii=False))

# Получение только координат
coords = st.get_coordinates_from_address("Москва", options)
if coords:
    print(f"Координаты: {coords[0]}, {coords[1]}")

# Обратное геокодирование
address = st.reverse_geocode(55.751244, 37.618423, options)
if address:
    print(f"Адрес: {address.get('display_name')}")
</pre>

## Сборка Ubuntu 22.04

Устанавливаем дополнительные библиотека: `sudo apt install libcairo2-dev pkg-config python3-dev`

<pre>
python3 -m venv routing-service
source routing-service/bin/activate
pip install -r requirements.txt
</pre>

### Публикация пакета

Устанавливаем библиотеки для публикации в pypi.org
<pre>
pip install setuptools wheel twine
</pre>

Выполняем в корне проекта
<pre>
python setup.py sdist bdist_wheel
twine upload --repository pypi dist/*
</pre>

__Внимание__: перед сборкой не забываем поменять версию в файле __setup.py__


