def _init_bounds(self): """ ### Initialize bounding polygons and bounding box ### Compute the projected bounding box """ from geometry.utils import bbox_to_polygon opts = self.options proj = self.proj mode = opts['bounds']['mode'][:] data = opts['bounds']['data'] if 'padding' not in opts['bounds']: padding = 0 else: padding = opts['bounds']['padding'] # If the bound mode is set to *bbox* we simply project # a rectangle in lat/lon coordinates. if mode == "bbox": # catch special case bbox sea = proj.bounding_geometry(data, projected=True) sbbox = geom_to_bbox(sea) sbbox.inflate(sbbox.width * padding) return bbox_to_polygon(sbbox) bbox = BBox() # If the bound mode is set to *points* we project all # points and compute the bounding box. if mode[:5] == "point": ubbox = BBox() for lon, lat in data: pt = proj.project(lon, lat) bbox.update(pt) ubbox.update((lon, lat)) self._unprojected_bounds = ubbox # In bound mode *polygons*, which should correctly be # named gemetry, we compute the bounding boxes of every # geometry. if mode[:4] == "poly": features = self._get_bounding_geometry() ubbox = BBox() if len(features) > 0: for feature in features: ubbox.join(geom_to_bbox(feature.geometry)) feature.project(proj) fbbox = geom_to_bbox(feature.geometry, data["min-area"]) bbox.join(fbbox) # Save the unprojected bounding box for later to # determine what features can be skipped. ubbox.inflate(ubbox.width * padding) self._unprojected_bounds = ubbox else: raise KartographError('no features found for calculating the map bounds') # If we need some extra geometry around the map bounds, we inflate # the bbox according to the set *padding*. bbox.inflate(bbox.width * padding) # At the end we convert the bounding box to a Polygon because # we need it for clipping tasks. return bbox_to_polygon(bbox)
def get_bounds(self, opts, proj): """ computes the (x,y) bounding box for the map, given a specific projection """ from geometry.utils import bbox_to_polygon bnds = opts['bounds'] mode = bnds['mode'][:] data = bnds['data'] if mode == "bbox": # catch special case bbox sea = proj.sea_shape(data) return MultiPolygon(sea) bbox = BBox() if mode == "points": for lon, lat in data: pt = proj.project(lon, lat) bbox.update(pt) if mode == "polygons": features = self.get_bounds_polygons(opts) for feature in features: fbbox = feature.geom.project(proj).bbox(data["min-area"]) bbox.join(fbbox) bbox.inflate(bbox.width * bnds['padding']) print bbox return bbox_to_polygon(bbox)
def get_bounds(self, opts, proj): """ computes the (x,y) bounding box for the map, given a specific projection """ from geometry.utils import bbox_to_polygon bnds = opts['bounds'] mode = bnds['mode'][:] data = bnds['data'] if self._verbose: print 'bounds mode', mode if mode == "bbox": # catch special case bbox sea = proj.sea_shape(data) spoly = MultiPolygon(sea) sbbox = spoly.bbox() sbbox.inflate(sbbox.width * bnds['padding']) return bbox_to_polygon(sbbox) bbox = BBox() if mode[:5] == "point": for lon, lat in data: pt = proj.project(lon, lat) bbox.update(pt) if mode[:4] == "poly": features = self.get_bounds_polygons(opts) if len(features) > 0: for feature in features: fbbox = feature.geom.project(proj).bbox(data["min-area"]) bbox.join(fbbox) else: raise KartographError( 'no features found for calculating the map bounds') bbox.inflate(bbox.width * bnds['padding']) return bbox_to_polygon(bbox)
def get_bounds(self, opts, proj): """ computes the (x,y) bounding box for the map, given a specific projection """ from geometry.utils import bbox_to_polygon bnds = opts['bounds'] mode = bnds['mode'][:] data = bnds['data'] if self._verbose: print 'bounds mode', mode if mode == "bbox": # catch special case bbox sea = proj.sea_shape(data) spoly = MultiPolygon(sea) sbbox = spoly.bbox() sbbox.inflate(sbbox.width * bnds['padding']) return bbox_to_polygon(sbbox) bbox = BBox() if mode[:5] == "point": for lon, lat in data: pt = proj.project(lon, lat) bbox.update(pt) if mode[:4] == "poly": features = self.get_bounds_polygons(opts) if len(features) > 0: for feature in features: fbbox = feature.geom.project(proj).bbox(data["min-area"]) bbox.join(fbbox) else: raise KartographError('no features found for calculating the map bounds') bbox.inflate(bbox.width * bnds['padding']) return bbox_to_polygon(bbox)