Last active
September 30, 2015 07:38
-
-
Save tmcw/1746328 to your computer and use it in GitHub Desktop.
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Publish the data!! ;)
(the source data)