def distance_poi_building(self, poi_node, building): """ Returns the distance between a point of interest and a building @type poi_node: L{geo.osm_import.Node} @param poi_node: OSM Node object @type building: L{geo.osm_import.Way} @param building: OSM Way object that is a building @returns: the distance in meters @rtype: C{float} """ min_dist = 1e400 bnodes = building.nodes for i in range(len(bnodes) - 1): distance = distance_point_line(bnodes[i], bnodes[i + 1], poi_node) if distance < min_dist: min_dist = distance return min_dist
def douglas_peucker(way_segment, tolerance): """ Performes the Douglas Peucker line generalization algorithm for a given way segment @param way_segment: List of L{geo.osm_import.Node} objects that represent the way segment @param tolerance: The tolerance value for the generlization in meters @return: A list of L{geo.osm_import.Node} objects that represents the generalized way segment @rtype: C{list} of L{geo.osm_import.Node} @see: the algorithm is adapted from the following public domain sources: - U{http://www.cse.hut.fi/en/research/SVG/TRAKLA2/exercises/DouglasPeucker-212.html} - U{http://www.mappinghacks.com/code/PolyLineReduction/} - U{http://mappinghacks.com/code/dp.py.txt} """ # the algorithm is adapted from: # http://www.cse.hut.fi/en/research/SVG/TRAKLA2/exercises/DouglasPeucker-212.html # http://www.mappinghacks.com/code/PolyLineReduction/ # http://mappinghacks.com/code/dp.py.txt new_way = [] stack = [] anchor = 0 floater = len(way_segment)-1 new_way.append(way_segment[anchor]) stack.append(floater) while stack: max_distance = 0.0 farthest = floater for i in range(anchor + 1, floater): distance = distance_point_line(way_segment[anchor], way_segment[floater], way_segment[i]) if distance > max_distance: max_distance = distance farthest = i if max_distance < tolerance: new_way.append(way_segment[stack.pop()]) anchor = floater if stack: floater = stack[-1] else: floater = farthest stack.append(floater) return new_way