如何将轮廓线变成填充轮廓? [英] How does one turn contour lines into filled contours?

查看:176
本文介绍了如何将轮廓线变成填充轮廓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道一种方法来转换 contourLines 多边形的输出以绘制为填充轮廓,例如 filled.contours 。是否有顺序如何绘制多边形才能查看所有可用层?这是一个无效的代码示例:

Does anyone know of a way to turn the output of contourLines polygons in order to plot as filled contours, as with filled.contours. Is there an order to how the polygons must then be plotted in order to see all available levels? Here is an example snippet of code that doesn't work:

#typical plot
filled.contour(volcano, color.palette = terrain.colors)

#try
cont <- contourLines(volcano)
fun <- function(x) x$level
LEVS <- sort(unique(unlist(lapply(cont, fun))))
COLS <- terrain.colors(length(LEVS))
contour(volcano)
for(i in seq(cont)){
    COLNUM <- match(cont[[i]]$level, LEVS)
    polygon(cont[[i]], col=COLS[COLNUM], border="NA")
}
contour(volcano, add=TRUE)

推荐答案

使用 raster 包的解决方案(调用 rgeos sp )。输出为 SpatialPolygonsDataFrame ,它将覆盖网格中的每个值:

A solution that uses the raster package (which calls rgeos and sp). The output is a SpatialPolygonsDataFrame that will cover every value in your grid:

library('raster')
rr <- raster(t(volcano))
rc <- cut(rr, breaks= 10)
pols <- rasterToPolygons(rc, dissolve=T)
spplot(pols)

这里是一个讨论,它将向您展示如何简化(整理 )生成的多边形。

Here's a discussion that will show you how to simplify ('prettify') the resulting polygons.

这篇关于如何将轮廓线变成填充轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