1

我正在使用 RGDAL 读取并绘制 geotiff 文件:

df.gtiff = readOGR("/df.tif")
image(df.gtiff, red=1, green=2, blue=3)

该地图包含一些完全平坦的表面,这些表面要么是湖泊,要么是海洋部分,即存在连续像素具有相同高度的斑块。有什么方法可以识别这些补丁,比如多边形,以便我可以统一着色它们(例如蓝色)?[注:文件太大,无法上传,gdalinfo(df.tif)如下所示):

Driver: GTiff/GeoTIFF
Files: ~/df.tif
Size is 2928, 2285
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (81.381111111111110,22.564444444444447)
Pixel Size = (0.002083333333333,-0.002083333333333)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  81.3811111,  22.5644444) ( 81d22'52.00"E, 22d33'52.00"N)
Lower Left  (  81.3811111,  17.8040278) ( 81d22'52.00"E, 17d48'14.50"N)
Upper Right (  87.4811111,  22.5644444) ( 87d28'52.00"E, 22d33'52.00"N)
Lower Right (  87.4811111,  17.8040278) ( 87d28'52.00"E, 17d48'14.50"N)
Center      (  84.4311111,  20.1842361) ( 84d25'52.00"E, 20d11' 3.25"N)
Band 1 Block=2928x1 Type=Byte, ColorInterp=Red
Band 2 Block=2928x1 Type=Byte, ColorInterp=Green
Band 3 Block=2928x1 Type=Byte, ColorInterp=Blue
4

1 回答 1

2

你可能只需要做

image( df.gtiff , col = rep( "cornflowerblue" , ncell(df.gtiff) ) )

但如果这不起作用,这里有一些工作示例:

require( raster )

#  Observe difference between a brick and a raster
logoB <- brick(system.file("external/rlogo.grd", package="raster"))
logoR <- raster(system.file("external/rlogo.grd", package="raster"))

#  Use a brick and plotRGB to get intended colours (image uses heat.colors)
par(mfrow=c(1,2))
image( logoR , axes = FALSE , labels = FALSE )
plotRGB( logoB )

在此处输入图像描述

#  To manually mask and colour to a single value:
#  This file doesn't have NA values so setting e.g. plot( logoR , col = "blue" ) won't work...

#  Example of cell values for background colour
logoB[1]
     red green blue
[1,] 255   255  255

#  Make binary mask with some threshold of 'close to white' or 'close to black' values
newLogo <- calc( logoB , function(x) sum( x ) < 725 + 0 | sum( x ) < 50 + 0 )

#  Then plot, supplying a colour for each binary level
plot(newLogo , col = c( "white" , "cornflowerblue" ) , main = "binary mask" )

在此处输入图像描述

# If your file has background cells set to NA you can just plot directly setting the colour equal to number of cells in raster:

require(maptools)
r <- raster(system.file("external/test.grd", package="raster"))
image( r , col = rep("cornflowerblue" , ncell(r)) , axes = FALSE )

在此处输入图像描述

于 2013-09-06T06:35:03.830 回答