R:计算没有闭合轮廓线的区域

时间:2014-02-04 12:45:11

标签: r area

我想计算0.975等高线内的区域,其中一些不是关闭的。这是情节:

contour(zpropMAteo,  levels = c(0.975),lty = 1,drawlabels = F, col=2)
plot(contorno, add=T )

enter image description here

其中contorno是一个窗口:多边形边界,带有图的连续边框:

str(contorno)
#List of 5
# $ type  : chr "polygonal"
# $ xrange: num [1:2] 704787 727062
# $ yrange: num [1:2] 4239419 4261570
# $ bdry  :List of 1
#  ..$ :List of 4
#  .. ..$ x   : num [1:9188] 704787 705760 705892 706135 706311 ...
#  .. ..$ y   : num [1:9188] 4251037 4248333 4247517 4247191 4246915 ...
#  .. ..$ area: num 1.76e+08
#  .. ..$ hole: logi FALSE
# $ units :List of 3
#  ..$ singular  : chr "unit"
#  ..$ plural    : chr "units"
#  ..$ multiplier: num 1
#  ..- attr(*, "class")= chr "units"
# - attr(*, "class")= chr "owin"

zpropMAteo是像素图片:

str(zpropMAteo)
#List of 10
# $ v     : num [1:99, 1:100] NA NA NA NA NA NA NA NA NA NA ...
#  ..- attr(*, "dimnames")=List of 2
#  .. ..$ : chr [1:99] "4239530.43796768" "4239753.18885493" "4239975.93974217"         "4240198.69062942" ...
#  .. ..$ : chr [1:100] "704898.406701755" "705121.157589002" "705343.908476249"         "705566.659363497" ...
# $ dim   : int [1:2] 99 100
# $ xrange: num [1:2] 704787 727062
# $ yrange: num [1:2] 4239419 4261570
# $ xstep : num 223
# $ ystep : num 224
# $ xcol  : num [1:100] 704898 705121 705344 705567 705789 ...
# $ yrow  : num [1:99] 4239531 4239755 4239978 4240202 4240426 ...
# $ type  : chr "real"
# $ units :List of 3
#  ..$ singular  : chr "unit"
#  ..$ plural    : chr "units"
#  ..$ multiplier: num 1
#  ..- attr(*, "class")= chr "units"
# - attr(*, "class")= chr "im"

正如您在图(右图)中看到的那样,问题在于有开放的轮廓线。也许解决方案可以计算与轮廓线和边界的交点,然后计算内部区域,或者可能首先计算一条轮廓线,它恰好是边界,我不知道,等高线(100%)或类似的东西那...然后获得交叉点和里面的区域。

我试着做

clinessMAteo<-contourLines(zpropMAteo$xcol,zpropMAteo$yrow,zpropMAteo$v,levels =     c(0.975))

有了这个结果:

str(clinessMAteo)
#List of 7
# $ :List of 3
#  ..$ level: num 0.975
#  ..$ x    : num [1:5] 710690 710584 710690 710716 710690
#  ..$ y    : num [1:5] 4246190 4246243 4246296 4246243 4246190
# $ :List of 3
#  ..$ level: num 0.975
#  ..$ x    : num [1:19] 714031 713978 713978 714031 714066 ...
#  ..$ y    : num [1:19] 4245519 4245572 4245796 4245814 4245796 ...
# $ :List of 3
#  ..$ level: num 0.975
#  ..$ x    : num [1:6] 715258 715258 715145 715136 715145 ...
#  ..$ y    : num [1:6] 4260226 4260339 4260510 4260563 4260581 ...
# $ :List of 3
#  ..$ level: num 0.975
#  ..$ x    : num [1:38] 718932 719154 719377 719574 719600 ...
#  ..$ y    : num [1:38] 4256978 4256942 4256891 4256759 4256742 ...
# $ :List of 3
#  ..$ level: num 0.975
#  ..$ x    : num [1:45] 719377 719600 719823 720045 720268 ...
#  ..$ y    : num [1:45] 4255696 4255691 4255710 4255710 4255687 ...
# $ :List of 3
#  ..$ level: num 0.975
#  ..$ x    : num [1:42] 724959 724946 724723 724562 724500 ...
#  ..$ y    : num [1:42] 4253166 4253162 4253138 4252956 4252900 ...
# $ :List of 3
#  ..$ level: num 0.975
#  ..$ x    : num [1:15] 722273 722238 722273 722496 722718 ...
#  ..$ y    : num [1:15] 4251802 4251837 4251858 4251920 4251848 ...

和区域:

areaMASteo <- sum(sapply(clinessMAteo,function(ring){areapl(cbind(ring$x,ring$y))

但我知道它不正确,因为我认为我应该首先关闭轮廓线。

任何想法? : - )

0 个答案:

没有答案