空间数据处理与分析过程中,一个主要的特点就是对空间对象进行可视化,制作精美的地图图件,本节介绍了空间可视化方法。
- 加载包和数据
#空间数据可视化
#example
library(maptools)
require(rgeos)
#import data
ZZsxq <- readShapePoly("ZZsxq",verbose = TRUE,proj4string = CRS("+init=epsg:27700"))
ZZsxq@data$name <- c("惠济区","金水区","经开区","郑东新区","中原区","二七区","高新区","管城区")
river <- readShapeLines("river",verbose = TRUE,proj4string = CRS("+init=epsg:27700"))
fdc <- readShapePoints("fdc",verbose = TRUE,proj4string = CRS("+init=epsg:27700"))
ZZjiedao <- readShapePoly("ZZjiedao")
ZZbj <- readShapePoly("ZZbj",verbose = TRUE,proj4string = CRS("+init=epsg:27700"))
ZZsxq_line <- readShapeLines("ZZsxq_line",verbose = TRUE,proj4string = CRS("+init=epsg:27700"))
#创建边界
ZZ.outline <- gUnaryUnion(ZZbj,id=NULL)
- 函数包maptools中提供了函数pointLabel、mapscale和north.arrow,分别用于在图件中添加文字标注、比例尺和指南针,以下代码可在之前图件中添加对应制图元素
###制图
#library packages
library(maptools)
library(GISTools)
#plot
plot(ZZjiedao,col="white",lty=2,border="blue")
plot(ZZsxq_line,col="red",lwd=1.5,add=T)
plot(ZZ.outline,lwd=2,add=T)
map.scale(204000,3873000,miles2ft(2),"Miles",2,0.5)
north.arrow(175000,3871000,miles2ft(0.15),col="lightblue")
- 对图层叠加显示,制作个性化地图
###制作个性化地图
#library packages
library(maptools)
library(GISTools)
#plot
plot(ZZjiedao,col="white",lty=2,border="blue")
plot(river,col="turquoise1",lwd=2,add=T)
plot(fdc,col="red",cex=0.2,pch=1,add=T)
plot(ZZsxq_line,col="red",lwd=1.5,add=T)
plot(ZZ.outline,lwd=2,add=T)
map.scale(204000,3873000,miles2ft(2),"Miles",2,0.5)
north.arrow(175000,3871000,miles2ft(0.15),col="lightblue")