Skip to main content

Popular tile grids and grids API for web mapping applications

Project description

gatilegrid

Geoadmin custom tile grid for web mapping applications.

Installation

$ pip install gatilegrid

Usage

Several tile grids are supported, namely 21781, 2056, 3857 and 4326. Here is an exemple using 21781. For 4326, an additional parameter is available (tmsCompatible=True).

from gatilegrid import getTileGrid
from gatilegrid import GeoadminTileGridLV03 as GeoadminTileGrid

zoom = 18
tileCol = 6
tileRow = 7

# Get and initialize the grid (top-left and bottom-left are availble)
gagrid = getTileGrid(21781)(originCorner='top-left')
# With extent constraint
offset = 100000
gagridExtent = GeoadminTileGrid(extent=[gagrid.MINX + offset, gagrid.MINY + offset,
                                        gagrid.MAXX - offset, gagrid.MAXY - offset])

bounds = [xmin, ymin, xmax, ymax] = gagrid.tileBounds(zoom, tileCol, tileRow)
print(bounds)
>>> [496800.0, 247600.0, 509600.0, 260400.0]
print(gagrid.tileAddressTemplate)
>>> {zoom}/{tileCol}/{tileRow}

topLeftCorner = [xmin, ymax]
tileAddress = [tileCol, tileRow] = gagrid.tileAddress(zoom, topLeftCorner)
print(tileAddress)
>>> [6, 7]

# Get the parent tiles
parentZoom = 1
gagrid.getParentTiles(zoom, tileCol, tileRow, parentZoom)
>>> [[1, 0, 0]]

# It also works if the point is within the tile
pointInTile = [topLeftCorner[0] + 200.0, topLeftCorner[1] - 200.0]
print(gagrid.tileAddress(zoom, pointInTile))
>>> [7, 6]

# Resolution in meters
print(gagrid.getResolution(zoom))
>>> 50.0

# Scale dpi dependent (defaults to 96)
print(gagrid.getScale(zoom, dpi=96.0))
>>> 188976.0

# Tile size in meters
print(gagrid.tileSize(zoom))
>>> 12800.0

# Number of tiles at zoom
print(gagrid.numberOfTilesAtZoom(zoom))
>>> 950
# Extent dependent
print(gagridExtent.numberOfTilesAtZoom(zoom))
>>> 253

# Get the closest zoom for a given resolution
print(gagrid.getClosestZoom(245))
>>> 16

# Get the ceiling zoom for a given resolution
print(gagrid.getCeilingZoom(245))
>>> 17

# Generate tilesSpec
minZoom = 16
maxZoom = zoom
tilesSpecGenerator = gagrid.iterGrid(minZoom, maxZoom)
for i, t in enumerate(tilesSpecGenerator):
    (tileBounds, zoom, tileCol, tileRow) = t
    print(t)
    if i == 1:
        break
>>> ([420000.0, 286000.0, 484000.0, 350000.0], 16, 0, 0)
>>> ([484000.0, 286000.0, 548000.0, 350000.0], 16, 1, 0)
# Extent dependent
tilesSpecGeneratorExtent = gagridExtent.iterGrid(minZoom, maxZoom)
for i, t in enumerate(tilesSpecGeneratorExtent):
    (tileBounds, zoom, tileCol, tileRow) = t
    print(t)
    if i = 1:
        break
>>> ([484000.0, 222000.0, 548000.0, 286000.0], 16, 1, 1)
>>> ([548000.0, 222000.0, 612000.0, 286000.0], 16, 2, 1)

This module also provides a simple grid API for grid cells addressing.

from gatilegrid import Grid

extent = [485349.96, 75250.055, 833849.959, 295950.054]
resolutionX = 100.0
resolutionY = -100.0
grid = Grid(extent, resolutionX, resolutionY)

# We use singed resolution to define the origin.
# Here the origin is at the top-left corner.
print(grid.origin)
>>> [485349.96, 295950.054]

# The Grid class defines a series of useful properties
print(grid.cellArea)
>>> 10000.0
print(grid.nbCellsX)
>>> 3485
print(grid.nbCellsY)
>>> 2207
print(grid.isTopLeft)
>>> True
print(grid.isBottomRight)
>>> False

[col, row] = grid.cellAddressFromPointCoordinate([500000, 100000])
print(col)
>>> 146
print(row)
>>> 1959

# Get the extent of the cell using its address
cellExtent = grid.cellExtent(col, row)
print(cellExtent)
>>> [499949.96, 99950.054, 500049.96, 100050.054]

# Get an address range using an extent
[minCol, minRow, maxCol, maxRow] = grid.getExtentAddress([500000, 100000, 550000, 150000])
print(minCol)
>>> 146
print(minRow)
>>> 1459
print(maxCol)
>>> 646
print(maxRow)
>>> 1959

Local Development

Setup

make setup

Tests

make test

Formatting and Linting

make format
make lint
#or
make format-lint

Release and Publish

New release and publish on PyPI is done automatically upon PR merge into master branch. For bug fixes and small new features, PR can be directly open on master. Then the PR title define the version bump as follow:

  • PR title and/or commit message contains #major => major version is bumped
  • PR title and/or commit message contains #patch or head branch name starts with bug-|hotfix-|bugfix- => patch version is bumped
  • Otherwise by default the minor version is bumped

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gatilegrid-1.0.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gatilegrid-1.0.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file gatilegrid-1.0.1.tar.gz.

File metadata

  • Download URL: gatilegrid-1.0.1.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for gatilegrid-1.0.1.tar.gz
Algorithm Hash digest
SHA256 835d92b90c4eec7cf5b8689cd941b73ffad2d152021eafe8e1597327ffaf0a12
MD5 543ff4bfdff1be542a5622718eaa3450
BLAKE2b-256 31f4c67ee96193a4c7a6a3a53428ecddf9b432188f0ade31126b0a7e6c3c22f3

See more details on using hashes here.

File details

Details for the file gatilegrid-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: gatilegrid-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for gatilegrid-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 087711b2f3147bfeebd65e83ea028a300e37c1b9c4cd2012bbbcd2a03ac20d8f
MD5 d051db1753d8bd486b0de9a8f40cc525
BLAKE2b-256 7b6028c086b2f8c4efa10b72147fc8f3108a56174f118c7f06514a31e91cb7e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page