[R-sig-Geo] Problems With Cartography 2 - Help

Andrés Peralta tirico85 at gmail.com
Wed May 10 10:27:02 CEST 2017


Hi to everyone,

I`m working with the second administrative level cartography from Ecuador
(available in: http://www.ecuadorencifras.gob.ec//documentos/web-inec/
Cartografia/2015/Clasificador_Geografico/2012/SHP.zip). The shape file is
called nxcantones.shp. I`ve been having a lot of problems opening and
working with this cartography in R; but i can open it in Q-GIS and ARCGIS
without any problem (I have opened it in both programs and saved it again).
As the cartography has various objects with the same ID - aparently the
same areas but repeated; we had to run the following sintax in order to
have one ID in each area:

*carto2012 <- readOGR("CANTONES2012/2012CLEAN.shp", "2012CLEAN",
stringsAsFactors=F) *
*proj4string(carto2012) <- CRS("+proj=utm +zone=17 +south +datum=WGS84
+units=m +no_defs")*

*carto2012x <- unionSpatialPolygons(carto2012, IDs=carto2012$DPA_CANTON)*
*proj4string(carto2012x) <- CRS("+proj=utm +zone=17 +south +datum=WGS84
+units=m +no_defs")*


*datos <- data.frame(ID=row.names(carto2012x), stringsAsFactors = F)*
*row.names(datos) <- row.names(carto2012x)*
*carto2012x2 <- SpatialPolygonsDataFrame(carto2012x, data=datos)*

*carto2012 <- carto2012x2 *

For our work, we had to make a neighborhood matrix of the cartography.

*x.nb <- poly2nb(carto2012u2) # U2 is the cartography after the recode of
some areas that had to be joined.*

*summary(x.nb)*

This seems to work fine. The problem is we need to connect the three island
areas (the Galapagos) but when we try to do so, it connects many areas
along all the cartography. I've tried to do it manually using *edit.nb* but
it does not work. I´ve also tried the following sintaxes:

x.nb1 <- x.nb
which(card(x.nb1)==0) #to discover the id of these areas without connections
id <- function(x){which(carto2012u2$ID==x)}

x.nb1[[id(2001)]] = unique(as.integer(sort(c(x.nb1[[id(2001)]], id(2002)))))
x.nb1[[id(2002)]] = unique(as.integer(sort(c(x.nb1[[id(2002)]], id(2001)))))

x.nb1[[id(2001)]] = unique(as.integer(sort(c(x.nb1[[id(2001)]], id(2003)))))
x.nb1[[id(2003)]] = unique(as.integer(sort(c(x.nb1[[id(2003)]], id(2001)))))

x.nb1[[id(2002)]] = unique(as.integer(sort(c(x.nb1[[id(2002)]], id(2003)))))
x.nb1[[id(2003)]] = unique(as.integer(sort(c(x.nb1[[id(2003)]], id(2002)))))

####
x.nb1[[id("2001")]] = unique(as.integer(sort(c(x.nb1[[id("2001")]],
id("2002")))))
x.nb1[[id("2002")]] = unique(as.integer(sort( id("2001"))))

x.nb1[[id("2001")]] = unique(as.integer(sort(c(x.nb1[[id("2001")]],
id("2003")))))
x.nb1[[id("2003")]] = unique(as.integer(sort( id("2001"))))

x.nb1[[id("2002")]] = unique(as.integer(sort(c(x.nb1[[id("2002")]],
id("2003")))))
x.nb1[[id("2003")]] = unique(as.integer(sort( id("2002"))))

Any ideas or suggestions? Your help will really be appreciated.


-- 

*             Andrés Peralta*
        Pre-doctoral Researcher
     GREDS/EMCONET / ASPB
<https://www.upf.edu/greds-emconet/en/>   <http://aspb.cat/>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list