Subsetting single raster from raster list using ArcPy?For Loop - Map Algebra (ArcGIS) using PythonAdding values in X column to list using ArcPy?Multiply a raster list with a field value list in a FOR loop in ArcPyRaster calculation in for loop returning exit code -1Creating multiple Feature Datasets from table/list using ArcPy?How to use loop to add georeferenced JPEGs from folder to mxd?Creating a list of Rasters from another list of Rasters based on file name?Concatenating list of strings using ArcPy?ArcPy search data from a list of values

How do I feed my black hole?

I don't have the theoretical background in my PhD topic. I can't justify getting the degree

Why is the UK so keen to remove the "backstop" when their leadership seems to think that no border will be needed in Northern Ireland?

about to retire but not retired yet, employed but not working any more

Why is strlen so complex in C?

When, exactly, does the Rogue Scout get to use their Skirmisher ability?

How long do you think advanced cybernetic implants would plausibly last?

LINQ for generating all possible permutations

Can an ISO file damage—or infect—the machine it's being burned on?

Why is a statement like 1 + n *= 3 allowed in Ruby?

What are the occurences of total war in the Native Americans?

Adoption records in 1871 based on census info

Cooking Scrambled Eggs

How to set different form displays for creating and editing an entity?

Given current technology, could TV display screens double as video camera sensors?

Semantic difference between regular and irregular 'backen'

Why can't I access the 'name' of an object when looping through the scene's objects?

What happened to the HDEV ISS Experiment? Is it over?

Is this password scheme legit?

Make utility using LINQ

Billiard balls collision

Did anybody find out it was Anakin who blew up the command center?

Why does Windows store Wi-Fi passwords in a reversible format?

Breaker Mapping Questions



Subsetting single raster from raster list using ArcPy?


For Loop - Map Algebra (ArcGIS) using PythonAdding values in X column to list using ArcPy?Multiply a raster list with a field value list in a FOR loop in ArcPyRaster calculation in for loop returning exit code -1Creating multiple Feature Datasets from table/list using ArcPy?How to use loop to add georeferenced JPEGs from folder to mxd?Creating a list of Rasters from another list of Rasters based on file name?Concatenating list of strings using ArcPy?ArcPy search data from a list of values






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a list of rasters, created by arcpy using ListRasters. Rasters are stored in a geodatabase. How can I subset only one raster of the raster list? The goal is to make a new list, but containing only one raster file.



Ultimate goal is to loop through list of rasters and calculate Area solar radiation for each one of them. But, but for learning/training purposes I wish to explore my parameters only on single raster for now. (I know I can read-in just single raster, but I thought that subsetting might be easy as well?)



I have thought that I can simply subset the element by the index value, but this seems not working in arcpy. Any advices? I think I am missing something very obvious...



import arcpy, os

# Set working environment
arcpy.env.workspace = os.path.join(inWD, "output/bufRastTwins.gdb")

# List all rasters with defined name wildcard: r_1, r_2, r_3.. to r_100
allRasters = arcpy.ListRasters("r_*")

# Select the first raster from the rasters list
myRasters = allRasters[0]
print myRasters


My attempt leads to loop through raster name, not throught the subsetted raster itself:



print myRaster:
r_1 # first element succesfully created

but for raster in myRasters:
print raster # this is obviously wrong

r
_
1









