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)
            spoly = MultiPolygon(sea)
            sbbox = spoly.bbox()
            sbbox.inflate(sbbox.width * bnds['padding'])
            return bbox_to_polygon(sbbox)

        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'])
        return bbox_to_polygon(bbox)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    def generate(self, opts, outfile=None, preview=True):
        """
        generates svg map
        """
        parse_options(opts)
        self._verbose = 'verbose' in opts and opts['verbose']
        self.prepare_layers(opts)

        proj = self.get_projection(opts)
        bounds_poly = self.get_bounds(opts, proj)
        bbox = bounds_poly.bbox()

        view = self.get_view(opts, bbox)
        w = view.width
        h = view.height
        view_poly = MultiPolygon([[(0, 0), (0, h), (w, h), (w, 0)]])
        # view_poly = bounds_poly.project_view(view)

        svg = self.init_svg_canvas(opts, proj, view, bbox)

        layers = []
        layerOpts = {}
        layerFeatures = {}

        # get features
        for layer in opts['layers']:
            id = layer['id']
            layerOpts[id] = layer
            layers.append(id)
            features = self.get_features(layer, proj, view, opts, view_poly)
            layerFeatures[id] = features

        self.join_layers(layers, layerOpts, layerFeatures)
        self.simplify_layers(layers, layerFeatures, layerOpts)
        self.crop_layers_to_view(layers, layerFeatures, view_poly)
        self.crop_layers(layers, layerOpts, layerFeatures)
        self.substract_layers(layers, layerOpts, layerFeatures)
        self.store_layers_svg(layers, layerOpts, layerFeatures, svg, opts)

        if outfile is None:
            if preview:
                svg.preview()
            else:
                return svg.tostring()
        else:
            svg.save(outfile)