Batch processing/extracting raw data of one raster using one shapefile (with many polygons)?Recoding values based on contents using ArcGIS Field Calculator?Find locations of raster maximum within polygons: Basin DelineationR - Plotting shapefile with geographical (raster) dataShapefile One-to-Many Relationship in ROverlaying grids with a polygon to determine the average value of the overlapping grids for that polygonChanging raster calculation values - shorten this script?Zonal identification and statistics in ArcGISHow to identify which lines/polygons intersect when using raster data in RPlotting and analyzing extracted elevation data in R?Computing number of points in a raster grid cell in R
What are the closest international airports in different countries?
Semen retention is a important thing in Martial arts?
Piece of chess engine, which accomplishes move generation
What is the reason for cards stating "Until end of turn, you don't lose this mana as steps and phases end"?
What force enables us to walk? Friction or normal reaction?
Why are we moving in circles with a tandem kayak?
Can a US President, after impeachment and removal, be re-elected or re-appointed?
My employer is refusing to give me the pay that was advertised after an internal job move
How long does it take for electricity to be considered OFF by general appliances?
Is SecureRandom.ints() secure?
In syntax, why cannot we say things like "he took walked at the park"? but can say "he took a walk at the park"?
Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?
Why does the Eurostar not show youth pricing?
How well would the Moon protect the Earth from an Asteroid?
How to efficiently shred a lot of cabbage?
Wrapping IMemoryCache with SemaphoreSlim
Omnidirectional LED, is it possible?
Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?
2010 (?) science fiction TV show with new world
A cubeful of three-dimensional devilry
Narset, Parter of Veils interaction with Aria of Flame
Employer stores plain text personal data in a 'data warehouse'
Exploiting the delay when a festival ticket is scanned
Is The Venice Syndrome documentary cover photo real?
Batch processing/extracting raw data of one raster using one shapefile (with many polygons)?
Recoding values based on contents using ArcGIS Field Calculator?Find locations of raster maximum within polygons: Basin DelineationR - Plotting shapefile with geographical (raster) dataShapefile One-to-Many Relationship in ROverlaying grids with a polygon to determine the average value of the overlapping grids for that polygonChanging raster calculation values - shorten this script?Zonal identification and statistics in ArcGISHow to identify which lines/polygons intersect when using raster data in RPlotting and analyzing extracted elevation data in R?Computing number of points in a raster grid cell in R
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
If we have a raster, say of integer elevation data for a country,
and one polygon shapefile, say of 300 river basins in that country, with a unique name for each, how would we most easily get output like this for them all?
basinID, gridcellelev
a, 320
a, 321
a, 320
b, 17
b, 18
b, 19
The most burdensome way seems to be filtering/converting the single shapefile into 300 shapefiles,
clipping the raster 300 times into 300 uniqueID rasters, reading them back in, generating individual tables for each basin, then combining them all together.
On the other hand the ideal way seems to be skipping the file generation, not saving the xy data, and creating the same table from just using one raster and one shapefile - by iteratively selecting the cells within a basin, stamping them with the basinID, creating a table, losing the coordinates, and keep repeating and appending that table until the 300th basin.
I'm not looking for any statistics, just the raw data listing of the grid cell elevations that would have been part of some standard clip method. I believe the attribute table that comes with the clipped raster from ArcMap is the counts/frequency of the cells. That output table format works for me too.
I don't know to minimally reproduce a raster and a polygon shapefile,
so I'd just be grateful for any tips/libraries/functions/examples. If starting with R, here's a starting point:
library(tidyverse)
library(raster)
library(rgdal)
library(sf)
elev_raster <- raster("spain_elev_meters.tif") #integer raster
basins <- readOGR("spainbasins.shp", "spainbasins") %>% st_as_sf() #unique basin ID column: `basinID`
I'd prefer to do everything in R, but happy to try any batch methods in ArcGIS as well (I have 10.6 with Spatial Analyst, but not Pro).
arcgis-desktop r
add a comment |
If we have a raster, say of integer elevation data for a country,
and one polygon shapefile, say of 300 river basins in that country, with a unique name for each, how would we most easily get output like this for them all?
basinID, gridcellelev
a, 320
a, 321
a, 320
b, 17
b, 18
b, 19
The most burdensome way seems to be filtering/converting the single shapefile into 300 shapefiles,
clipping the raster 300 times into 300 uniqueID rasters, reading them back in, generating individual tables for each basin, then combining them all together.
On the other hand the ideal way seems to be skipping the file generation, not saving the xy data, and creating the same table from just using one raster and one shapefile - by iteratively selecting the cells within a basin, stamping them with the basinID, creating a table, losing the coordinates, and keep repeating and appending that table until the 300th basin.
I'm not looking for any statistics, just the raw data listing of the grid cell elevations that would have been part of some standard clip method. I believe the attribute table that comes with the clipped raster from ArcMap is the counts/frequency of the cells. That output table format works for me too.
I don't know to minimally reproduce a raster and a polygon shapefile,
so I'd just be grateful for any tips/libraries/functions/examples. If starting with R, here's a starting point:
library(tidyverse)
library(raster)
library(rgdal)
library(sf)
elev_raster <- raster("spain_elev_meters.tif") #integer raster
basins <- readOGR("spainbasins.shp", "spainbasins") %>% st_as_sf() #unique basin ID column: `basinID`
I'd prefer to do everything in R, but happy to try any batch methods in ArcGIS as well (I have 10.6 with Spatial Analyst, but not Pro).
arcgis-desktop r
"I believe the standard raster clip output that comes out of ArcMap is not the raw data but the counts/frequency of the cells." No, you'll get a raster which is equal the original one but clipped on the area defined by one or more polygons.
– umbe1987
Jul 19 at 14:29
Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.
– dbo
Jul 19 at 14:31
The attribute table of a raster generally gives you only a list of unique pixel values witout repetition along with their respective count in that raster.
– umbe1987
Jul 19 at 14:36
@umbe1987, either would be fine - the frequency as you mention or the raw list of each cell's elevation - as long as each row has the basinID. In R I'm familiar with how to quickly convert one to the other.
– dbo
Jul 19 at 14:40
add a comment |
If we have a raster, say of integer elevation data for a country,
and one polygon shapefile, say of 300 river basins in that country, with a unique name for each, how would we most easily get output like this for them all?
basinID, gridcellelev
a, 320
a, 321
a, 320
b, 17
b, 18
b, 19
The most burdensome way seems to be filtering/converting the single shapefile into 300 shapefiles,
clipping the raster 300 times into 300 uniqueID rasters, reading them back in, generating individual tables for each basin, then combining them all together.
On the other hand the ideal way seems to be skipping the file generation, not saving the xy data, and creating the same table from just using one raster and one shapefile - by iteratively selecting the cells within a basin, stamping them with the basinID, creating a table, losing the coordinates, and keep repeating and appending that table until the 300th basin.
I'm not looking for any statistics, just the raw data listing of the grid cell elevations that would have been part of some standard clip method. I believe the attribute table that comes with the clipped raster from ArcMap is the counts/frequency of the cells. That output table format works for me too.
I don't know to minimally reproduce a raster and a polygon shapefile,
so I'd just be grateful for any tips/libraries/functions/examples. If starting with R, here's a starting point:
library(tidyverse)
library(raster)
library(rgdal)
library(sf)
elev_raster <- raster("spain_elev_meters.tif") #integer raster
basins <- readOGR("spainbasins.shp", "spainbasins") %>% st_as_sf() #unique basin ID column: `basinID`
I'd prefer to do everything in R, but happy to try any batch methods in ArcGIS as well (I have 10.6 with Spatial Analyst, but not Pro).
arcgis-desktop r
If we have a raster, say of integer elevation data for a country,
and one polygon shapefile, say of 300 river basins in that country, with a unique name for each, how would we most easily get output like this for them all?
basinID, gridcellelev
a, 320
a, 321
a, 320
b, 17
b, 18
b, 19
The most burdensome way seems to be filtering/converting the single shapefile into 300 shapefiles,
clipping the raster 300 times into 300 uniqueID rasters, reading them back in, generating individual tables for each basin, then combining them all together.
On the other hand the ideal way seems to be skipping the file generation, not saving the xy data, and creating the same table from just using one raster and one shapefile - by iteratively selecting the cells within a basin, stamping them with the basinID, creating a table, losing the coordinates, and keep repeating and appending that table until the 300th basin.
I'm not looking for any statistics, just the raw data listing of the grid cell elevations that would have been part of some standard clip method. I believe the attribute table that comes with the clipped raster from ArcMap is the counts/frequency of the cells. That output table format works for me too.
I don't know to minimally reproduce a raster and a polygon shapefile,
so I'd just be grateful for any tips/libraries/functions/examples. If starting with R, here's a starting point:
library(tidyverse)
library(raster)
library(rgdal)
library(sf)
elev_raster <- raster("spain_elev_meters.tif") #integer raster
basins <- readOGR("spainbasins.shp", "spainbasins") %>% st_as_sf() #unique basin ID column: `basinID`
I'd prefer to do everything in R, but happy to try any batch methods in ArcGIS as well (I have 10.6 with Spatial Analyst, but not Pro).
arcgis-desktop r
arcgis-desktop r
edited Jul 19 at 18:09
Vince
15.3k4 gold badges30 silver badges50 bronze badges
15.3k4 gold badges30 silver badges50 bronze badges
asked Jul 19 at 14:21
dbodbo
1214 bronze badges
1214 bronze badges
"I believe the standard raster clip output that comes out of ArcMap is not the raw data but the counts/frequency of the cells." No, you'll get a raster which is equal the original one but clipped on the area defined by one or more polygons.
– umbe1987
Jul 19 at 14:29
Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.
– dbo
Jul 19 at 14:31
The attribute table of a raster generally gives you only a list of unique pixel values witout repetition along with their respective count in that raster.
– umbe1987
Jul 19 at 14:36
@umbe1987, either would be fine - the frequency as you mention or the raw list of each cell's elevation - as long as each row has the basinID. In R I'm familiar with how to quickly convert one to the other.
– dbo
Jul 19 at 14:40
add a comment |
"I believe the standard raster clip output that comes out of ArcMap is not the raw data but the counts/frequency of the cells." No, you'll get a raster which is equal the original one but clipped on the area defined by one or more polygons.
– umbe1987
Jul 19 at 14:29
Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.
– dbo
Jul 19 at 14:31
The attribute table of a raster generally gives you only a list of unique pixel values witout repetition along with their respective count in that raster.
– umbe1987
Jul 19 at 14:36
@umbe1987, either would be fine - the frequency as you mention or the raw list of each cell's elevation - as long as each row has the basinID. In R I'm familiar with how to quickly convert one to the other.
– dbo
Jul 19 at 14:40
"I believe the standard raster clip output that comes out of ArcMap is not the raw data but the counts/frequency of the cells." No, you'll get a raster which is equal the original one but clipped on the area defined by one or more polygons.
– umbe1987
Jul 19 at 14:29
"I believe the standard raster clip output that comes out of ArcMap is not the raw data but the counts/frequency of the cells." No, you'll get a raster which is equal the original one but clipped on the area defined by one or more polygons.
– umbe1987
Jul 19 at 14:29
Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.
– dbo
Jul 19 at 14:31
Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.
– dbo
Jul 19 at 14:31
The attribute table of a raster generally gives you only a list of unique pixel values witout repetition along with their respective count in that raster.
– umbe1987
Jul 19 at 14:36
The attribute table of a raster generally gives you only a list of unique pixel values witout repetition along with their respective count in that raster.
– umbe1987
Jul 19 at 14:36
@umbe1987, either would be fine - the frequency as you mention or the raw list of each cell's elevation - as long as each row has the basinID. In R I'm familiar with how to quickly convert one to the other.
– dbo
Jul 19 at 14:40
@umbe1987, either would be fine - the frequency as you mention or the raw list of each cell's elevation - as long as each row has the basinID. In R I'm familiar with how to quickly convert one to the other.
– dbo
Jul 19 at 14:40
add a comment |
3 Answers
3
active
oldest
votes
While this is not a complete answer, as I do not have your exact files etc., it should serve as a close basis for what you are trying to do.
setwd("D:/blah/")
library(velox)
library(raster)
library(rgdal)
library(sf)
library(tidyverse)
elev_raster <- raster("ElevationRaster.tif")
basins <- readOGR("basin.shp", "basin") %>% st_as_sf()
basins_ID <- data.frame(c(1:length(basins$geometry)),as.character(basins$name),stringsAsFactors = F) # create a frame to link geometry ID to the basin name
colnames(basins_ID) <- c("ID","Name") # a bit of house-keeping to make the frame easier to understand
vlx_data <- velox(elev_raster) # velox rasters are super fast for extracting. Normal raster-package ones are sloooow.
extracted_data <- vlx_data$extract(basins,df=T,small=T) # extracting with velox is easy
colnames(extracted_data) <- c("ID","Elev") # house keeping again
merged_data <- merge(extracted_data,basins_ID,by="ID") # and now we merge the data tables to make nice looking dataset
head(merged_data)
This results in this nice dataFrame:
ID Elev Name
1 1 31.050 a
2 1 14.550 a
3 1 19.840 a
4 1 63.226 a
5 1 86.181 a
6 1 77.979 a
awesome. thank you! very glad to know aboutvelox
now, too.
– dbo
Jul 19 at 15:52
add a comment |
If you're comfortable with arcpy, you can try this script.
Basically, it loop through each basin, clip the input raster and write in the output table all the values found in the clipped raster along with the name of the current basin.
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# CHANGE THESE TO FIT YOUR NAMES!!!
# COMPLETE PATH AND NAME OF YOUR INPUT RASTER
in_raster = r"C:Umbertocorsiumbe_arcgisproGDEM30m_clip02.tif"
# COMPLETE PATH AND NAME OF YOUR BASIN SHAPE
basins = r"C:UsersminorauDocumentsArcGISDefault.gdbbasins"
# NAME OF THE FIELD YOU WANT TO PRESERVE FROM THE BASIN ATTRIBUTE TABLE
basin_field = "name"
# OUTPUT PATH TO STORE YOU FINAL TABLE (I USED A GDB)
output_gdb = r"C:UsersminorauDocumentsArcGISDefault.gdb"
out_table = arcpy.CreateTable_management(output_gdb, "output_table")
arcpy.AddField_management(out_table, basin_field, "TEXT")
arcpy.AddField_management(out_table, "Value", "LONG")
basins_lyr = arcpy.MakeFeatureLayer_management(basins, "basins_lyr")
# loop through each basin
with arcpy.da.SearchCursor(basins, [basin_field]) as b_cur:
for basin in b_cur:
arcpy.SelectLayerByAttribute_management(basins_lyr, "NEW_SELECTION", """0 = '1'""".format(basin_field, basin[0]))
raster_clip = ExtractByMask(in_raster, basins_lyr)
##Build attribute table for single band raster dataset
##Overwrite the existing attribute table file
#arcpy.BuildRasterAttributeTable_management(raster_clip, "Overwrite")
temp_result = arcpy.TableToTable_conversion(raster_clip, output_gdb, "output")
with arcpy.da.SearchCursor(temp_result, ['Value']) as r_cur:
for val in r_cur:
with arcpy.da.InsertCursor(out_table, [basin_field, "Value"]) as i_cur:
i_cur.insertRow((basin[0], val[0]))
Here is a printscreen of the results and the inputs I've used to test it:
thank you! I'm most comfortable with R but I will learn from your example.
– dbo
Jul 19 at 15:51
You're welcome, happy you found a solution to your problem!
– umbe1987
Jul 19 at 15:52
add a comment |
How about "Convert Raster to Polygon", then do a "Spatial Join" of those new elevation polygons with your basin polygons. Do it so the centroids of the elevation polygons being inside of a basin polygon as the match method.
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%2f329347%2fbatch-processing-extracting-raw-data-of-one-raster-using-one-shapefile-with-man%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
While this is not a complete answer, as I do not have your exact files etc., it should serve as a close basis for what you are trying to do.
setwd("D:/blah/")
library(velox)
library(raster)
library(rgdal)
library(sf)
library(tidyverse)
elev_raster <- raster("ElevationRaster.tif")
basins <- readOGR("basin.shp", "basin") %>% st_as_sf()
basins_ID <- data.frame(c(1:length(basins$geometry)),as.character(basins$name),stringsAsFactors = F) # create a frame to link geometry ID to the basin name
colnames(basins_ID) <- c("ID","Name") # a bit of house-keeping to make the frame easier to understand
vlx_data <- velox(elev_raster) # velox rasters are super fast for extracting. Normal raster-package ones are sloooow.
extracted_data <- vlx_data$extract(basins,df=T,small=T) # extracting with velox is easy
colnames(extracted_data) <- c("ID","Elev") # house keeping again
merged_data <- merge(extracted_data,basins_ID,by="ID") # and now we merge the data tables to make nice looking dataset
head(merged_data)
This results in this nice dataFrame:
ID Elev Name
1 1 31.050 a
2 1 14.550 a
3 1 19.840 a
4 1 63.226 a
5 1 86.181 a
6 1 77.979 a
awesome. thank you! very glad to know aboutvelox
now, too.
– dbo
Jul 19 at 15:52
add a comment |
While this is not a complete answer, as I do not have your exact files etc., it should serve as a close basis for what you are trying to do.
setwd("D:/blah/")
library(velox)
library(raster)
library(rgdal)
library(sf)
library(tidyverse)
elev_raster <- raster("ElevationRaster.tif")
basins <- readOGR("basin.shp", "basin") %>% st_as_sf()
basins_ID <- data.frame(c(1:length(basins$geometry)),as.character(basins$name),stringsAsFactors = F) # create a frame to link geometry ID to the basin name
colnames(basins_ID) <- c("ID","Name") # a bit of house-keeping to make the frame easier to understand
vlx_data <- velox(elev_raster) # velox rasters are super fast for extracting. Normal raster-package ones are sloooow.
extracted_data <- vlx_data$extract(basins,df=T,small=T) # extracting with velox is easy
colnames(extracted_data) <- c("ID","Elev") # house keeping again
merged_data <- merge(extracted_data,basins_ID,by="ID") # and now we merge the data tables to make nice looking dataset
head(merged_data)
This results in this nice dataFrame:
ID Elev Name
1 1 31.050 a
2 1 14.550 a
3 1 19.840 a
4 1 63.226 a
5 1 86.181 a
6 1 77.979 a
awesome. thank you! very glad to know aboutvelox
now, too.
– dbo
Jul 19 at 15:52
add a comment |
While this is not a complete answer, as I do not have your exact files etc., it should serve as a close basis for what you are trying to do.
setwd("D:/blah/")
library(velox)
library(raster)
library(rgdal)
library(sf)
library(tidyverse)
elev_raster <- raster("ElevationRaster.tif")
basins <- readOGR("basin.shp", "basin") %>% st_as_sf()
basins_ID <- data.frame(c(1:length(basins$geometry)),as.character(basins$name),stringsAsFactors = F) # create a frame to link geometry ID to the basin name
colnames(basins_ID) <- c("ID","Name") # a bit of house-keeping to make the frame easier to understand
vlx_data <- velox(elev_raster) # velox rasters are super fast for extracting. Normal raster-package ones are sloooow.
extracted_data <- vlx_data$extract(basins,df=T,small=T) # extracting with velox is easy
colnames(extracted_data) <- c("ID","Elev") # house keeping again
merged_data <- merge(extracted_data,basins_ID,by="ID") # and now we merge the data tables to make nice looking dataset
head(merged_data)
This results in this nice dataFrame:
ID Elev Name
1 1 31.050 a
2 1 14.550 a
3 1 19.840 a
4 1 63.226 a
5 1 86.181 a
6 1 77.979 a
While this is not a complete answer, as I do not have your exact files etc., it should serve as a close basis for what you are trying to do.
setwd("D:/blah/")
library(velox)
library(raster)
library(rgdal)
library(sf)
library(tidyverse)
elev_raster <- raster("ElevationRaster.tif")
basins <- readOGR("basin.shp", "basin") %>% st_as_sf()
basins_ID <- data.frame(c(1:length(basins$geometry)),as.character(basins$name),stringsAsFactors = F) # create a frame to link geometry ID to the basin name
colnames(basins_ID) <- c("ID","Name") # a bit of house-keeping to make the frame easier to understand
vlx_data <- velox(elev_raster) # velox rasters are super fast for extracting. Normal raster-package ones are sloooow.
extracted_data <- vlx_data$extract(basins,df=T,small=T) # extracting with velox is easy
colnames(extracted_data) <- c("ID","Elev") # house keeping again
merged_data <- merge(extracted_data,basins_ID,by="ID") # and now we merge the data tables to make nice looking dataset
head(merged_data)
This results in this nice dataFrame:
ID Elev Name
1 1 31.050 a
2 1 14.550 a
3 1 19.840 a
4 1 63.226 a
5 1 86.181 a
6 1 77.979 a
answered Jul 19 at 15:29
Mikkel Lydholm RasmussenMikkel Lydholm Rasmussen
5,2038 silver badges19 bronze badges
5,2038 silver badges19 bronze badges
awesome. thank you! very glad to know aboutvelox
now, too.
– dbo
Jul 19 at 15:52
add a comment |
awesome. thank you! very glad to know aboutvelox
now, too.
– dbo
Jul 19 at 15:52
awesome. thank you! very glad to know about
velox
now, too.– dbo
Jul 19 at 15:52
awesome. thank you! very glad to know about
velox
now, too.– dbo
Jul 19 at 15:52
add a comment |
If you're comfortable with arcpy, you can try this script.
Basically, it loop through each basin, clip the input raster and write in the output table all the values found in the clipped raster along with the name of the current basin.
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# CHANGE THESE TO FIT YOUR NAMES!!!
# COMPLETE PATH AND NAME OF YOUR INPUT RASTER
in_raster = r"C:Umbertocorsiumbe_arcgisproGDEM30m_clip02.tif"
# COMPLETE PATH AND NAME OF YOUR BASIN SHAPE
basins = r"C:UsersminorauDocumentsArcGISDefault.gdbbasins"
# NAME OF THE FIELD YOU WANT TO PRESERVE FROM THE BASIN ATTRIBUTE TABLE
basin_field = "name"
# OUTPUT PATH TO STORE YOU FINAL TABLE (I USED A GDB)
output_gdb = r"C:UsersminorauDocumentsArcGISDefault.gdb"
out_table = arcpy.CreateTable_management(output_gdb, "output_table")
arcpy.AddField_management(out_table, basin_field, "TEXT")
arcpy.AddField_management(out_table, "Value", "LONG")
basins_lyr = arcpy.MakeFeatureLayer_management(basins, "basins_lyr")
# loop through each basin
with arcpy.da.SearchCursor(basins, [basin_field]) as b_cur:
for basin in b_cur:
arcpy.SelectLayerByAttribute_management(basins_lyr, "NEW_SELECTION", """0 = '1'""".format(basin_field, basin[0]))
raster_clip = ExtractByMask(in_raster, basins_lyr)
##Build attribute table for single band raster dataset
##Overwrite the existing attribute table file
#arcpy.BuildRasterAttributeTable_management(raster_clip, "Overwrite")
temp_result = arcpy.TableToTable_conversion(raster_clip, output_gdb, "output")
with arcpy.da.SearchCursor(temp_result, ['Value']) as r_cur:
for val in r_cur:
with arcpy.da.InsertCursor(out_table, [basin_field, "Value"]) as i_cur:
i_cur.insertRow((basin[0], val[0]))
Here is a printscreen of the results and the inputs I've used to test it:
thank you! I'm most comfortable with R but I will learn from your example.
– dbo
Jul 19 at 15:51
You're welcome, happy you found a solution to your problem!
– umbe1987
Jul 19 at 15:52
add a comment |
If you're comfortable with arcpy, you can try this script.
Basically, it loop through each basin, clip the input raster and write in the output table all the values found in the clipped raster along with the name of the current basin.
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# CHANGE THESE TO FIT YOUR NAMES!!!
# COMPLETE PATH AND NAME OF YOUR INPUT RASTER
in_raster = r"C:Umbertocorsiumbe_arcgisproGDEM30m_clip02.tif"
# COMPLETE PATH AND NAME OF YOUR BASIN SHAPE
basins = r"C:UsersminorauDocumentsArcGISDefault.gdbbasins"
# NAME OF THE FIELD YOU WANT TO PRESERVE FROM THE BASIN ATTRIBUTE TABLE
basin_field = "name"
# OUTPUT PATH TO STORE YOU FINAL TABLE (I USED A GDB)
output_gdb = r"C:UsersminorauDocumentsArcGISDefault.gdb"
out_table = arcpy.CreateTable_management(output_gdb, "output_table")
arcpy.AddField_management(out_table, basin_field, "TEXT")
arcpy.AddField_management(out_table, "Value", "LONG")
basins_lyr = arcpy.MakeFeatureLayer_management(basins, "basins_lyr")
# loop through each basin
with arcpy.da.SearchCursor(basins, [basin_field]) as b_cur:
for basin in b_cur:
arcpy.SelectLayerByAttribute_management(basins_lyr, "NEW_SELECTION", """0 = '1'""".format(basin_field, basin[0]))
raster_clip = ExtractByMask(in_raster, basins_lyr)
##Build attribute table for single band raster dataset
##Overwrite the existing attribute table file
#arcpy.BuildRasterAttributeTable_management(raster_clip, "Overwrite")
temp_result = arcpy.TableToTable_conversion(raster_clip, output_gdb, "output")
with arcpy.da.SearchCursor(temp_result, ['Value']) as r_cur:
for val in r_cur:
with arcpy.da.InsertCursor(out_table, [basin_field, "Value"]) as i_cur:
i_cur.insertRow((basin[0], val[0]))
Here is a printscreen of the results and the inputs I've used to test it:
thank you! I'm most comfortable with R but I will learn from your example.
– dbo
Jul 19 at 15:51
You're welcome, happy you found a solution to your problem!
– umbe1987
Jul 19 at 15:52
add a comment |
If you're comfortable with arcpy, you can try this script.
Basically, it loop through each basin, clip the input raster and write in the output table all the values found in the clipped raster along with the name of the current basin.
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# CHANGE THESE TO FIT YOUR NAMES!!!
# COMPLETE PATH AND NAME OF YOUR INPUT RASTER
in_raster = r"C:Umbertocorsiumbe_arcgisproGDEM30m_clip02.tif"
# COMPLETE PATH AND NAME OF YOUR BASIN SHAPE
basins = r"C:UsersminorauDocumentsArcGISDefault.gdbbasins"
# NAME OF THE FIELD YOU WANT TO PRESERVE FROM THE BASIN ATTRIBUTE TABLE
basin_field = "name"
# OUTPUT PATH TO STORE YOU FINAL TABLE (I USED A GDB)
output_gdb = r"C:UsersminorauDocumentsArcGISDefault.gdb"
out_table = arcpy.CreateTable_management(output_gdb, "output_table")
arcpy.AddField_management(out_table, basin_field, "TEXT")
arcpy.AddField_management(out_table, "Value", "LONG")
basins_lyr = arcpy.MakeFeatureLayer_management(basins, "basins_lyr")
# loop through each basin
with arcpy.da.SearchCursor(basins, [basin_field]) as b_cur:
for basin in b_cur:
arcpy.SelectLayerByAttribute_management(basins_lyr, "NEW_SELECTION", """0 = '1'""".format(basin_field, basin[0]))
raster_clip = ExtractByMask(in_raster, basins_lyr)
##Build attribute table for single band raster dataset
##Overwrite the existing attribute table file
#arcpy.BuildRasterAttributeTable_management(raster_clip, "Overwrite")
temp_result = arcpy.TableToTable_conversion(raster_clip, output_gdb, "output")
with arcpy.da.SearchCursor(temp_result, ['Value']) as r_cur:
for val in r_cur:
with arcpy.da.InsertCursor(out_table, [basin_field, "Value"]) as i_cur:
i_cur.insertRow((basin[0], val[0]))
Here is a printscreen of the results and the inputs I've used to test it:
If you're comfortable with arcpy, you can try this script.
Basically, it loop through each basin, clip the input raster and write in the output table all the values found in the clipped raster along with the name of the current basin.
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# CHANGE THESE TO FIT YOUR NAMES!!!
# COMPLETE PATH AND NAME OF YOUR INPUT RASTER
in_raster = r"C:Umbertocorsiumbe_arcgisproGDEM30m_clip02.tif"
# COMPLETE PATH AND NAME OF YOUR BASIN SHAPE
basins = r"C:UsersminorauDocumentsArcGISDefault.gdbbasins"
# NAME OF THE FIELD YOU WANT TO PRESERVE FROM THE BASIN ATTRIBUTE TABLE
basin_field = "name"
# OUTPUT PATH TO STORE YOU FINAL TABLE (I USED A GDB)
output_gdb = r"C:UsersminorauDocumentsArcGISDefault.gdb"
out_table = arcpy.CreateTable_management(output_gdb, "output_table")
arcpy.AddField_management(out_table, basin_field, "TEXT")
arcpy.AddField_management(out_table, "Value", "LONG")
basins_lyr = arcpy.MakeFeatureLayer_management(basins, "basins_lyr")
# loop through each basin
with arcpy.da.SearchCursor(basins, [basin_field]) as b_cur:
for basin in b_cur:
arcpy.SelectLayerByAttribute_management(basins_lyr, "NEW_SELECTION", """0 = '1'""".format(basin_field, basin[0]))
raster_clip = ExtractByMask(in_raster, basins_lyr)
##Build attribute table for single band raster dataset
##Overwrite the existing attribute table file
#arcpy.BuildRasterAttributeTable_management(raster_clip, "Overwrite")
temp_result = arcpy.TableToTable_conversion(raster_clip, output_gdb, "output")
with arcpy.da.SearchCursor(temp_result, ['Value']) as r_cur:
for val in r_cur:
with arcpy.da.InsertCursor(out_table, [basin_field, "Value"]) as i_cur:
i_cur.insertRow((basin[0], val[0]))
Here is a printscreen of the results and the inputs I've used to test it:
edited Jul 19 at 15:49
answered Jul 19 at 15:34
umbe1987umbe1987
1,4782 gold badges13 silver badges30 bronze badges
1,4782 gold badges13 silver badges30 bronze badges
thank you! I'm most comfortable with R but I will learn from your example.
– dbo
Jul 19 at 15:51
You're welcome, happy you found a solution to your problem!
– umbe1987
Jul 19 at 15:52
add a comment |
thank you! I'm most comfortable with R but I will learn from your example.
– dbo
Jul 19 at 15:51
You're welcome, happy you found a solution to your problem!
– umbe1987
Jul 19 at 15:52
thank you! I'm most comfortable with R but I will learn from your example.
– dbo
Jul 19 at 15:51
thank you! I'm most comfortable with R but I will learn from your example.
– dbo
Jul 19 at 15:51
You're welcome, happy you found a solution to your problem!
– umbe1987
Jul 19 at 15:52
You're welcome, happy you found a solution to your problem!
– umbe1987
Jul 19 at 15:52
add a comment |
How about "Convert Raster to Polygon", then do a "Spatial Join" of those new elevation polygons with your basin polygons. Do it so the centroids of the elevation polygons being inside of a basin polygon as the match method.
add a comment |
How about "Convert Raster to Polygon", then do a "Spatial Join" of those new elevation polygons with your basin polygons. Do it so the centroids of the elevation polygons being inside of a basin polygon as the match method.
add a comment |
How about "Convert Raster to Polygon", then do a "Spatial Join" of those new elevation polygons with your basin polygons. Do it so the centroids of the elevation polygons being inside of a basin polygon as the match method.
How about "Convert Raster to Polygon", then do a "Spatial Join" of those new elevation polygons with your basin polygons. Do it so the centroids of the elevation polygons being inside of a basin polygon as the match method.
answered Jul 19 at 16:35
alexGISalexGIS
1,1383 silver badges8 bronze badges
1,1383 silver badges8 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%2f329347%2fbatch-processing-extracting-raw-data-of-one-raster-using-one-shapefile-with-man%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
"I believe the standard raster clip output that comes out of ArcMap is not the raw data but the counts/frequency of the cells." No, you'll get a raster which is equal the original one but clipped on the area defined by one or more polygons.
– umbe1987
Jul 19 at 14:29
Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.
– dbo
Jul 19 at 14:31
The attribute table of a raster generally gives you only a list of unique pixel values witout repetition along with their respective count in that raster.
– umbe1987
Jul 19 at 14:36
@umbe1987, either would be fine - the frequency as you mention or the raw list of each cell's elevation - as long as each row has the basinID. In R I'm familiar with how to quickly convert one to the other.
– dbo
Jul 19 at 14:40