Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active Sep 30, 2015
Embed
What would you like to do?
import shapely
from shapely import speedups, wkb
from shapely.geometry import *
from osgeo import ogr
import time, random
from math import *
if shapely.speedups.available:
shapely.speedups.enable()
source = ogr.Open('data/diss.shp')
l = source.GetLayer(0)
f = l.GetNextFeature()
countries = shapely.wkb.loads(f.GetGeometryRef().ExportToWkb())
shpdriver = ogr.GetDriverByName('ESRI Shapefile')
squiggle_ds = shpdriver.CreateDataSource("out/shadow%d.shp" % time.time())
lyr = squiggle_ds.CreateLayer('squiggle')
xs = [x * 0.5 for x in range(-360, 360)]
for y in range(-80, 80):
lsp = []
for x in xs:
p = Point((x, y))
if p.intersects(countries):
lsp.append((x, y + random.random() - 0.5))
else:
lsp.append((x, y + (sin(x * (0.05 + (abs(y) / 80.0) )))))
ls = LineString(lsp)
q_geom = ogr.CreateGeometryFromWkb(ls.wkb)
feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetGeometry(q_geom)
lyr.CreateFeature(feat)
print "created feature for %d" % y
@teeler
Copy link

teeler commented Feb 11, 2012

Publish the data!! ;)
(the source data)

@tmcw
Copy link
Author

tmcw commented Mar 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment