Esempio n. 1
0
def _get_raster_image_as_np(lock, conn, data):
    """Convert a raster map into an image and return
    a numpy array with RGB or Gray values.

    :param lock: A multiprocessing.Lock instance
    :param conn: A multiprocessing.Pipe instance used to send True or False
    :param data: The list of data entries [function_id, raster_name, extent, color]
    """
    array = None
    try:
        name = data[1]
        mapset = data[2]
        extent = data[3]
        color = data[4]

        mapset = utils.get_mapset_raster(name, mapset)

        if not mapset:
            raise ValueError("Unable to find raster map <%s>" % (name))

        rast = RasterRow(name, mapset)

        if rast.exist():

            reg = Region()
            reg.from_rast(name)

            if extent is not None:
                if "north" in extent:
                    reg.north = extent["north"]
                if "south" in extent:
                    reg.south = extent["south"]
                if "east" in extent:
                    reg.east = extent["east"]
                if "west" in extent:
                    reg.west = extent["west"]
                if "rows" in extent:
                    reg.rows = extent["rows"]
                if "cols" in extent:
                    reg.cols = extent["cols"]
                reg.adjust()

            array = raster2numpy_img(name, reg, color)
    except:
        raise
    finally:
        conn.send(array)
Esempio n. 2
0
def _get_raster_image_as_np(lock, conn, data):
    """Convert a raster map into an image and return
       a numpy array with RGB or Gray values.

       :param lock: A multiprocessing.Lock instance
       :param conn: A multiprocessing.Pipe instance used to send True or False
       :param data: The list of data entries [function_id, raster_name, extent, color]
    """
    array = None
    try:
        name = data[1]
        mapset = data[2]
        extent = data[3]
        color = data[4]

        mapset = utils.get_mapset_raster(name, mapset)

        if not mapset:
            raise ValueError("Unable to find raster map <%s>"%(name))

        rast = RasterRow(name, mapset)

        if rast.exist():

            reg = Region()
            reg.from_rast(name)

            if extent is not None:
                if "north" in extent:
                    reg.north = extent["north"]
                if "south" in extent:
                    reg.south = extent["south"]
                if "east" in extent:
                    reg.east =  extent["east"]
                if "west" in extent:
                    reg.west =  extent["west"]
                if "rows" in extent:
                    reg.rows =  extent["rows"]
                if "cols" in extent:
                    reg.cols =  extent["cols"]
                reg.adjust()

            array = raster2numpy_img(name, reg, color)
    except:
        raise
    finally:
        conn.send(array)
Esempio n. 3
0
    def test_resampling_to_QImg_1(self):

        region = Region()
        region.from_rast(self.name)
        region.cols = 320
        region.rows = 240
        region.adjust()

        tmpfile = tempfile(False)
        tmpfile = tmpfile + ".png"

        a = raster2numpy_img(self.name, region)

        image = QImage(a.data, region.cols, region.rows, QImage.Format_ARGB32)
        # image.save("data/a.png")
        image.save(tmpfile)
        self.assertFilesEqualMd5(tmpfile, "data/a.png")
Esempio n. 4
0
    def test_resampling_to_QImg_1(self):

        region = Region()
        region.from_rast(self.name)
        region.cols = 320
        region.rows = 240
        region.adjust()

        tmpfile = tempfile(False)
        tmpfile = tmpfile + ".png"

        a = raster2numpy_img(self.name, region)

        image = QImage(a.data, region.cols, region.rows,
                       QImage.Format_ARGB32)
        #image.save("data/a.png")
        image.save(tmpfile)
        self.assertFilesEqualMd5(tmpfile, "data/a.png")
Esempio n. 5
0
    def test_resampling_to_QImg_4(self):

        region = Region()
        region.from_rast(self.name)
        region.cols = 400
        region.rows = 300
        region.adjust()

        tmpfile = tempfile(False)
        tmpfile = tmpfile + ".png"

        array = raster2numpy_img(rastname=self.name, region=region,
                                 color="RGB")

        image = QImage(array.data,
                       region.cols, region.rows, QImage.Format_RGB32)
        #image.save("data/e.png")
        image.save(tmpfile)
        self.assertFilesEqualMd5(tmpfile, "data/e.png")
Esempio n. 6
0
    def test_resampling_to_QImg_large(self):

        region = Region()
        region.from_rast(self.name)
        region.cols = 4000
        region.rows = 3000
        region.adjust()

        tmpfile = tempfile(False)
        tmpfile = tmpfile + ".png"

        # With array as argument
        array = np.ndarray((region.rows*region.cols*4), np.uint8)

        raster2numpy_img(rastname=self.name, region=region,
                         color="ARGB", array=array)

        image = QImage(array.data,
                       region.cols, region.rows, QImage.Format_ARGB32)
        #image.save("data/c.png")
        image.save(tmpfile)
        self.assertFilesEqualMd5(tmpfile, "data/c.png")