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;
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
add a comment |
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
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 likeos.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
add a comment |
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
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
arcpy raster list
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 likeos.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
add a comment |
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 likeos.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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
edited 7 hours ago
answered 8 hours ago
BERABERA
20k6 gold badges23 silver badges46 bronze badges
20k6 gold badges23 silver badges46 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 likeos.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