Toss the dwarf or pick up the axe

BTW, a member of the ANSI C committee once told me that the only thing rand is used for in C code is to decide whether to pick up the axe or throw the dwarf, and if that’s true I guess “the typical libc rand” is adequate for all but the most fanatic of gamers . Tim Peters. 21 June 1997

import ogr
import osr
import random

ds = ogr.Open(r'c:\hobu\shapefiles\data.shp', 1)

layer = ds.GetLayer(0)
count = layer.GetFeatureCount()
for i in range(count):
    feature = layer.GetFeature(i)
    fudge = random.randint(0,10000)
    geometry = feature.GetGeometryRef()
    gcount = geometry.GetGeometryCount()

    for j in range(gcount):
        g = geometry.GetGeometryRef(j)
        pcount = g.GetPointCount()

        for p in range(pcount):
            x,y = g.GetX(p), g.GetY(p)
            g.SetPoint(p,x+fudge,y+fudge,0)

    layer.SetFeature(feature)

ds.Destroy()

Leave a Reply