How to create a single raster based on the values of three rasters (Conditional)?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















I have three rasters of soil granulometric fractions (clay, sand and silt), all in %. I want to make a single raster of the soil texture classes. For that, I need to make some conditionals (i. e.: when sand > 90 and clay < 10, so the class in the new raster must have the value 1).



Any suggestion? I'm using Arcgis 10.6.










share|improve this question
























  • Do they have the same extent and resolution?

    – BERA
    Feb 15 at 12:55






  • 1





    Did you take a look at the raster calculator of arcgis ?

    – nmatton
    Feb 15 at 12:58











  • @BERA yes. All the rasters hava the same resolution.

    – Diêgo Araújo
    Feb 15 at 13:00















1















I have three rasters of soil granulometric fractions (clay, sand and silt), all in %. I want to make a single raster of the soil texture classes. For that, I need to make some conditionals (i. e.: when sand > 90 and clay < 10, so the class in the new raster must have the value 1).



Any suggestion? I'm using Arcgis 10.6.










share|improve this question
























  • Do they have the same extent and resolution?

    – BERA
    Feb 15 at 12:55






  • 1





    Did you take a look at the raster calculator of arcgis ?

    – nmatton
    Feb 15 at 12:58











  • @BERA yes. All the rasters hava the same resolution.

    – Diêgo Araújo
    Feb 15 at 13:00













1












1








1








I have three rasters of soil granulometric fractions (clay, sand and silt), all in %. I want to make a single raster of the soil texture classes. For that, I need to make some conditionals (i. e.: when sand > 90 and clay < 10, so the class in the new raster must have the value 1).



Any suggestion? I'm using Arcgis 10.6.










share|improve this question
















I have three rasters of soil granulometric fractions (clay, sand and silt), all in %. I want to make a single raster of the soil texture classes. For that, I need to make some conditionals (i. e.: when sand > 90 and clay < 10, so the class in the new raster must have the value 1).



Any suggestion? I'm using Arcgis 10.6.







arcgis-desktop spatial-analyst raster-calculator arcgis-10.6 conditional






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 15 at 12:45









PolyGeo

53.6k1781243




53.6k1781243










asked Feb 15 at 11:20









Diêgo AraújoDiêgo Araújo

62




62












  • Do they have the same extent and resolution?

    – BERA
    Feb 15 at 12:55






  • 1





    Did you take a look at the raster calculator of arcgis ?

    – nmatton
    Feb 15 at 12:58











  • @BERA yes. All the rasters hava the same resolution.

    – Diêgo Araújo
    Feb 15 at 13:00

















  • Do they have the same extent and resolution?

    – BERA
    Feb 15 at 12:55






  • 1





    Did you take a look at the raster calculator of arcgis ?

    – nmatton
    Feb 15 at 12:58











  • @BERA yes. All the rasters hava the same resolution.

    – Diêgo Araújo
    Feb 15 at 13:00
















Do they have the same extent and resolution?

– BERA
Feb 15 at 12:55





Do they have the same extent and resolution?

– BERA
Feb 15 at 12:55




1




1





Did you take a look at the raster calculator of arcgis ?

– nmatton
Feb 15 at 12:58





Did you take a look at the raster calculator of arcgis ?

– nmatton
Feb 15 at 12:58













@BERA yes. All the rasters hava the same resolution.

– Diêgo Araújo
Feb 15 at 13:00





@BERA yes. All the rasters hava the same resolution.

– Diêgo Araújo
Feb 15 at 13:00










2 Answers
2






active

oldest

votes


















3














Try converting your rasters to numpy arrays, build a classifying function and convert resulting Array back to raster. (This way you dont need Spatial Analyst extension)



Example with two random rasters with values from 0-1. Modify the function etc:



import numpy as np
import arcpy

raster1 = "randraster_1" #Change
raster2 = "randraster_2" #Change
output_raster = r'C:Default.gdbresultraster123' #Change

arr1 = arcpy.RasterToNumPyArray(raster1)
arr2 = arcpy.RasterToNumPyArray(raster2)

def whatsoil(a,b):
if a>b:
return 1
elif a<b:
return 2
else:
return 3
vwhatsoil = np.vectorize(whatsoil)

arr3 = vwhatsoil(arr1, arr2)

desc = arcpy.Describe(raster1+r'/Band_1')
arcpy.env.outputCoordinateSystem = desc.spatialReference

resultraster = arcpy.NumPyArrayToRaster(in_array=arr3, lower_left_corner=desc.extent.lowerLeft, x_cell_size=desc.meanCellHeight, y_cell_size=desc.meanCellWidth)
resultraster.save(output_raster)


enter image description here






