2013-04-30 334 views
1

承蒙@AriBFriedman和@PaulHiemstra,随后建议搞清楚如何合并.SHP文件,我已成功使用下面的代码和数据产生以下地图:如何添加一个shp文件来修改地图边界?

数据:

MoroccoWestern Sahara

代码:

# Loading administrative coordinates for Morocco maps 
    library(sp) 
    library(maptools) 
    library(mapdata) 

    # Loading shape files 
    Mor <- readShapeSpatial("F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/Country-CGE/MAR_adm1.shp") 
    Sah <- readShapeSpatial("F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/Country-CGE/ESH_adm1.shp") 

    # Ploting the maps individually 
    png("Morocco.png") 
    Morocco <- readShapePoly("F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/Country-CGE/MAR_adm1.shp") 
    plot(Morocco) 
    dev.off() 

    png("WesternSahara.png") 
    WesternSahara <- readShapePoly("F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/Country-CGE/ESH_adm1.shp") 
    plot(WesternSahara) 
    dev.off() 

    # Merged map of Morocco and Western Sahara 

    MoroccoData <- rbind([email protected],[email protected]) # First, 'stack' the attribute list rows using rbind() 
    MoroccoPolys <- c([email protected],[email protected]) # Next, combine the two polygon lists into a single list using c() 

    # summary(MoroccoData) 
    # summary(MoroccoPolys) 

    offset <- length(MoroccoPolys) # Next, generate a new polygon ID for the new SpatialPolygonDataFrame object 

    browser() 
    for (i in 1: offset) 
    { 
    sNew = as.character(i) 
    MoroccoPolys[[i]]@ID = sNew 
    } 

    ID <- c(as.character(1:length(MoroccoPolys))) # Create an identical ID field and append it to the merged Data component 
    MoroccoDataWithID <- cbind(ID,MoroccoData) 

    MoroccoPolysSP <- SpatialPolygons(MoroccoPolys,proj4string=CRS(proj4string(Sah))) # Promote the merged list to a SpatialPolygons data object 

    Morocco <- SpatialPolygonsDataFrame(MoroccoPolysSP,data = MoroccoDataWithID,match.ID = FALSE) # Combine the merged Data and Polygon components into a new SpatialPolygonsDataFrame. 

    [email protected]$id <- rownames([email protected]) 
    Morocco.fort <- fortify(Morocco, region='id') 
    Morocco.fort <- Morocco.fort[order(Morocco.fort$order), ] 

    MoroccoMap <- ggplot(data=Morocco.fort, aes(long, lat, group=group)) + 
    geom_polygon(colour='black',fill='white') + 
    theme_bw() 

结果:

个个别地图

Morocco Western Sahara

合并后的地图:

Morocco-Merged

问:

我想消除通过地图的中间切割边界?任何人有任何建议和/或帮助?

THX所有

回答

0

我没有做到这一点,通过使用QGIS软件,它是免费的,在这个环节QGIS

下载合并后削减在地图中两个额外的面层消除