Exemplo n.º 1
0
    def _colorMapBasic(self, ds):

        # contour colormap
        if ds.custom["c_basicCustomRange"]:
            zMin = ds.custom["c_basicCustomRangeMin"]
            zMax = ds.custom["c_basicCustomRangeMax"]
        else:
            zMin, zMax = ds.value_range()

        qcm = ds.custom["c_basicRamp"]
        if not qcm:
            return  # something went wrong (e.g. user selected "new color ramp...")

        # if the color ramp is a gradient, we will use the defined stops
        # otherwise (unknown type of color ramp) we will just take few samples

        isGradient = isinstance(qcm, QgsVectorGradientColorRampV2)

        items = []
        count = qcm.count() if isGradient else 5
        for i in range(count):
            if isGradient:
                if i == 0: v, c = 0.0, qcm.color1()
                elif i == count - 1: v, c = 1.0, qcm.color2()
                else: v, c = gradientColorRampStop(qcm, i - 1)
            else:
                v = i / float(count - 1)
                c = qcm.color(v)
            vv = zMin + v * (zMax - zMin)
            items.append((vv, [c.red(), c.green(), c.blue()], '%.3f' % vv))

        cm = crayfish.ColorMap()
        cm.set_items(items)

        return cm
Exemplo n.º 2
0
    def export_contours(self, output, mupp, useLines, interval=-1, proj4wkt=""):
        cm = None
        if interval == -1:
            zMin, zMax = output.z_range()
            cm = crayfish.ColorMap(zMin, zMax) # default color map

        tmpdir = tmp_dir()
        renderedFile = os.path.join(tmpdir, "4quads.shp")
        res = output.export_contours(mupp, interval, renderedFile, proj4wkt, useLines, cm)
        self.assertTrue(res)
        return renderedFile
Exemplo n.º 3
0
    def initCustomValues(self, ds):
        """ set defaults for data source """
        print "INIT CUSTOM ", ds
        self.cached_ds.add(ds)

        # make child datasets (maximums) share the configuration with parent
        parent_ds = self.parentDataSet(ds)
        if parent_ds:
            ds.config = parent_ds.config
            ds.custom = parent_ds.custom
            # maybe also increase range?
            return

        minZ, maxZ = ds.value_range()
        ds.config = {
            "c_colormap": None,  # will be assigned in updateColorMap() call
            "v_shaft_length_method": 0,  # MinMax
            "v_shaft_length_min": 3,
            "v_shaft_length_max": 40,
            "v_shaft_length_scale": 10,
            "v_shaft_length_fixed": 10,
            "v_pen_width": 1,
            "v_head_width": 15,
            "v_head_length": 40,
            "v_grid": False,
            "v_grid_x": 10,
            "v_grid_y": 10,
            "v_filter_min": -1,
            "v_filter_max": -1,
            "v_color": (0, 0, 0, 255)  # black
        }
        ds.custom = {
            "c_basic": True,
            "c_basicCustomRange": False,
            "c_basicCustomRangeMin": minZ,
            "c_basicCustomRangeMax": maxZ,
            "c_basicName": "[default]",
            "c_basicRamp": defaultColorRamp(),
            "c_alpha": 255,
            "c_advancedColorMap": crayfish.ColorMap(minZ, maxZ)
        }
        self.updateColorMap(
            ds)  # make sure to apply the settings to form a color map
Exemplo n.º 4
0
    def readColorMapXml(self, elem):

        cmElem = elem.firstChildElement("colormap")
        if cmElem.isNull():
            return
        cm = crayfish.ColorMap()
        cm.method = crayfish.ColorMap.Discrete if cmElem.attribute(
            "method") == "discrete" else crayfish.ColorMap.Linear
        cm.clip = (cmElem.attribute("clip-low") == "1",
                   cmElem.attribute("clip-high") == "1")
        itemElems = cmElem.elementsByTagName("item")
        items = []
        for i in range(itemElems.length()):
            itemElem = itemElems.item(i).toElement()
            value = qstring2float(itemElem.attribute("value"))
            color = qstring2rgb(itemElem.attribute("color"))
            label = itemElem.attribute("label") if itemElem.hasAttribute(
                "label") else "%.3f" % value
            items.append((value, color, label))
        cm.set_items(items)
        return cm