0

I've downloaded an 8-day composite (4x4km) of "chlorophyll a" for May 1, 2014. https://oceancolor.gsfc.nasa.gov/cgi/l3?per=8D&prd=CHL_chlor_a.nc&sen=A&res=4km&num=24&ctg=Standard&date=1May2015

I opened the chlorophyll file in r:

chloro<-raster(path.expand("C:/MODIS_data/CHL_A_MODIS/1May2014_L3M_8D_CHL_4km.nc"))

I then made the following polygon in r:

vertices<-c(-129.0417,-129.0417,-130.4583,-130.4583,50.45833,51.79166,51.79166,50.45833)
vertices<-matrix(vertices,4,2)
polygon<-Polygon(vertices)
polygono<-Polygons(list(polygon),1)
polygonsp<-SpatialPolygons(list(polygono))
proj4string(polygonsp)<-CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
plot(polygonsp)

I used the polygon to crop the chlorophyll raster to my study area:

chloro_area<-crop(chloro, polygonsp)

I wanted to look at the distribution of chlorophyll values in the region so I extracted the data as a data frame:

chloro_df<-as.data.frame(chloro_area)

I can open this df and see the values without any problem. However, because of the format of my other data files, it is preferable for me to project the raster in UTM.

chloro_area_utm<-projectRaster(chloro_area, crs="+proj=utm +zone=9 ellps=WGS84 datum=WGS84")

However, when I try the same code, I get a data frame filled with NA values.

chloro_df_utm<-as.data.frame(chloro_area_utm)

Why won't it work? I would like the raster to be in UTM so that I can overlay SpatialPoints, and calculate distances, etc.

  • Reprojecting is a destructive resampling process. What are the data like before that? – mdsumner Mar 15 '17 at 6:18
  • "Filled" with NA's? I get a border of NAs round the data, but if I plot it I can still see the data, and if I plot a transformed version of your polygon it fits round the data quite nicely. I'm not sure why there's a border of NAs. I suggest you crop the original to a wider area, transform the raster, then crop using a polygon in UTM coordinates. – Spacedman Mar 15 '17 at 7:42
  • We'll, that's embarrassing. Spacedman, turns out I didn't scroll through the df. There are lots of NAs for the borders, but the values are in there too. If reprojecting is a destructive resampling process, should I try to avoid it if I can? I've always been told that working with data that's only projected in latlong is poor practice. – Splash1199 Mar 15 '17 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.