Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IPython Notebook and supporting script.
- Loading branch information
Sean Gillies
committed
Oct 14, 2014
1 parent
77aff4b
commit 1ed88ee
Showing
4 changed files
with
530 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bench/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Benchmarks | ||
========== | ||
|
||
Scripts for benchmarking and analysis of tile indexing. | ||
|
||
Setup | ||
----- | ||
|
||
.. code-block:: console | ||
|
||
pip install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
|
||
# Check the tile indexing of a shapefile's features | ||
# | ||
# 1. Read feature from a file | ||
# 2. Compute its tile index | ||
# 3. Compare the size of its tile index to its own size | ||
# 4. Save tile index zoom level, above ratio to a dict | ||
# 4. Next feature... | ||
# 5. Dump/plot statistics | ||
|
||
from collections import defaultdict | ||
import math | ||
from pprint import pprint | ||
|
||
import click | ||
import mercantile | ||
import fiona | ||
|
||
|
||
latitude_x = math.atan(math.sinh(math.pi)) | ||
|
||
|
||
@click.command() | ||
@click.argument('input', type=click.Path(exists=True)) | ||
def index_features(input): | ||
levels = defaultdict(lambda: defaultdict(int)) | ||
with fiona.open(input) as src: | ||
for i, feat in enumerate(src): | ||
feat_bounds = fiona.bounds(feat) | ||
|
||
# Tile bounds and area. | ||
x, y, z = mercantile.bounding_tile(*feat_bounds) | ||
w, s, e, n = mercantile.bounds(x, y, z) | ||
tile_length = (2 * math.pi * 6378137.0) / (2.0 ** z) | ||
|
||
# Feature bounds and area. | ||
w, s, e, n = feat_bounds | ||
if s < -latitude_x: | ||
s = latitude_x | ||
if n > latitude_x: | ||
n = latitude_x | ||
minx, miny = mercantile.xy(w, s) | ||
maxx, maxy = mercantile.xy(e, n) | ||
feature_width, feature_height = (maxx - minx), (maxy - miny) | ||
feature_length = max(feature_width, feature_height) | ||
|
||
print i, z, tile_length, feature_length, tile_length/feature_length | ||
|
||
|
||
if __name__ == '__main__': | ||
index_features() |
Oops, something went wrong.