1

I want to automatically create two variables from a shape file: 1. a dummy indicator for if a region has a international border and 2. a dummy indicator for if a region has a coastal border.

For example for Guinea variable 1 would be the regions with red dots below, and variable 2 would be with blue dots (I did these by eye).

library(raster)
sd0 <- getData(name = "GADM", country = "GIN", level = 2)
plot(sd0)

enter image description here

There does not seem to be any information in the @data slot for these type of characteristics:

head(sd0@data)
# OBJECTID ID_0 ISO NAME_0 ID_1  NAME_1 ID_2   NAME_2 HASC_2 CCN_2 CCA_2     TYPE_2  ENGTYPE_2 NL_NAME_2
# 1        1   97 GIN Guinea    1    Boké    1    Boffa  GN.BF    NA       Préfecture Prefecture          
# 2        2   97 GIN Guinea    1    Boké    2     Boké  GN.BK    NA       Préfecture Prefecture          
# 3        3   97 GIN Guinea    1    Boké    3     Fria  GN.FR    NA       Préfecture Prefecture          
# 4        4   97 GIN Guinea    1    Boké    4   Gaoual  GN.GA    NA       Préfecture Prefecture          
# 5        5   97 GIN Guinea    1    Boké    5 Koundara  GN.KD    NA       Préfecture Prefecture          
# 6        6   97 GIN Guinea    2 Conakry    6  Conakry  GN.CK    NA       Préfecture Prefecture          
                    

Perhaps they are elsewhere (I have little to no experience with shape files)? Is there a function somewhere that could at least allow me to create a variable that indicates if a region has no outer boundaries (i.e. all those with no dots in the map above)?

guyabel
  • 8,014
  • 6
  • 57
  • 86
  • Do you want to create it by hand or automatically ? By hand, you just have to create a data.frame with the same number of rows than number of polygons and use `cbind` to add it to your SpatialPolygonDataFrame. WIth automatic function, we may be able to find polygons that have a free border, but we will not be able to know if this is the sea or another country. Except if using maps of surrounding countries. – Sébastien Rochette Apr 04 '17 at 06:59
  • @StatnMap automatically – guyabel Apr 04 '17 at 07:18
  • You may have a look at functions of package `rgeos`. You can use `gTouches` to find polygons that have a border in common with the surrounding countries. Or maybe transform your SpatialPolygon as SpatialPoints and use `gDistance` between every point and the closest polygon to find (with a threshold distance), which points are far from a polygon, and thus having no border in common. – Sébastien Rochette Apr 04 '17 at 07:58

0 Answers0