Method to change values in raster with certain conditions in Python (QGIS)

by Lauzeruz   Last Updated September 11, 2019 10:22 AM

I'm creating a plugin which changes the temperature on a map based on a new land use value. For this I created a Dataframe with these temperature changes. For the indexes of the rows I have a raster layer with new land use values from 1-10 and for the columns I have the old land uses with values 1-4. I know I can use these as conditions but I am not completely sure how to use these. Here is the Dataframe:

import pandas as pd

 df = pd.DataFrame(columns=[2, 1, 3, 4],#(2)Green areas, (1)Buildings, (3)Paved Environments and (4)Wet land uses
        index=list(range(1, 11)))
        #(1-10) = 'Trees on grass', 'Trees on avenue', 'Grass field', 'Green roofs', 'Cool roofs',
                        #'Facade greening', 'Solar Panels', 'Pond/river', 'Fountain', 'Surface albedo change'

        df.loc[1] = pd.Series({2: -0.65, 1: -1.65, 3: -1.65, 4: -0.75})
        df.loc[2] = pd.Series({2: 0, 1: -1, 3: -1, 4: -0.1})
        df.loc[3] = pd.Series({2: 0, 1: -1, 3: -1, 4: -0.1})
        df.loc[4] = pd.Series({2: 0.48, 1: -0.52, 3: -0.52, 4: 0.38})
        df.loc[5] = pd.Series({2: 0.48, 1: -0.52, 3: -0.52, 4: 0.38})
        df.loc[6] = pd.Series({2: 0.7, 1: -0.3, 3: -0.3, 4: 0.6})
        df.loc[7] = pd.Series({2: 1, 1: 0, 3: 0, 4: 0.9})
        df.loc[8] = pd.Series({2: 0.1, 1: -0.9, 3: -0.9, 4: 0})
        df.loc[9] = pd.Series({2: -2.0, 1: -3.0, 3: -3.0, 4: -2.1})
        df.loc[10] = pd.Series({2: 0.4, 1: -0.6, 3: -0.6, 4: 0.3})

Does someone have a method to extract the values of the old and new land use layer and use them as indexes for this Dataframe and than store this value in a new raster map. This new raster map can than be used in a Raster Calculator to create a new temperature map. Which method would be most suited for this?



Related Questions



QgisPlugin_Faculty

Updated March 19, 2019 12:22 PM


India map on QGIS canvas using PyQgis

Updated August 06, 2019 09:22 AM

PyQGIS: QgsExpression.evaluate() is deprecated

Updated June 03, 2017 20:22 PM