readOGR (パッケージ 'rgdal' から) を使用してシェープファイルをインポートし、SpatialPolygonsDataFrame を取得しました。(パッケージ「raster」の)「rasterize」機能を使用すると、これが得られます
http://img15.hostingpics.net/pics/427269plot.png
しかし、エッジのみをラスタライズしたいので、このような GeoTiff を取得できます
readOGR (パッケージ 'rgdal' から) を使用してシェープファイルをインポートし、SpatialPolygonsDataFrame を取得しました。(パッケージ「raster」の)「rasterize」機能を使用すると、これが得られます
http://img15.hostingpics.net/pics/427269plot.png
しかし、エッジのみをラスタライズしたいので、このような GeoTiff を取得できます
これは、オブジェクトタイプを使用してraster
とを使用して行うことができます。この例を試して、インポートしたシェープファイル名に置き換えてください。sp
SpatialLines
spdf
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 )
一般に、このポリゴン データを にプロットするには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 ファイルのポリゴン プロットが作成されます。