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

How do BIP numbers get assigned?

I have found a mistake on someone's code published online: what is the protocol?

Random piece of plastic

Who determines when road center lines are solid or dashed?

The most secure way to handle someone forgetting to verify their account?

Inscriptio Labyrinthica

Why don't humans perceive waves as twice the frequency they are?

Which GPUs to get for Mathematical Optimization (if any)?

Proof that every field is perfect???

Do pedestrians imitate auto traffic?

How do I reproduce this layout and typography?

Who would use the word "manky"?

How was Luke's prosthetic hand in Episode V filmed?

"This used to be my phone number"

How many opportunity attacks can you make per turn before becoming exhausted?

Apex Legends stuck at 60 FPS (G-Sync 144hz monitor)

When will the last unambiguous evidence of mankind be gone?

How to tell if JDK is available from within running JVM?

Why aren't there any women super GMs?

Batch processing/extracting raw data of one raster using one shapefile (with many polygons)?

Is encryption still applied if you ignore the SSL certificate warning for self-signed certs?

Why doesn't Venus have a magnetic field? How does the speed of rotation affect the magnetic field of a planet?

How can I help our ranger feel special about her beast companion?

🍩🔔🔥Scrambled emoji tale⚛️🎶🛒 #2️⃣



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;








1















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).










share|improve this question









New contributor



doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • "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
    8 hours ago











  • Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.

    – doconnor
    8 hours ago











  • 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
    8 hours ago












  • @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.

    – doconnor
    8 hours ago

















1















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).










share|improve this question









New contributor



doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • "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
    8 hours ago











  • Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.

    – doconnor
    8 hours ago











  • 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
    8 hours ago












  • @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.

    – doconnor
    8 hours ago













1












1








1








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).










share|improve this question









New contributor



doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor



doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 4 hours ago









Vince

15.1k4 gold badges30 silver badges50 bronze badges




15.1k4 gold badges30 silver badges50 bronze badges






New contributor



doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 8 hours ago









doconnordoconnor

1114 bronze badges




1114 bronze badges




New contributor



doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




doconnor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • "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
    8 hours ago











  • Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.

    – doconnor
    8 hours ago











  • 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
    8 hours ago












  • @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.

    – doconnor
    8 hours ago

















  • "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
    8 hours ago











  • Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.

    – doconnor
    8 hours ago











  • 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
    8 hours ago












  • @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.

    – doconnor
    8 hours ago
















"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
8 hours ago





"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
8 hours ago













Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.

– doconnor
8 hours ago





Oh right, good point @umbe1987 - I'll revise - though the accompanying attribute table that I'm looking for seems to be the counts.

– doconnor
8 hours ago













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
8 hours ago






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
8 hours ago














@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.

– doconnor
8 hours ago





@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.

– doconnor
8 hours ago










3 Answers
3






active

oldest

votes


















3














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





share|improve this answer























  • awesome. thank you! very glad to know about velox now, too.

    – doconnor
    7 hours ago



















2














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:



enter image description here






share|improve this answer

























  • thank you! I'm most comfortable with R but I will learn from your example.

    – doconnor
    7 hours ago











  • You're welcome, happy you found a solution to your problem!

    – umbe1987
    7 hours ago


















-1














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.






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
    );



    );






    doconnor is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    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









    3














    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





    share|improve this answer























    • awesome. thank you! very glad to know about velox now, too.

      – doconnor
      7 hours ago
















    3














    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





    share|improve this answer























    • awesome. thank you! very glad to know about velox now, too.

      – doconnor
      7 hours ago














    3












    3








    3







    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





    share|improve this answer













    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






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 7 hours ago









    Mikkel Lydholm RasmussenMikkel Lydholm Rasmussen

    5,1688 silver badges19 bronze badges




    5,1688 silver badges19 bronze badges












    • awesome. thank you! very glad to know about velox now, too.

      – doconnor
      7 hours ago


















    • awesome. thank you! very glad to know about velox now, too.

      – doconnor
      7 hours ago

















    awesome. thank you! very glad to know about velox now, too.

    – doconnor
    7 hours ago






    awesome. thank you! very glad to know about velox now, too.

    – doconnor
    7 hours ago














    2














    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:



    enter image description here






    share|improve this answer

























    • thank you! I'm most comfortable with R but I will learn from your example.

      – doconnor
      7 hours ago











    • You're welcome, happy you found a solution to your problem!

      – umbe1987
      7 hours ago















    2














    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:



    enter image description here






    share|improve this answer

























    • thank you! I'm most comfortable with R but I will learn from your example.

      – doconnor
      7 hours ago











    • You're welcome, happy you found a solution to your problem!

      – umbe1987
      7 hours ago













    2












    2








    2







    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:



    enter image description here






    share|improve this answer















    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:



    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 7 hours ago

























    answered 7 hours ago









    umbe1987umbe1987

    1,4582 gold badges13 silver badges30 bronze badges




    1,4582 gold badges13 silver badges30 bronze badges












    • thank you! I'm most comfortable with R but I will learn from your example.

      – doconnor
      7 hours ago











    • You're welcome, happy you found a solution to your problem!

      – umbe1987
      7 hours ago

















    • thank you! I'm most comfortable with R but I will learn from your example.

      – doconnor
      7 hours ago











    • You're welcome, happy you found a solution to your problem!

      – umbe1987
      7 hours ago
















    thank you! I'm most comfortable with R but I will learn from your example.

    – doconnor
    7 hours ago





    thank you! I'm most comfortable with R but I will learn from your example.

    – doconnor
    7 hours ago













    You're welcome, happy you found a solution to your problem!

    – umbe1987
    7 hours ago





    You're welcome, happy you found a solution to your problem!

    – umbe1987
    7 hours ago











    -1














    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.






    share|improve this answer



























      -1














      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.






      share|improve this answer

























        -1












        -1








        -1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 6 hours ago









        alexGISalexGIS

        1,1403 silver badges8 bronze badges




        1,1403 silver badges8 bronze badges




















            doconnor is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            doconnor is a new contributor. Be nice, and check out our Code of Conduct.












            doconnor is a new contributor. Be nice, and check out our Code of Conduct.











            doconnor is a new contributor. Be nice, and check out our Code of Conduct.














            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%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





















































            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

            François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480