Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active September 30, 2015 07:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmcw/1746328 to your computer and use it in GitHub Desktop.
Save tmcw/1746328 to your computer and use it in GitHub Desktop.
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