def simplify_layers(self, layers, layerFeatures, layerOpts): """ performs polygon simplification """ # step 1: unify from simplify import create_point_store, simplify_distance point_store = create_point_store() for id in layers: if layerOpts[id]['simplify'] is not False: for feature in layerFeatures[id]: feature.geom.unify(point_store, layerOpts[id]['unify-precision']) # print 'unified points:', point_store['removed'], (100*point_store['removed']/(point_store['removed']+point_store['kept'])),'%' to_simplify = [] for id in layers: if layerOpts[id]['simplify'] is not False: to_simplify.append(id) to_simplify.sort(key=lambda id: layerOpts[id]['simplify']) for id in to_simplify: if self._verbose: print 'simplifying', id for feature in layerFeatures[id]: for pts in feature.geom.points(): simplify_distance(pts, layerOpts[id]['simplify']) feature.geom.update()
def simplify_layers(self, layers, layerFeatures, layerOpts): """ performs polygon simplification """ # step 1: unify from simplify import create_point_store, simplify_distance point_store = create_point_store() for id in layers: if layerOpts[id]['simplify'] is not False: for feature in layerFeatures[id]: feature.geom.unify(point_store, layerOpts[id]['unify-precision']) #print 'unified points:', point_store['removed'], (100*point_store['removed']/(point_store['removed']+point_store['kept'])),'%' to_simplify = [] for id in layers: if layerOpts[id]['simplify'] is not False: to_simplify.append(id) to_simplify.sort(key=lambda id: layerOpts[id]['simplify']) for id in to_simplify: print 'simplifying', id for feature in layerFeatures[id]: for pts in feature.geom.points(): simplify_distance(pts, layerOpts[id]['simplify']) feature.geom.update()
def _simplify_layers(self): """ ### Simplify geometries """ from simplify import create_point_store, simplify_lines # We will use a glocal point cache for all layers. If the # same point appears in more than one layer, it will be # simplified only once. point_store = create_point_store() # Compute topology for all layers. That means that every point # is checked for duplicates, and eventually replaced with # an existing instance. for layer in self.layers: if layer.options['simplify'] is not False: for feature in layer.features: if feature.is_simplifyable(): feature.compute_topology( point_store, layer.options['unify-precision']) # Now we break features into line segments, which makes them # easier to simplify. for layer in self.layers: if layer.options['simplify'] is not False: for feature in layer.features: if feature.is_simplifyable(): feature.break_into_lines() # Finally, apply the chosen line simplification algorithm. total = 0 kept = 0 for layer in self.layers: if layer.options['simplify'] is not False: for feature in layer.features: if feature.is_simplifyable(): lines = feature.break_into_lines() lines = simplify_lines( lines, layer.options['simplify']['method'], layer.options['simplify']['tolerance']) for line in lines: total += len(line) for pt in line: if not pt.deleted: kept += 1 # ..and restore the geometries from the simplified line segments. feature.restore_geometry( lines, layer.options['filter-islands']) return (total, kept)
def _simplify_layers(self): """ ### Simplify geometries """ from simplify import create_point_store, simplify_lines # We will use a glocal point cache for all layers. If the # same point appears in more than one layer, it will be # simplified only once. point_store = create_point_store() # Compute topology for all layers. That means that every point # is checked for duplicates, and eventually replaced with # an existing instance. for layer in self.layers: if layer.options['simplify'] is not False: for feature in layer.features: if feature.is_simplifyable(): feature.compute_topology(point_store, layer.options['unify-precision']) # Now we break features into line segments, which makes them # easier to simplify. for layer in self.layers: if layer.options['simplify'] is not False: for feature in layer.features: if feature.is_simplifyable(): feature.break_into_lines() # Finally, apply the chosen line simplification algorithm. total = 0 kept = 0 for layer in self.layers: if layer.options['simplify'] is not False: for feature in layer.features: if feature.is_simplifyable(): lines = feature.break_into_lines() lines = simplify_lines(lines, layer.options['simplify']['method'], layer.options['simplify']['tolerance']) for line in lines: total += len(line) for pt in line: if not pt.deleted: kept += 1 # ..and restore the geometries from the simplified line segments. feature.restore_geometry(lines, layer.options['filter-islands']) return (total, kept)