Использование функции coords2country в R для исключительных экономических зон, а не границ страны

Я хочу назначить исключительные экономические зоны страны для точечных данных из растра, где точки представляют уровни насыщения арагонита в океане. Растр представляет собой один слой, который дает значение арагонитов для многих точек широты/долготы в океане. Я хочу назначить каждую точку широты/долготы исключительной экономической зоне. Этот сайт делает это для отдельных пар координат, но у меня есть 15 000 точек, поэтому я надеюсь, что это возможно сделать в Р.

Данные выглядят так:

      long      lat Aragonite
1 20.89833 84.66917  1.542071
2 22.69496 84.66917  1.538187
3 24.49159 84.66917  1.537830
4 26.28822 84.66917  1.534834
5 28.08485 84.66917  1.534595
6 29.88148 84.66917  1.532505

Ранее я использовал приведенный ниже код для назначения стран растровым точкам, но это возвращает NA для многих точек в океане, которые находятся в национальных ИЭЗ.

#convert the raster to points for assigning countries
r.pts <- rasterToPoints(r, spatial = TRUE)

#view new proj 4 string of spatialpointsdataframe
proj4string(r.pts)
##[1] "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"

###converting reclassified points to countries
# The single argument to this function, points, is a data.frame in which:
#   - column 1 contains the longitude in degrees
#   - column 2 contains the latitude in degrees
coords2country = function(r.pts)
{
countriesSP <- getMap(resolution='high')
#countriesSP <- getMap(resolution='high') #you could use high res map from rworldxtra if you were concerned about detail

#setting CRS directly to that from rworldmap
r.pts = SpatialPoints(r.pts, proj4string=CRS(proj4string(countriesSP))) 

# use 'over' to get indices of the Polygons object containing each point 
indices = over(r.pts, countriesSP)
# return the ADMIN names of each country
indices$ADMIN 
#indices$ISO3 # returns the ISO3 code
#indices$continent   # returns the continent (6 continent model)
#indices$REGION   # returns the continent (7 continent model)
}

#get country names for each pair of points
rCountries <- coords2country(r.pts)

Есть ли способ сделать аналогичную функцию для coords2countries, но для ИЭЗ в океане?

РЕДАКТИРОВАТЬ: некоторые данные для воспроизводимого примера

dput(head(r.pts))
structure(list(layer = c(5, 5, 5, 5, 5, 5), x = c(-178.311660375408,-176.511660375408, -174.711660375408, -172.911660375408, -171.111660375408,-169.311660375408), y = c(73.1088933113454, 73.1088933113454,73.1088933113454, 73.1088933113454, 73.1088933113454, 73.1088933113454),.Names = c("layer", "x", "y"),row.names = c(NA, 6L), class = "data.frame") 

person Phoebe Stewart-Sinclair    schedule 12.12.2016    source источник
comment
Пожалуйста, предоставьте dput() образцов данных для воспроизводимости   -  person Hack-R    schedule 12.12.2016
comment
Извините, я сделал это выше с подмножеством данных.   -  person Phoebe Stewart-Sinclair    schedule 13.12.2016


Ответы (1)


Вам нужен шейп-файл, который включает EEZ. Загрузите тот, который находится здесь: World EEZ v9 (21 октября 2016 г., 123 МБ) http://www.marineregions.org/downloads.php#marbound

Вы можете загрузить шейп-файл EEZ с помощью функции readOGR() из пакета rgdal. Разархивируйте шейп-файл EEZ в свой рабочий каталог и запустите countriesSP <- rgdal::readOGR(dsn = ".", layer = "eez_boundaries") вместо countriesSP <- getMap(resolution='high')

Ни один из предоставленных вами примеров данных не попадает в ИЭЗ страны, поэтому я не могу сказать, действительно ли это работает, но, вероятно, должно...

library(sp)
library(rworldmap)
library(rgeos)

r <- read.table(header = TRUE, text = "
long lat Aragonite
1 20.89833 84.66917  1.542071
2 22.69496 84.66917  1.538187
3 24.49159 84.66917  1.537830
4 26.28822 84.66917  1.534834
5 28.08485 84.66917  1.534595
6 29.88148 84.66917  1.532505
")
# or
#r <- data.frame(long = c(-178.311660375408,-176.511660375408, -174.711660375408, -172.911660375408, -171.111660375408,-169.311660375408), 
#                lat = c(73.1088933113454, 73.1088933113454,73.1088933113454, 73.1088933113454, 73.1088933113454, 73.1088933113454))

r.pts <- sp::SpatialPoints(r)

# download file from here: http://www.marineregions.org/download_file.php?fn=v9_20161021
# put the zip file in your working directory: getwd()
unzip('World_EEZ_v9_20161021.zip')

# countriesSP <- rworldmap::getMap(resolution = "high")
# or
countriesSP <- rgdal::readOGR(dsn = ".", layer = "eez_boundaries")

r.pts <- sp::SpatialPoints(r.pts, proj4string = sp::CRS(proj4string(countriesSP))) 
indices <- over(r.pts, countriesSP)
indices$ADMIN
person CJ Yetman    schedule 10.02.2017