0

readOGR (パッケージ 'rgdal' から) を使用してシェープファイルをインポートし、SpatialPolygonsDataFrame を取得しました。(パッケージ「raster」の)「rasterize」機能を使用すると、これが得られます

http://img15.hostingpics.net/pics/427269plot.png

しかし、エッジのみをラスタライズしたいので、このような GeoTiff を取得できます

http://img15.hostingpics.net/pics/270288Rplot.png

4

2 に答える 2

3

これは、オブジェクトタイプを使用してrasterとを使用して行うことができます。この例を試して、インポートしたシェープファイル名に置き換えてください。spSpatialLinesspdf

spdf <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1]) # Read in your datafile. You can use readOGR or readShapePoly, it doesn't really matter.
sldf <- as( spdf , "SpatialLinesDataFrame") # Create a lines object. This gives you the borders of the polygons
r <- raster( nrow = 180 , ncols = 360 , ext = extent(spdf) ) # Create a template raster file which will form the mask you will rasterzie to (so if you want a more precise 
r <- rasterize( sldf , r ) # Depending on the resolution of your target raster and the complexity of your shapefile this may take a few seconds or a few minutes to run

必要に応じてラスターファイルを保存できます。

plot( spdf )
plot( r )

ここに画像の説明を入力してください ここに画像の説明を入力してください

于 2013-03-07T12:26:17.640 に答える
0

一般に、このポリゴン データを にプロットするにはggplot2:

library(ggplot2)
# Convert the SpatialPolygons object to a data.frame, which ggplot2 needs
poly_data_frame = fortify(poly_spatialpolygon)
ggplot(poly_data_frame, aes(x = x, y = y)) + geom_polygon(fill = "transparent")
ggsave("poly_plot.png")

これで、ポリゴン内に色のない PNG ファイルのポリゴン プロットが作成されます。

于 2013-02-26T21:04:22.617 に答える