bbox-tiler
This script takes a bounding rectangle, and creates tile bounding linear rings in the same units (e.g. degrees). This was designed with the Google Earth Engine API in mind, and the tile boundaries can be used to create polygon geometries.
Given a desired number of output tiles, this script will determine the size of each linear ring and the approximate number of them. Given a desired length of the tile sides, it will determine the final number of tiles (defaults to 10).
Results will be saved to a csv file with schema x_tile,y_tile,bbox
if a filename is provided with the -f
flag. Otherwise, results are
printed to standard out.
Installation
sudo pip install bboxtiler
Usage
Python REPL:
from bbox_tiler import bbox
UPPER_LEFT = [99., 10.]
LOWER_RIGHT = [100., 9]
>>> bbox.mk_tile_bounding_points(UPPER_LEFT, LOWER_RIGHT, 4)
[[[99.0, 10.0], [99.0, 9.5], [99.5, 9.5], [99.5, 10.0], [99.0, 10.0]],
[[99.0, 9.5], [99.0, 9.0], [99.5, 9.0], [99.5, 9.5], [99.0, 9.5]],
[[99.5, 10.0], [99.5, 9.5], [100.0, 9.5], [100.0, 10.0], [99.5, 10.0]],
[[99.5, 9.5], [99.5, 9.0], [100.0, 9.0], [100.0, 9.5], [99.5, 9.5]]]
# include tile indices in output
>>> bbox.mk_tile_bounding_points(UPPER_LEFT, LOWER_RIGHT, 4, tile_idxs=True)
[[0, 0, [[99.0, 10.0], [99.0, 9.5], [99.5, 9.5], [99.5, 10.0], [99.0, 10.0]]],
[0, 1, [[99.0, 9.5], [99.0, 9.0], [99.5, 9.0], [99.5, 9.5], [99.0, 9.5]]],
[1, 0, [[99.5, 10.0], [99.5, 9.5], [100.0, 9.5], [100.0, 10.0], [99.5, 10.0]]],
[1, 1, [[99.5, 9.5], [99.5, 9.0], [100.0, 9.0], [100.0, 9.5], [99.5, 9.5]]]]
Command line:
$ python bbox_tiler/bbox.py -n 4 "99., 10." "100., 9."
[[99.0, 10.0], [99.0, 9.5], [99.5, 9.5], [99.5, 10.0], [99.0, 10.0]]
[[99.0, 9.5], [99.0, 9.0], [99.5, 9.0], [99.5, 9.5], [99.0, 9.5]]
[[99.5, 10.0], [99.5, 9.5], [100.0, 9.5], [100.0, 10.0], [99.5, 10.0]]
[[99.5, 9.5], [99.5, 9.0], [100.0, 9.0], [100.0, 9.5], [99.5, 9.5]]
# add tile indices
$ python bbox_tiler/bbox.py -n 4 "99., 10." "100., 9." -i
0 0 [[99.0, 10.0], [99.0, 9.5], [99.5, 9.5], [99.5, 10.0], [99.0, 10.0]]
0 1 [[99.0, 9.5], [99.0, 9.0], [99.5, 9.0], [99.5, 9.5], [99.0, 9.5]]
1 0 [[99.5, 10.0], [99.5, 9.5], [100.0, 9.5], [100.0, 10.0], [99.5, 10.0]]
1 1 [[99.5, 9.5], [99.5, 9.0], [100.0, 9.0], [100.0, 9.5], [99.5, 9.5]]
Command-line Syntax
python bbox.py -h
usage: bbox.py [-h] [-n tile-count] [-l TILE_EDGE_LENGTH] [-f output-file]
upper-left lower-right
Generate tile bounding boxes.
positional arguments:
upper-left 'x,y' string (comma separated) of upper-left corner of
bounding rectangle.
lower-right 'x,y' string (comma separated) of lower-right corner
of bounding rectangle.
optional arguments:
-h, --help show this help message and exit
-n tile-count, --tile_count tile-count
Approximate number of tiles to generate. Defaults to
10
-l TILE_EDGE_LENGTH, --tile-edge-length TILE_EDGE_LENGTH
Length of tile edge, in the same units as upper-left
and upper-right arguments (e.g. degrees or meters)
-f output-file, --output-file output-file
Output results to tab-separated file at this location.
-i, --tile-idxs Include tile indices in output.
Packaging
python setup.py register
python setup.py sdist upload