Skip to content

Instantly share code, notes, and snippets.

@rmarianski
Created February 8, 2016 16:09
Show Gist options
  • Save rmarianski/5136989fdb90598aa96d to your computer and use it in GitHub Desktop.
Save rmarianski/5136989fdb90598aa96d to your computer and use it in GitHub Desktop.
mvt bounds
from tilequeue.transform import apply_to_all_coords
from tilequeue.transform import rescale_point
import shapely.wkt
def coerce_int((x, y)):
return int(x), int(y)
def make_fn(fn):
def _fn((x, y)):
x, y = fn((x, y))
return coerce_int((x, y))
return _fn
scale = 4096
bounds = (0., 0., 4096., 4096.)
geometry_wkt = 'POLYGON((0 0, 4096 0, 4096 4096, 0 4096, 0 0))'
shape = shapely.wkt.loads(geometry_wkt)
rescale_fn = rescale_point(bounds, scale)
fn = make_fn(rescale_fn)
transform_fn = apply_to_all_coords(fn)
transformed_shape = transform_fn(shape)
print transformed_shape.wkt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment