Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

While plotting the gadm map of Russia in R, I have a problem at the 180 degree meridian, where part of the Russian region is plotted separately. You can see it on the plot using the following code (it's the edge left and part is on the right). Can anyone suggest how to avoid this problem? Thanks in advance.

Here is a short version of the code for my question:

require(sp)

rus<-url("http://www.gadm.org/data/rda/RUS_adm1.RData")
print(load(rus))
gadm$regions = as.factor(1:88)
spplot(gadm,"regions")

Map

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Project the data. This example uses a polar stereographic projection centered near the middle of Russia (longitude 105 degrees east):

require(rgdal)
proj4.str <- CRS("+init=epsg:3413 +lon_0=105")
gadm.prj <- spTransform(gadm, proj4.str)
spplot(gadm.prj, "regions")

Map

The problem region is in the upper right. You can see that this region has been split into two pieces and, by virtue of the projection, reassembled into a contiguous area: the common boundary is visible. That's how it is in the data: it is explicitly represented as two separate features. To remove the visible split, you would need to merge the two pieces (an operation much more easily done with a GIS than with R).

share|improve this answer
    
Thank you sooooo much! –  Ruvin Rafailov Jun 11 '13 at 20:00
    
Just one more stupid question, please, if you do not mind, I'm wondering how it can be done to plot just one polygon from the map, like Moscow only for example –  Ruvin Rafailov Jun 11 '13 at 20:35
2  
The help page for sp mentions that this class supports " methods including print/show, plot, subset, [, [[, \$, names, dim, summary,..." The help page for subset shows its syntax. The trick is knowing which field to use for finding Moscow! I found it by looking at unique values of all the fields, finally alighting on levels(gadm$NAME_1). This led to spplot(subset(gadm.prj, subset=(NAME_1=="Moskva")),"regions"), which does the trick. –  whuber Jun 11 '13 at 20:45
    
got it! thank you very much again, you really saved me, I had a problem as I didnt't know about subset syntaxis –  Ruvin Rafailov Jun 11 '13 at 20:57

I see that whuber already beat me to it, but I will post my answer anyways.

If you want to keep the data in the longlat projection, you can add the "Longitudinal Wrapping" parameter to the Proj4 string.

library(rgdal)

p4 <- projection(gadm)
p4_new <- paste(p4, "+lon_wrap=105")

gadm_new <- spTransform(gadm, CRS(p4_new))
spplot(gadm_new, "regions")

This will center your map at longitude 105 degrees east. enter image description here

share|improve this answer
1  
+1 It's nice to see this option available in spTransform. –  whuber Jun 11 '13 at 19:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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