0

DATA

Download from this website the following ZIP file: NUTS_2006_60M_SH.zip and save all the NUTS_RG_60M_2006 files. In what follows I refer to this as "NUTS3 regions".

Download from this website the following nc-file: cru_ts3.23.1991.2000.pet.dat.nc.gz This is a raster with data all over the world.

Desired output

The nc-file is a raster of the world with values in different colors.

raster data

The goal is now to translate these data to a NUTS3 polygon regions and save it back as a nuts3-shapefile with the data added to the polyons.

Add data to polygons

Software

I can work with R, but since I couldn't make it work in R, I switched to ArcGIS. If the data are added to the NUTS3 shapefile, I can continue working with it in R.

Any solution in R or ArcGIS is welcome, as long as the output is 1 polygon shapefile with all the values added.

Problem

I can open the nc-file in ArcGIS (toolbox, multi-dimension tools, make netCDF Raster Layer). I can also overlap the nuts3-file with the raster. But I can't merge the data together in one shapefile (by taking the average of the underlying rasters that overlap with one polygon) and drop all the data that I don't need.

I found some examples on how to do this on Google, but only one of them explained how to start from an nc-file. As far as I understood, I first have to right click on the data-layer to export the data as a raster (as it is now only an nc-file and not yet a shapefile). However, this is not working since I get the following error: "Output file format with specified pixel type or number of bands or colormap is not supported."

2 Answers 2

1
  1. Under ArcMap: Toolbox\Multidimension tools\Make netCDF Raster Layer: Raster layer will appear in TOC of map document
  2. In ArcMap-document TOC: Right click the Raster layer entry and convert to e.g. TIFF-file. I do not think that you can convert straight away to ESRI-GRID-format
  3. Toolbox\Conversion tools\ToRaster\Raster to other format (multiple): choose ESRI GRID
  4. Toolbox: Spatial Analyst Tools\Zonal Statistics\Zonal Statistics (as table). Use the NUTS-dataset for input and the ESRI-GRID as the input value raster. Specify the statistic you need.
  5. Cheers
1
  • Thank you very much for your help! I really appreciate it. I think your solution works, but I do not get the output I need because I might have some memory issues to run it. Eventually I found a way to solve it in R, so I am fine now! Nevertheless: thank you once again!
    – user33125
    Commented Jun 28, 2016 at 13:53
1

I found an answer on the following website on how to do this in R. The solution that is given above also works, but I am having memory problems to run it.

http://article.gmane.org/gmane.comp.lang.r.geo/24010/match=

##########################################################################
library(fields)
library(chron)
library(ncdf4)

setwd("C:/Users/lucp8042/Desktop/CRU")

## we have the files
nutsdsn <- "NUTS_2006_60M_SH/shape/data"
nutslayer <- "NUTS_RG_60M_2006" ## bingo, polygons


library(rgdal)  ## to read shapefile
admin  <- readOGR(".", layer = "NUTS_RG_60M_2006")


##### PET #####
setwd("C:/Users/lucp8042/Desktop/CRU/Pet")
ncfile <- "cru_ts3.23.1981.1990.pet.dat.nc"


library(raster)
## looks fine
plot(raster(ncfile))  ## this gets the first layer (or "band")
plot(admin, add = TRUE)

admin

## get every layer (without actually loading necessarily)
(cru_ts3 <- brick(ncfile))


## extract everything, collapse to mean values

## note that this will automatically transform to the raster
## and warn, you should explore what this does (the plot above does not for example)
ex <- extract(cru_ts3, admin, fun = mean)
dim(ex)
## [1] 1927  120

## tidy up
d <- as.data.frame(ex)
row.names(d) <- row.names(admin)
1
  • By plotting the netCDF file you are reading the raster into memory. It is questionable that this format is held out of memory so, I would convert it to a tiff and than attempt you analysis. We just had memory issues with netCDF and changing rasrer formats worked. Commented Apr 9, 2017 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.