Library for building OSM tools
Project description
pyosmkit: library for building OSM tools
This package contains helpers for building tools around OSM tiles.
Since 0.11 package name was changed from pyosm to pyosmkit to avoid pypi conflicts.
Installation
# from pypi
pip install --user pyosmkit
# or from github where ${TAG} is the git version tag, eg v0.6
pip install --user git+https://github.com/tierpod/pyosmkit.git@${TAG}#egg=pyosmkit
Developing
git clone https://github.com/tierpod/pyosmkit.git && cd pyosmkit
make venv
source ./venv/bin/activate
make init-dev
pyosmkit.point
Create points, convert coordinates.
- zxy_to_latlong(z, x, y) -> LatLong
- latlong_to_zxy(lat, lng, zoom) -> ZXY
>>> import pyosmkit.point
>>> p = pyosmkit.point.ZXY(z=10, x=697, y=321)
>>> pyosmkit.point.zxy_to_latlong(p.z, p.x, p.y)
LatLong(lat=55.5783, long=65.0391)
pyosmkit.tile
Create osm tile, get filename.
- Tile.from_url(url) -> Tile
- Tile.from_metatile(mt) -> Tile
- Tile.filepath(url) -> str
>>> from pyosmkit.tile import Tile
>>> t = Tile.from_url("/style/1/1/1.png")
>>> print(t)
Tile(z:1, x:1, y:1, style:style, ext:.png)
>>> t.filepath("/cache")
'/cache/style/1/1/1.png'
pyosmkit.polygon
List of tiles can be grouped to the closed polygon. You can check if LatLong point inside this polygon or not (using ray-casting algorithm):
>>> from pyosmkit.point import LatLong
>>> from pyosmkit.polygon import Polygon
>>> polygon = Polygon([LatLong(0, 0), LatLong(10, 0), LatLong(10, 10),
... LatLong(0, 10), LatLong(0, 0)])
>>> LatLong(1, 2) in polygon
True
>>> LatLong(11, 12) in polygon
False
Also, a list of polygons can be grouped to Region (support in statement).
pyosmkit.metatile
Metatile
Create metatile coordinates, get filename:
- Metatile.from_url(url) -> Metatile
- Metatile.from_tile(Tile) -> Metatile
- Metatile.filepath(basedir) -> str
>>> from pyosmkit.tile import Tile
>>> from pyosmkit.metatile import Metatile
>>> tile = Tile(z=10, x=697, y=321, style="mapname", ext=".png")
>>> mt = Metatile.from_tile(tile)
>>> print(mt)
Metatile(z:10, x:696-703, y:320-327, style:mapname)
>>> mt.filepath("/cache")
'/cache/mapname/10/0/0/33/180/128.meta'
MetatileFile
Try to implement metatile file encoder/decoder in pythonic way (inspired by Raymond Hettinger videos).
- pyosmkit.metatile.open(filename, mode) -> MetatileFile: opens file for reading ("rb" mode) or writing ("wb"). Returns file-like object.
Support with statement, in statement, iterating over points:
>>> import pyosmkit.metatile
>>> mt = pyosmkit.metatile.open("tests/data/0.meta", "rb")
>>> # check if tile (1, 2) contains in metatile
>>> (1, 2) in mt
True
>>> (10, 10) in mt
False
>>> # iterate over Points and print only points with x == 7
>>> for point in mt:
... if point.x == 7:
... print(point)
Point(x=7, y=0)
Point(x=7, y=1)
Point(x=7, y=2)
Point(x=7, y=3)
Point(x=7, y=4)
Point(x=7, y=5)
Point(x=7, y=6)
Point(x=7, y=7)
>>> # read all tiles data, iterate over Points and print only none-empty data:
>>> tiles_data = mt.readtiles()
>>> for point, data in tiles_data.items():
... if data:
... # do something with point(z, x, y) or data (bytes)
... pass
>>> mt.close()
- MetatileFile.readtile(x, y) -> bytes
- MetatileFile.readtiles() -> dict {Point(x, y): bytes, ...}
- MetatileFile.write(x, y, z, data), where z is the metatile zoom level, x, y is the lowest values, data is the dict {Point(x, y): bytes, ...}
metatile format description
Can be found in mod_tile project:
pyosmkit.mbtile
Decode mbtiles file, read tile from mbtiles file. Support with, in statements.
>>> import pyosmkit.mbtile
>>> from pyosmkit.point import ZXY
>>> point = ZXY(z=1, x=1, y=0)
>>> with pyosmkit.mbtile.open("tests/data/0.mbtiles") as mb:
... print(point in mb)
... print(len(mb.readtile(point.z, point.x, point.y)))
True
26298
-
pyosmkit.mbtile.open(file, mode, flip_y) -> MBTileFile: open file for reading. Returns file-like object.
-
MBTileFile.readtile(z, x, y) -> buffer
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyosmkit-0.11.tar.gz.
File metadata
- Download URL: pyosmkit-0.11.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d888cf3a177eccb6f7e5a4d8d8db224518bf392851fc26bcf674a4ae427471f
|
|
| MD5 |
2626c2b41466b67ce76b62c8f3c957f2
|
|
| BLAKE2b-256 |
44e741596bd47c5e90ec6cd2f465496c9a7f92922f0461c0cca8d4527ecc6407
|
File details
Details for the file pyosmkit-0.11-py2-none-any.whl.
File metadata
- Download URL: pyosmkit-0.11-py2-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aeae3a81dab47a94156d9da38f9c0e70f1293988b651a4d79ea72ba2f871252
|
|
| MD5 |
8a6ee00ad305c6b434c997c316e34a4e
|
|
| BLAKE2b-256 |
25efd8b00723144f6ac92ac02d9c34b6288934b7ebba9f242363574f60f217d9
|