Beispiel #1
0
    def test_resampling_2(self):

        region = Region()

        region.ewres = 5
        region.nsres = 5
        region.north = 60
        region.south = -20
        region.east = 60
        region.west = -20
        region.adjust(rows=True, cols=True)

        rast = RasterRow(self.name)
        rast.set_region(region)
        rast.open(mode='r')
        """
        [nan, nan, nan, nan, nan, nan, nan, nan]
        [nan, nan, nan, nan, nan, nan, nan, nan]
        [nan, nan, 11.0, 21.0, 31.0, 41.0, nan, nan]
        [nan, nan, 12.0, 22.0, 32.0, 42.0, nan, nan]
        [nan, nan, 13.0, 23.0, 33.0, 43.0, nan, nan]
        [nan, nan, 14.0, 24.0, 34.0, 44.0, nan, nan]
        [nan, nan, nan, nan, nan, nan, nan, nan]
        [nan, nan, nan, nan, nan, nan, nan, nan]
        """

        six.assertCountEqual(self, rast[2].tolist()[2:6], [11., 21., 31., 41.])
        six.assertCountEqual(self, rast[5].tolist()[2:6], [14., 24., 34., 44.])

        rast.close()
    def test_resampling_2(self):
        
        region = Region()
        
        region.ewres = 5
        region.nsres = 5
        region.north = 60
        region.south = -20
        region.east = 60
        region.west = -20
        region.adjust(rows=True, cols=True)
        
        rast = RasterRow(self.name)
        rast.set_region(region)
        rast.open(mode='r')
        
        """
        [nan, nan, nan, nan, nan, nan, nan, nan]
        [nan, nan, nan, nan, nan, nan, nan, nan]
        [nan, nan, 11.0, 21.0, 31.0, 41.0, nan, nan]
        [nan, nan, 12.0, 22.0, 32.0, 42.0, nan, nan]
        [nan, nan, 13.0, 23.0, 33.0, 43.0, nan, nan]
        [nan, nan, 14.0, 24.0, 34.0, 44.0, nan, nan]
        [nan, nan, nan, nan, nan, nan, nan, nan]
        [nan, nan, nan, nan, nan, nan, nan, nan]
        """

        self.assertItemsEqual(rast[2].tolist()[2:6], [11.,21.,31.,41.])        
        self.assertItemsEqual(rast[5].tolist()[2:6], [14.,24.,34.,44.])
        
        rast.close()
Beispiel #3
0
def worker(cmd):

    window, src = cmd
    
    reg = Region()
    old_reg = deepcopy(reg)
    
    try:
        # update region
        reg.north = dict(window)['north']
        reg.south = dict(window)['south']
        reg.west = dict(window)['west']
        reg.east = dict(window)['east']
        reg.set_current()
        reg.write()
        reg.set_raster_region()
        
        # read raster data
        with RasterRow(src) as rs:
            arr = np.asarray(rs)
    except:
        pass

    finally:
        # reset region
        old_reg.write()
        reg.set_raster_region()
    
    return(arr)
Beispiel #4
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)
Beispiel #5
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)
 def test_resampling_1(self):
     
     region = Region()
     
     region.ewres = 4
     region.nsres = 4
     region.north = 30
     region.south = 10
     region.east = 30
     region.west = 10
     region.adjust(rows=True, cols=True)
     
     rast = RasterRow(self.name)
     rast.set_region(region)
     rast.open(mode='r')
     
     self.assertItemsEqual(rast[0].tolist(), [22,22,22,22,22,32,32,32,32,32])        
     self.assertItemsEqual(rast[5].tolist(), [23,23,23,23,23,33,33,33,33,33])
     
     rast.close()
 def test_resampling_1(self):
     
     region = Region()
     
     region.ewres = 4
     region.nsres = 4
     region.north = 30
     region.south = 10
     region.east = 30
     region.west = 10
     region.adjust(rows=True, cols=True)
     
     rast = RasterRow(self.name)
     rast.set_region(region)
     rast.open(mode='r')
     
     self.assertItemsEqual(rast[0].tolist(), [22, 22, 22, 22, 22, 32, 32, 32, 32, 32])
     self.assertItemsEqual(rast[5].tolist(), [23, 23, 23, 23, 23, 33, 33, 33, 33, 33])
     
     rast.close()