[R-sig-Geo] Overlapping a grid shapefile with a NUTS3 shapefile to determine one average value for each NUTS3 region
holtermann at hwwi.org
Wed Jul 22 11:45:54 CEST 2015
take a look at the "overlay" command in the raster-package. Weight=TRUE may be a step in the right direction for your problem.
Hamburgisches WeltWirtschaftsInstitut gemeinnützige GmbH (HWWI)
Heimhuder Straße 71
Email: holtermann at hwwi.org
Amtsgericht Hamburg HRB 94303
Geschäftsführer: PD Dr. Christian Growitsch | Prof. Dr. Henning Vöpel
Prokura: Dipl. Kauffrau Alexis Malchin
Umsatzsteuer-ID: DE 241849425
Von: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] Im Auftrag von Janka Vanschoenwinkel
Gesendet: Mittwoch, 22. Juli 2015 11:37
An: r-sig-geo at r-project.org
Betreff: [R-sig-Geo] Overlapping a grid shapefile with a NUTS3 shapefile to determine one average value for each NUTS3 region
I would like to add the average value of, let’s say soil moisture, to each
NUTS3 region. However, soil moisture values are stored in little grids.
Therefore, I need to find a way to calculate which grids overlap with a certain NUTS3 region in order to determine the average soil moisture value for that NUTS3 region. Visually, it can be compared to this picture where little grids approximate together the shape of US states:
It is possible that one NUTS3 region consists of 2 full grids and 3 half grids, while another NUTS3 region consists of only a 0.75 grid. It is also possible that some grids are empty because I don’t have values there.
I assume that this requires 3 steps (but I am actually not sure):
- Step 1 would be to add the values of the text file to the grid
- Step 2 would be to overlap the grid shapefile with the empty nuts3
- Step 3 would be to write a new nuts3 shapefile which contains the
My data and shapefiles can be found through the following link:
- mydata = read.csv("MyData.csv", header = TRUE) #contains coordinates
in latitude and longitude form that represent the centroids of each
“grid”. #mydata also contains 1 variable (random numbers in this case)
that I want to match to the nuts3 regions in the “nuts” shapefile
- grid <- readOGR(".", layer = "grid_025dd") #each grid contains de
centroid coordinates that should be linked to mydata in order to fill all
the grids with the variable of mydata
- nuts <- readOGR(".", layer = "NUTS_RG_60M_2006")
Currently, I am nowhere. Maybe I don’t use the right keywords to google, but mostly, I am not used to working with coordinates. In the previous maps that I made, I was always capable of using some sort of objectid common to the data and the shapefile. Now, this is not the case. There should be an easy way to tell R to use the coordinates of mydata and combine them with the coordinates of the grids, but I can’t figure it out.
Another issue that I face is that the values of the grids in ‘mydata’
should fill up an entire grid. Yet, R recognizes the values as point values.
Could someone please help me and point me in the correct direction for step
1 and 2? I think I should be able to do step 3 on my own.
Thanks a lot for your help! I appreciate it a lot!
[[alternative HTML version deleted]]
R-sig-Geo mailing list
R-sig-Geo at r-project.org
More information about the R-sig-Geo