share|improve this question


























  • Hi @BERA, thank you for your comment. I am trying to calculate solar radiation afterwards, but for making a script I wanted to run it simply on one raster. I have completed my question to answer your comment.

    – maycca
    8 hours ago











  • arcpy.ListRasters is only returning a list containing "raster names in the workspace". Extracting the first element of this list is only giving you the first raster name within the specified workspace. With it you can do something like os.path.join(inWD, "output/bufRastTwins.gdb", allRasters[0] to hae the full path plus name of your raster and use this as your input for further analysis.

    – umbe1987
    8 hours ago

















1















I have a list of rasters, created by arcpy using ListRasters. Rasters are stored in a geodatabase. How can I subset only one raster of the raster list? The goal is to make a new list, but containing only one raster file.



Ultimate goal is to loop through list of rasters and calculate Area solar radiation for each one of them. But, but for learning/training purposes I wish to explore my parameters only on single raster for now. (I know I can read-in just single raster, but I thought that subsetting might be easy as well?)



I have thought that I can simply subset the element by the index value, but this seems not working in arcpy. Any advices? I think I am missing something very obvious...



import arcpy, os

# Set working environment
arcpy.env.workspace = os.path.join(inWD, "output/bufRastTwins.gdb")

# List all rasters with defined name wildcard: r_1, r_2, r_3.. to r_100
allRasters = arcpy.ListRasters("r_*")

# Select the first raster from the rasters list
myRasters = allRasters[0]
print myRasters


My attempt leads to loop through raster name, not throught the subsetted raster itself:



print myRaster:
r_1 # first element succesfully created

but for raster in myRasters:
print raster # this is obviously wrong

r
_
1









share|improve this question


























  • Hi @BERA, thank you for your comment. I am trying to calculate solar radiation afterwards, but for making a script I wanted to run it simply on one raster. I have completed my question to answer your comment.

    – maycca
    8 hours ago











  • arcpy.ListRasters is only returning a list containing "raster names in the workspace". Extracting the first element of this list is only giving you the first raster name within the specified workspace. With it you can do something like os.path.join(inWD, "output/bufRastTwins.gdb", allRasters[0] to hae the full path plus name of your raster and use this as your input for further analysis.

    – umbe1987
    8 hours ago













1












1








1








I have a list of rasters, created by arcpy using ListRasters. Rasters are stored in a geodatabase. How can I subset only one raster of the raster list? The goal is to make a new list, but containing only one raster file.



Ultimate goal is to loop through list of rasters and calculate Area solar radiation for each one of them. But, but for learning/training purposes I wish to explore my parameters only on single raster for now. (I know I can read-in just single raster, but I thought that subsetting might be easy as well?)



I have thought that I can simply subset the element by the index value, but this seems not working in arcpy. Any advices? I think I am missing something very obvious...



import arcpy, os

# Set working environment
arcpy.env.workspace = os.path.join(inWD, "output/bufRastTwins.gdb")

# List all rasters with defined name wildcard: r_1, r_2, r_3.. to r_100
allRasters = arcpy.ListRasters("r_*")

# Select the first raster from the rasters list
myRasters = allRasters[0]
print myRasters


My attempt leads to loop through raster name, not throught the subsetted raster itself:



print myRaster:
r_1 # first element succesfully created

but for raster in myRasters:
print raster # this is obviously wrong

r
_
1









share|improve this question
















I have a list of rasters, created by arcpy using ListRasters. Rasters are stored in a geodatabase. How can I subset only one raster of the raster list? The goal is to make a new list, but containing only one raster file.



Ultimate goal is to loop through list of rasters and calculate Area solar radiation for each one of them. But, but for learning/training purposes I wish to explore my parameters only on single raster for now. (I know I can read-in just single raster, but I thought that subsetting might be easy as well?)



I have thought that I can simply subset the element by the index value, but this seems not working in arcpy. Any advices? I think I am missing something very obvious...



import arcpy, os

# Set working environment
arcpy.env.workspace = os.path.join(inWD, "output/bufRastTwins.gdb")

# List all rasters with defined name wildcard: r_1, r_2, r_3.. to r_100
allRasters = arcpy.ListRasters("r_*")

# Select the first raster from the rasters list
myRasters = allRasters[0]
print myRasters


My attempt leads to loop through raster name, not throught the subsetted raster itself:



print myRaster:
r_1 # first element succesfully created

but for raster in myRasters:
print raster # this is obviously wrong

r
_
1






arcpy raster list






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago









PolyGeo

54.9k17 gold badges86 silver badges258 bronze badges




54.9k17 gold badges86 silver badges258 bronze badges










asked 8 hours ago









mayccamaycca

1,3641 gold badge17 silver badges38 bronze badges




1,3641 gold badge17 silver badges38 bronze badges















  • Hi @BERA, thank you for your comment. I am trying to calculate solar radiation afterwards, but for making a script I wanted to run it simply on one raster. I have completed my question to answer your comment.

    – maycca
    8 hours ago











  • arcpy.ListRasters is only returning a list containing "raster names in the workspace". Extracting the first element of this list is only giving you the first raster name within the specified workspace. With it you can do something like os.path.join(inWD, "output/bufRastTwins.gdb", allRasters[0] to hae the full path plus name of your raster and use this as your input for further analysis.

    – umbe1987
    8 hours ago

















  • Hi @BERA, thank you for your comment. I am trying to calculate solar radiation afterwards, but for making a script I wanted to run it simply on one raster. I have completed my question to answer your comment.

    – maycca
    8 hours ago











  • arcpy.ListRasters is only returning a list containing "raster names in the workspace". Extracting the first element of this list is only giving you the first raster name within the specified workspace. With it you can do something like os.path.join(inWD, "output/bufRastTwins.gdb", allRasters[0] to hae the full path plus name of your raster and use this as your input for further analysis.

    – umbe1987
    8 hours ago
















Hi @BERA, thank you for your comment. I am trying to calculate solar radiation afterwards, but for making a script I wanted to run it simply on one raster. I have completed my question to answer your comment.

– maycca
8 hours ago





Hi @BERA, thank you for your comment. I am trying to calculate solar radiation afterwards, but for making a script I wanted to run it simply on one raster. I have completed my question to answer your comment.

– maycca
8 hours ago













arcpy.ListRasters is only returning a list containing "raster names in the workspace". Extracting the first element of this list is only giving you the first raster name within the specified workspace. With it you can do something like os.path.join(inWD, "output/bufRastTwins.gdb", allRasters[0] to hae the full path plus name of your raster and use this as your input for further analysis.

– umbe1987
8 hours ago





arcpy.ListRasters is only returning a list containing "raster names in the workspace". Extracting the first element of this list is only giving you the first raster name within the specified workspace. With it you can do something like os.path.join(inWD, "output/bufRastTwins.gdb", allRasters[0] to hae the full path plus name of your raster and use this as your input for further analysis.

– umbe1987
8 hours ago










1 Answer
1






active

oldest

votes


















2















This myRasters = allRasters[0] will select first element of the list which is a string. So if you loop over it you loop over each characher in it which is what you see:



rasters = ['abc','def']

for raster in rasters[0]:
print(raster)
a
b
c


You can slice the list like this which will return a list of only the first element:



for raster in myRasters[:1]:
print(raster)
abc





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%2f333035%2fsubsetting-single-raster-from-raster-list-using-arcpy%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2















    This myRasters = allRasters[0] will select first element of the list which is a string. So if you loop over it you loop over each characher in it which is what you see:



    rasters = ['abc','def']

    for raster in rasters[0]:
    print(raster)
    a
    b
    c


    You can slice the list like this which will return a list of only the first element:



    for raster in myRasters[:1]:
    print(raster)
    abc





    share|improve this answer































      2















      This myRasters = allRasters[0] will select first element of the list which is a string. So if you loop over it you loop over each characher in it which is what you see:



      rasters = ['abc','def']

      for raster in rasters[0]:
      print(raster)
      a
      b
      c


      You can slice the list like this which will return a list of only the first element:



      for raster in myRasters[:1]:
      print(raster)
      abc





      share|improve this answer





























        2














        2










        2









        This myRasters = allRasters[0] will select first element of the list which is a string. So if you loop over it you loop over each characher in it which is what you see:



        rasters = ['abc','def']

        for raster in rasters[0]:
        print(raster)
        a
        b
        c


        You can slice the list like this which will return a list of only the first element:



        for raster in myRasters[:1]:
        print(raster)
        abc





        share|improve this answer















        This myRasters = allRasters[0] will select first element of the list which is a string. So if you loop over it you loop over each characher in it which is what you see:



        rasters = ['abc','def']

        for raster in rasters[0]:
        print(raster)
        a
        b
        c


        You can slice the list like this which will return a list of only the first element:



        for raster in myRasters[:1]:
        print(raster)
        abc






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 7 hours ago

























        answered 8 hours ago









        BERABERA

        20k6 gold badges23 silver badges46 bronze badges




        20k6 gold badges23 silver badges46 bronze badges






























            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%2f333035%2fsubsetting-single-raster-from-raster-list-using-arcpy%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

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單