def __contains_point_geo_bad(self, point): """ DO NOT USE Interface to using the shapely polygon.contains. Gives different results to polygon is_inside_polygon. What's more it seems to be wrong. Alot of code in this function that is going down the wrong track. """ #f = self.y if True: # This gives the wrong answer, and it is slow. poly = polygon_to_geos_polygon(self._linestring) if not poly.contains(Point(point)): return False else: outline = not self.outline_geos_polygon.contains(Point(point)) poly = polygon_to_geos_polygon(self._linestring) brute = not poly.contains(Point(point)) if not outline == brute: # This doesn't happen print "(self._linestring", self._linestring print "self.outline_geos_polygon", self.outline_geos_polygon import sys sys.exit() if outline: return False if False: # This doesn't work try: if not self.outline_geos_polygon.contains(Point(point)): return False except: self.outline_geos_polygon = polygon_to_geos_polygon( self._linestring) outline = not self.outline_geos_polygon.contains(Point(point)) poly = polygon_to_geos_polygon(self._linestring) if not self.outline_geos_polygon.contains(Point(point)): return False for exclusion_zone in self._exclude: exclude_polygon = polygon_to_geos_polygon(exclusion_zone) if exclude_polygon.contains(Point(point)): return False return True
def __init__(self, linestring, exclude=None, area=None): """ linestring : main polygon exclude : polygons that are excluded from the main polygon Both linestring and exlude must be Simple polygons. They must be a sequence of points. The first point must be repeated as the last point. area : geodesic area of the polygon (different to the flat-earth area) """ # print "linestring", linestring linestring = [tuple(line) for line in linestring] # print "linestring", linestring if exclude is None: exclude = [] exclude = [[tuple(line) for line in ex] for ex in exclude] self._linestring = linestring self._exclude = exclude self.geos_polygon = polygon_to_geos_polygon(linestring) if not self.geos_polygon.is_valid: raise InvalidPolygonError(linestring) # These do not work #self.outline_geos_polygon = copy.deepcopy(self.geos_polygon) self.outline_geos_polygon = polygon_to_geos_polygon(linestring) #self.outline_geos_polygon = None for exclusion_zone in exclude: exclude_polygon = polygon_to_geos_polygon(exclusion_zone) # Checking valid exclude if not exclude_polygon.is_valid: raise InvalidPolygonError(exclusion_zone) # Main = Main - exclude self.geos_polygon = self.geos_polygon.difference(exclude_polygon) self._precomputed_points = {} self._area = area
def __contains_point_geo(self, point): """ DO NOT USE Interface to using the shapely polygon.contains. Gives different results to polygon is_inside_polygon. What's more it seems to be wrong. And it is not very deterministic. Sometimes it is right, sometimes it's wrong, with seemingly the same data. """ # This gives the wrong answer, and it is slow. poly = polygon_to_geos_polygon(self._linestring) if not poly.contains(Point(point)): return False for exclusion_zone in self._exclude: exclude_polygon = polygon_to_geos_polygon(exclusion_zone) if exclude_polygon.contains(Point(point)): return False return True