我正在尝试从简单的shapefile加载和绘制图层。它是美国的州界。我可以加载它:
> library("sp","rgdal")
> shape = readOGR("/home/username/data/share/mapnik/world_boundaries/states_EPSG4326.shp", layer="states_EPSG4326")
OGR data source with driver: ESRI Shapefile
Source: "/home/username/data/share/mapnik/world_boundaries/states_EPSG4326.shp", layer: "states_EPSG4326"
with 2895 features and 9 fields
Feature type: wkbPolygon with 2 dimensions
但它无法绘制:
> plot(shape)
There were 50 or more warnings (use warnings() to see the first 50)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: Path drawing not available for this device
2: Path drawing not available for this device
3: Path drawing not available for this device
...
我错过了什么?情节窗口中没有显示任何内容。此shapefile中只有单个图层。我可以在qgis中绘制它,我试图找到替代品。 R似乎是一个受欢迎的选择,但到目前为止我没有太多运气。我用Google搜索了这个警告,但没有发现任何有用的信息。
修改 我尝试过的每个形状文件都会收到相同的响应。这是我验证过的shapefile以相同的方式响应:
http://dds.cr.usgs.gov/pub/data/nationalatlas/statep010_nt00798.tar.gz
这是sessionInfo()的输出:
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C
[4] LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_0.7-22 sp_1.0-2
loaded via a namespace (and not attached):
[1] grid_2.15.2 lattice_0.20-10 tools_2.15.2
这也是一个gentoo系统,在dev-lang / R上启用了以下使用标志:
未启用以下使用标志(未编译的功能):
对我来说只有两个看起来很可疑的是cairo和tk,他们是否需要进行策划?
我从终端跑了R,但结果却相似但不完全相同:
> shape = readOGR("/home/username/Downloads/state/statep010.shp", layer="statep010")
OGR data source with driver: ESRI Shapefile
Source: "/home/username/Downloads/state/statep010.shp", layer: "statep010"
with 62 features and 9 fields
Feature type: wkbPolygon with 2 dimensions
> plot(shape)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border, ... :
Path drawing not available for this device
2: In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border, ... :
Path drawing not available for this device
3: In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border, ... :
Path drawing not available for this device
...
答案 0 :(得分:3)
按照Roger Bivand this thread中的说明使用plot(shape, usePolypath = FALSE)
。
答案 1 :(得分:2)
如果您只对绘制管理边界感兴趣,那么您是否只能使用某些R包提供的数据源?
maps
提供全球行政区域。您也可以检索国家/地区边界。请参阅ggplot here使用的示例。
dismo
提供GADM database的数据。您可以按国家/地区和级别检索数据。
library(maps)
library(raster)
admlim <-getData('GADM', country='USA', level=1)
proj4string(admlim) <- CRS('+init=epsg:4326')
# plot(admlim) # plain plot
# dataframe for ggplot()
# This will take a long, long time for USA level 1 data from GADM
t.adm <- fortify(admlim)
ggplot(aes(long, lat, group = group), data = t.adm,
colour = 'grey20', fill = NA) +
geom_path() +
scale_y_continuous(breaks=(-2:2) * 30) +
scale_x_continuous(breaks=(-4:4) * 45) +
coord_map('ortho', orientation=c(41, -74, 0))
答案 2 :(得分:0)
我有同样的问题,可以在安装libcairo2-dev和libpango1.0-dev之后再次编译R来解决它
关于debian:
sudo apt install libcairo2-dev
sudo apt install libpango1.0-dev
我确信之前特别是libpango1.0-dev丢失了。然后我用了
./configure --prefix=/.../.../R --with-cairo
make && make install
并修复了它。
希望它有所帮助。