share|improve this answer

























  • if you're using numpy, you'll likely get much better performance with numpy.where over your whatsoil function

    – Paul H
    Feb 15 at 17:59












  • Ok! I did not know how to do it with 3 input arrays and many if elses so i used a function instead

    – BERA
    Feb 15 at 18:01







  • 1





    You should be able to numpy.where(a > b, 1, numpy.where(a < b, 2, 3)). numpy.select works in this case too.

    – Paul H
    Feb 15 at 23:13


















2














you can also use the raster calculator, but it quickly creates long statement



Map algebra > raster calculator, for example :




Con(("sand" > 90) and ("clay" <10 ), 1, Con(("silt">50) and
("clay"<30),2,3)




The syntax is Con (condition, value if true, value if false)






share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312357%2fhow-to-create-a-single-raster-based-on-the-values-of-three-rasters-conditional%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Try converting your rasters to numpy arrays, build a classifying function and convert resulting Array back to raster. (This way you dont need Spatial Analyst extension)



    Example with two random rasters with values from 0-1. Modify the function etc:



    import numpy as np
    import arcpy

    raster1 = "randraster_1" #Change
    raster2 = "randraster_2" #Change
    output_raster = r'C:Default.gdbresultraster123' #Change

    arr1 = arcpy.RasterToNumPyArray(raster1)
    arr2 = arcpy.RasterToNumPyArray(raster2)

    def whatsoil(a,b):
    if a>b:
    return 1
    elif a<b:
    return 2
    else:
    return 3
    vwhatsoil = np.vectorize(whatsoil)

    arr3 = vwhatsoil(arr1, arr2)

    desc = arcpy.Describe(raster1+r'/Band_1')
    arcpy.env.outputCoordinateSystem = desc.spatialReference

    resultraster = arcpy.NumPyArrayToRaster(in_array=arr3, lower_left_corner=desc.extent.lowerLeft, x_cell_size=desc.meanCellHeight, y_cell_size=desc.meanCellWidth)
    resultraster.save(output_raster)


    enter image description here






    share|improve this answer

























    • if you're using numpy, you'll likely get much better performance with numpy.where over your whatsoil function

      – Paul H
      Feb 15 at 17:59












    • Ok! I did not know how to do it with 3 input arrays and many if elses so i used a function instead

      – BERA
      Feb 15 at 18:01







    • 1





      You should be able to numpy.where(a > b, 1, numpy.where(a < b, 2, 3)). numpy.select works in this case too.

      – Paul H
      Feb 15 at 23:13















    3














    Try converting your rasters to numpy arrays, build a classifying function and convert resulting Array back to raster. (This way you dont need Spatial Analyst extension)



    Example with two random rasters with values from 0-1. Modify the function etc:



    import numpy as np
    import arcpy

    raster1 = "randraster_1" #Change
    raster2 = "randraster_2" #Change
    output_raster = r'C:Default.gdbresultraster123' #Change

    arr1 = arcpy.RasterToNumPyArray(raster1)
    arr2 = arcpy.RasterToNumPyArray(raster2)

    def whatsoil(a,b):
    if a>b:
    return 1
    elif a<b:
    return 2
    else:
    return 3
    vwhatsoil = np.vectorize(whatsoil)

    arr3 = vwhatsoil(arr1, arr2)

    desc = arcpy.Describe(raster1+r'/Band_1')
    arcpy.env.outputCoordinateSystem = desc.spatialReference

    resultraster = arcpy.NumPyArrayToRaster(in_array=arr3, lower_left_corner=desc.extent.lowerLeft, x_cell_size=desc.meanCellHeight, y_cell_size=desc.meanCellWidth)
    resultraster.save(output_raster)


    enter image description here






    share|improve this answer

























    • if you're using numpy, you'll likely get much better performance with numpy.where over your whatsoil function

      – Paul H
      Feb 15 at 17:59












    • Ok! I did not know how to do it with 3 input arrays and many if elses so i used a function instead

      – BERA
      Feb 15 at 18:01







    • 1





      You should be able to numpy.where(a > b, 1, numpy.where(a < b, 2, 3)). numpy.select works in this case too.

      – Paul H
      Feb 15 at 23:13













    3












    3








    3







    Try converting your rasters to numpy arrays, build a classifying function and convert resulting Array back to raster. (This way you dont need Spatial Analyst extension)



    Example with two random rasters with values from 0-1. Modify the function etc:



    import numpy as np
    import arcpy

    raster1 = "randraster_1" #Change
    raster2 = "randraster_2" #Change
    output_raster = r'C:Default.gdbresultraster123' #Change

    arr1 = arcpy.RasterToNumPyArray(raster1)
    arr2 = arcpy.RasterToNumPyArray(raster2)

    def whatsoil(a,b):
    if a>b:
    return 1
    elif a<b:
    return 2
    else:
    return 3
    vwhatsoil = np.vectorize(whatsoil)

    arr3 = vwhatsoil(arr1, arr2)

    desc = arcpy.Describe(raster1+r'/Band_1')
    arcpy.env.outputCoordinateSystem = desc.spatialReference

    resultraster = arcpy.NumPyArrayToRaster(in_array=arr3, lower_left_corner=desc.extent.lowerLeft, x_cell_size=desc.meanCellHeight, y_cell_size=desc.meanCellWidth)
    resultraster.save(output_raster)


    enter image description here






    share|improve this answer















    Try converting your rasters to numpy arrays, build a classifying function and convert resulting Array back to raster. (This way you dont need Spatial Analyst extension)



    Example with two random rasters with values from 0-1. Modify the function etc:



    import numpy as np
    import arcpy

    raster1 = "randraster_1" #Change
    raster2 = "randraster_2" #Change
    output_raster = r'C:Default.gdbresultraster123' #Change

    arr1 = arcpy.RasterToNumPyArray(raster1)
    arr2 = arcpy.RasterToNumPyArray(raster2)

    def whatsoil(a,b):
    if a>b:
    return 1
    elif a<b:
    return 2
    else:
    return 3
    vwhatsoil = np.vectorize(whatsoil)

    arr3 = vwhatsoil(arr1, arr2)

    desc = arcpy.Describe(raster1+r'/Band_1')
    arcpy.env.outputCoordinateSystem = desc.spatialReference

    resultraster = arcpy.NumPyArrayToRaster(in_array=arr3, lower_left_corner=desc.extent.lowerLeft, x_cell_size=desc.meanCellHeight, y_cell_size=desc.meanCellWidth)
    resultraster.save(output_raster)


    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 15 at 13:55

























    answered Feb 15 at 13:18









    BERABERA

    16.5k52043




    16.5k52043












    • if you're using numpy, you'll likely get much better performance with numpy.where over your whatsoil function

      – Paul H
      Feb 15 at 17:59












    • Ok! I did not know how to do it with 3 input arrays and many if elses so i used a function instead

      – BERA
      Feb 15 at 18:01







    • 1





      You should be able to numpy.where(a > b, 1, numpy.where(a < b, 2, 3)). numpy.select works in this case too.

      – Paul H
      Feb 15 at 23:13

















    • if you're using numpy, you'll likely get much better performance with numpy.where over your whatsoil function

      – Paul H
      Feb 15 at 17:59












    • Ok! I did not know how to do it with 3 input arrays and many if elses so i used a function instead

      – BERA
      Feb 15 at 18:01







    • 1





      You should be able to numpy.where(a > b, 1, numpy.where(a < b, 2, 3)). numpy.select works in this case too.

      – Paul H
      Feb 15 at 23:13
















    if you're using numpy, you'll likely get much better performance with numpy.where over your whatsoil function

    – Paul H
    Feb 15 at 17:59






    if you're using numpy, you'll likely get much better performance with numpy.where over your whatsoil function

    – Paul H
    Feb 15 at 17:59














    Ok! I did not know how to do it with 3 input arrays and many if elses so i used a function instead

    – BERA
    Feb 15 at 18:01






    Ok! I did not know how to do it with 3 input arrays and many if elses so i used a function instead

    – BERA
    Feb 15 at 18:01





    1




    1





    You should be able to numpy.where(a > b, 1, numpy.where(a < b, 2, 3)). numpy.select works in this case too.

    – Paul H
    Feb 15 at 23:13





    You should be able to numpy.where(a > b, 1, numpy.where(a < b, 2, 3)). numpy.select works in this case too.

    – Paul H
    Feb 15 at 23:13













    2














    you can also use the raster calculator, but it quickly creates long statement



    Map algebra > raster calculator, for example :




    Con(("sand" > 90) and ("clay" <10 ), 1, Con(("silt">50) and
    ("clay"<30),2,3)




    The syntax is Con (condition, value if true, value if false)






    share|improve this answer



























      2














      you can also use the raster calculator, but it quickly creates long statement



      Map algebra > raster calculator, for example :




      Con(("sand" > 90) and ("clay" <10 ), 1, Con(("silt">50) and
      ("clay"<30),2,3)




      The syntax is Con (condition, value if true, value if false)






      share|improve this answer

























        2












        2








        2







        you can also use the raster calculator, but it quickly creates long statement



        Map algebra > raster calculator, for example :




        Con(("sand" > 90) and ("clay" <10 ), 1, Con(("silt">50) and
        ("clay"<30),2,3)




        The syntax is Con (condition, value if true, value if false)






        share|improve this answer













        you can also use the raster calculator, but it quickly creates long statement



        Map algebra > raster calculator, for example :




        Con(("sand" > 90) and ("clay" <10 ), 1, Con(("silt">50) and
        ("clay"<30),2,3)




        The syntax is Con (condition, value if true, value if false)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 15 at 14:14









        radouxjuradouxju

        40.8k143119




        40.8k143119



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312357%2fhow-to-create-a-single-raster-based-on-the-values-of-three-rasters-conditional%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?