Web Content Display

CoastWatch Forum Information

The NOAA CoastWatch Forum provides information in several categories.  The information is relevant to CoastWatch products and software (https://coastwatch.noaa.gov)  and vary in technical details.  For questions and issues not addressed here,  start a thread in the appropriate category or contact the CoastWatch HelpDesk (coastwatch.info@noaa.gov).  Please note our Privacy Policy (https://www.noaa.gov/privacy.html) and that this is a public forum.  All information is voluntarily and anonymous submissions are accepted pending review prior to posting. 

Forums

Back

RE: Using rxtractogon() to extract data per shapefile

MW
Morgan Winston, modified 3 Years ago.

Using rxtractogon() to extract data per shapefile

Youngling Posts: 12 Join Date: 9/6/17 Recent Posts

Hi there,

I went through the R tutorial 3 to learn how to extract data using shapefiles, which I understood, however my shapefile is composed of multiple polygons per island (including 1km buffer surrounding). I would like to extract the data per polygon and convert it to a format (like a data table) that is ggplot friendly because my ultimate goal is to plot a timeseries of SST by year for each island. Do you have any example code that I could reference for a question like this? Namely, a way to assign the island name (which is in the attribute table of the shape file) to the SST data extracted...

Thanks!

Morgan

CW
Cara Wilson, modified 3 Years ago.

RE: Using rxtractogon() to extract data per shapefile

Youngling Posts: 41 Join Date: 6/12/17 Recent Posts

Morgan - 

Simply change the variable name (ie set) that the extracted data is read into. So in the tutorial the code is:

sst <- rxtractogon (dataInfo, parameter=parameter, xcoord=xcoord, ycoord=ycoord, tcoord=tcoord)

But I think what you want to do is assign that variable by one you already have. If you are doing this is a do loop (using I as your indexing term) for multiple islands, you can reassign the variable name to one named for the island so if your island names are in the variable names 

names <- c('island1','island2') 

 assign(names[i],sst)

and then the extracted data will be in a variable named by the items in the "names" variable.  

 Does that make sense?  

 

Cara 

MW
Morgan Winston, modified 3 Years ago.

RE: Using rxtractogon() to extract data per shapefile

Youngling Posts: 12 Join Date: 9/6/17 Recent Posts

Hi Cara,

When you say change the variable name that the extracted data is read into, are you referring to 'sst'?

I'm not sure I am following. Do you mean write a for loop (what's a do loop?) that extracts data for each island at a time (I think I can figure that out)? What is the best way to then merge the data together?

Thanks!

Morgan

CW
Cara Wilson, modified 3 Years ago.

RE: Using rxtractogon() to extract data per shapefile

Youngling Posts: 41 Join Date: 6/12/17 Recent Posts
Yes, sorry I meant a for loop. And yes I was referring to the sat on the left hand side of that command line. It can be called anything. You could forego a for loop and just make that call 10 times, with different values in the xcoord and ycoord variables and give the returned value a different name each time. 

Cara

Sent from my iPhone

On Oct 28, 2020, at 5:05 PM, Morgan Winston <VLab.Notifications@noaa.gov> wrote:



Hi Cara,

When you say change the variable name that the extracted data is read into, are you referring to 'sst'?

I'm not sure I am following. Do you mean write a for loop (what's a do loop?) that extracts data for each island at a time (I think I can figure that out)? What is the best way to then merge the data together?

Thanks!

Morgan


--
Morgan Winston CoastWatch Virtual Lab Forum https://vlab.noaa.gov/web/coastwatch/coastwatch-knowledge-base/forum/-/message_boards/view_message/12349496 VLab.Notifications@noaa.gov

MW
Morgan Winston, modified 3 Years ago.

RE: Using rxtractogon() to extract data per shapefile

Youngling Posts: 12 Join Date: 9/6/17 Recent Posts

Thanks Cara I got it all figured out.

Now having weird issue getting 1985 SST data - I get the following error:

sst <- rxtractogon(dataInfo, parameter=parameter, xcoord=xcoord, ycoord=ycoord, tcoord=tcoord) # extract sst data
[1] "dimension coordinate out of bounds"
[1] "dimension name: time"
[1] "given coordinate bounds 1985-01-01 1985-12-30"
[1] "ERDDAP datasets bounds 1985-01-01 12:00:00 2020-10-27 12:00:00"

My tcoord is:

tcoord <- c("1985-01-01", "1985-12-31")

Odd because I don't think its an error with the code - when I replace 1985 with 1986 it works! I thought there was data available for all of 1985? I am working with the CRW Daily SST dataset.

Morgan