Skip to content

Commit

Permalink
IPython Notebook and supporting script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Gillies committed Oct 14, 2014
1 parent 77aff4b commit 1ed88ee
Show file tree
Hide file tree
Showing 4 changed files with 530 additions and 0 deletions.
1 change: 1 addition & 0 deletions .npmignore
@@ -0,0 +1 @@
bench/
11 changes: 11 additions & 0 deletions bench/README.md
@@ -0,0 +1,11 @@
Benchmarks
==========

Scripts for benchmarking and analysis of tile indexing.

Setup
-----

.. code-block:: console

pip install -r requirements.txt
52 changes: 52 additions & 0 deletions bench/dataset-tiling
@@ -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()

0 comments on commit 1ed88ee

Please sign in to comment.