0 Comments

空间数据的类型(2)

发布于:2013-03-09  |   作者:广州网站建设  |   已聚集:人围观

      线和多边形可能有属性,例如,图1.3a中的140等高线有"在海平面140米以上"的标志,两个封闭的等高线有160米的属性。但在本研究区域,若干个非封闭的等高线拥有110米高的属性。140米等高线多边形里的区域拥有超过海平面140米的属性。超过160米等高线的区域采用带有孔的多边形表示(图1.3d),其中心是火山口的一部分,其低于160米。广州网站建设

图1.3  Maunga Whau(伊甸山)是Auckland火山带近50座火山之一
绘制图1.3的完整代码如下:

  1. > library(sp)  
  2. > data(volcano)  
  3. > grey_gamma <- 2.2  
  4. > grys <- grey.colors(8, 0.55, 0.95, grey_gamma)  
  5. > layout(matrix(c(1,2,1,3,1,4),3,2,byrow=TRUE), c(3,1))  
  6. > image(volcano, axes=Fcol=grysasp=1main="a")  
  7. > contour(volcano, add=T)  
  8. > box()  
  9. > image(volcano, axes=Fcol='white'asp=1main="b")  
  10. > library(maptools)  
  11. > x2 = ContourLines2SLDF(contourLines(volcano))  
  12. > plot(x2, add=T)  
  13. > box()  
  14. > image(volcano, axes=Fcol='white'asp=1main="c")  
  15. > plot(SpatialPolygons(list(Polygons(list(Polygon(coordinates  
  16. + (x2[x2$level == 140,]))), ID="x"))),add = T)  
  17. > box()  
  18. > image(volcano, axes=Fcol=grysasp=1main="d")  
  19. > x3l1 = coordinates(x2[x2$level == 160,])[[1]][[1]]  
  20. > x3l2 = coordinates(x2[x2$level == 160,])[[1]][[2]]  
  21. > x3 = SpatialPolygons(list(Polygons(list(Polygon(x3l1,hole=F),  
  22. + Polygon(x3l2,hole=T)), ID=c("x"))))  
  23. > SP2TRI = function(x, debug = TRUE){  
  24. +    p = x@polygons[[1]] # object of class Polygons  
  25. +    pp1 = p@Polygons[[1]] # outer Polygon  
  26. +    pp2 = p@Polygons[[2]] # inner Polygon  
  27. +    stopifnot(!p1@hole)  
  28. +    stopifnot(p2@hole)  
  29. +    # find nearest point  
  30. +    allcoords = rbind(p1@coords, p2@coords)  
  31. +    n1 = nrow(p1@coords)  
  32. +    n2 = nrow(p2@coords)  
  33. +    dists = as.matrix(dist(allcoords))[((n1+1):(n1+n2)),1:n1]  
  34. +   wm = which.min(dists)[1]  
  35. +    ind1 = (wm %/% n2) + 1  
  36. +    ind2 = wm %% n2  
  37. +    if (debug)  
  38. +        print(c(ind1,ind2))  
  39. +    #plot polygon points:  
  40. +    p1p1c = p1@coords  
  41. +    p2p2c = p2@coords  
  42. +    #plot shortest distance:  
  43. +    if (debug)  
  44. +        lines(rbind(p1c[ind1,], p2c[ind2,]))  
  45. +    if (debug)  
  46. +        points(rbind(p1c, p2c))  
  47. +    p = rbind(p1c[c(ind1:n1,1:ind1),], p2c[c(ind2:n2,1:ind2),], p1c[ind1,])  
  48. +    #polygon(p, col = 'red'border = NULL)  
  49. +    polygon(p, angle=45border = NAdensity = 12)  }  
  50. > plot(x3, col = 'transparent'add = T)  
  51. > SP2TRI(x3, F)  
  52. > box()  

      由火山的等高线形成的多边形通常或多或少有圆形的几何特性。在一般情况下,多边形可以有任意形式,某些情况下,甚至可以重叠。一个特殊但常见的情况是,当它们代表某一类别边界,如行政区时,它们不能重叠,并应该划分整个研究区域,研究区中的每个点可以而且必须归属于一个单一的多边形或处于一个或多个多边形的边界上。广州网站建设

       网格是一种表示空间数据的特殊形式,在每个网格单元中的值代表网格单元对应实际区域的平均值,或单元中心点的值,或其他传感器观测值。在第一种情况下,我们可以将一个网格单元看成是有序点的特例;在第二种情况下,它们是矩形的集合。在任何情况下,可以从网格的位置计算每个单元的位置、单元的大小和网格单元的组织。网格是铺盖平面的常用方式,它们因为如下原因而显得十分重要:

      数码相机和遥感仪器之类的设备基于网格记录数据;

    电脑显示屏和投影仪基于网格显示数据;

      许多空间或时空模型,如气候模型,使用规则网格来离散空间。

飞机