def simplify(filename, tolerance=0.00035):
""" Simplify GeoJSON vector """
# tolerance is set using GeoJSON map units. Expects decimal degrees, but should work with anything
if tolerance is None:
return filename
logger.info('Updating file %s with simplified geometries' % filename, action='Updating file',
actee=filename, actor=__name__)
vs = ogr.Open(filename, 1) # 1 opens the file in read/write mode, 0 for read-only mode
layer = vs.GetLayer()
feat = layer.GetNextFeature()
while feat is not None:
geo = feat.geometry()
simple = geo.Simplify(tolerance)
feat.SetGeometry(simple)
layer.SetFeature(feat)
feat = layer.GetNextFeature()
layer = None
vs.Destroy()
评论列表
文章目录