wmap <- readOGR(dsn="~/R/funwithR/data/ne_110m_land", layer="ne_110m_land")
Run Code Online (Sandbox Code Playgroud)
此代码未加载形状文件,并生成错误
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open file
Run Code Online (Sandbox Code Playgroud)
我确信该目录是正确的.最后/也不存在,图层名称也正确.
在ne_110m_land目录文件中我有:
ne_110m_land.dbf
ne_110m_land.prj
ne_110m_land.shp
ne_110m_land.shx
ne_110m_land.VERSION.txt
ne_110m_land.README.html
Run Code Online (Sandbox Code Playgroud) 我想安装rgdal的"R version 3.2.3 (2015-12-10)".我下载并安装了
然后在RStudio我打字install.packages("rgdal")给了我这个:
> ....
>
> configure: CC: clang configure: CXX: clang++ configure: rgdal:
> 1.1-1 checking for /usr/bin/svnversion... yes configure: svn revision:
> 572 checking for gdal-config...
> no no configure: error: gdal-config
> not found or not executable. ERROR: configuration failed for package
> ‘rgdal’
> * removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgdal’
> Warning in install.packages : installation of package ‘rgdal’ had
> non-zero exit status …Run Code Online (Sandbox Code Playgroud) 如何在shapefile之后保留多边形的信息?让我试着解释一下:
我有一个包含这些数据的shapefile:
> head(mapa@data)
ID CD_GEOCODI TIPO CD_GEOCODB NM_BAIRRO CD_GEOCODS NM_SUBDIST CD_GEOCODD NM_DISTRIT CD_GEOCODM NM_MUNICIP NM_MICRO NM_MESO
12228 33679 431490205000133 URBANO 431490205003 Cidade Baixa 43149020500 <NA> 431490205 PORTO ALEGRE 4314902 PORTO ALEGRE PORTO ALEGRE METROPOLITANA DE PORTO ALEGRE
12229 33680 431490205000134 URBANO 431490205003 Cidade Baixa 43149020500 <NA> 431490205 PORTO ALEGRE 4314902 PORTO ALEGRE PORTO ALEGRE METROPOLITANA DE PORTO ALEGRE
12230 33681 431490205000135 URBANO 431490205003 Cidade Baixa 43149020500 <NA> 431490205 PORTO ALEGRE 4314902 PORTO ALEGRE PORTO ALEGRE METROPOLITANA DE PORTO ALEGRE …Run Code Online (Sandbox Code Playgroud) 我试图从顶点位置创建一组多边形,以X,Y格式保存.
以下是我的数据示例 - 每行代表一个多边形的顶点.多边形是正方形
square <- rbind(c(255842.4, 4111578, 255862.4, 4111578, 255862.4, 4111558,
255842.4, 4111558, 255842.4, 4111578, 255842.4, 4111578),
c(257397.0, 4111309, 257417.0, 4111309, 257417.0, 4111289,
257397.0, 4111289, 257397.0, 4111309, 257397.0, 4111309))
ID <- c("SJER1", "SJER2")'
Run Code Online (Sandbox Code Playgroud)
我正在使用SpatialPolygons,因此我的数据需要在列表中.所以我创建了一个循环来尝试从矩阵中将我的数据转换为列表格式.
我创建了一个循环代码,我在本网站的其他一些问题中找到了代码.我打破了每一步,试图理解为什么我只得到一个多边形作为输出,即使我有2组点.
for (i in 1:2) {
pts <- rbind(c(square[i,1], square[i,2]), c(square[i,3], square[i,4]),
c(square[i,5],square[i,6]), c(square[i,7],square[i,8]),
c(square[i,9],square[i,10]))
sp1 <- list(Polygon(pts))
sp2 <- list(Polygons(sp1,i))
sp = SpatialPolygons(sp2)
}
plot(sp)
Run Code Online (Sandbox Code Playgroud)
你能帮我理解我如何调整代码来写出两个多边形而不是一个多边形吗?而且,如果我使用矩阵(方形)作为我的起始数据集,我如何为每个多边形分配ID,如果我指定了一个字符ID,它会将我的所有数据转换为一个字符.
我的最终目标是SpatialPolygons对象中的两个多边形,第一个具有ID SJER1,第二个具有SJER2存储在SpatialPolygons对象中的ID .
然后我会把它写到shapefile中.
我找到了一个如何做到这一点的相当简单的例子,但我无法让它为我工作.我是R的新手
library(rgdal)
xy <- cbind(c(118, 119), c(10, 50))
project(xy, "+proj=utm +zone=51 ellps=WGS84")
[,1] [,2]
[1,] -48636.65 1109577
[2,] 213372.05 5546301
Run Code Online (Sandbox Code Playgroud)
但这是示例数字.我有成千上万的坐标需要转换,我无法弄清楚如何将它们从我的表中转移到这个脚本中
我的数据集有3列,ID,X和Y.如何使用这个等式转换它们?我已经坚持了几个星期
我的问题与从 PROJ4 升级到 PROJ6 引起的变化以及各种 R 空间包 ( sp, sf, raster) 中的后果有关。
我们现在收到很多关于“废弃数据”的警告,看起来有点令人担忧,我有点困惑我应该怎么做。我可以看到这在某些情况下会产生可怕的后果,而在其他情况下可以忽略它们。
似乎我不是唯一一个有点迷茫的人(见这里)。我希望我提出的带有特定可重现示例的问题将有助于我们更好地理解该主题。
我知道我们可以删除警告,并且我已经阅读了上下文:r-spatial 博客文章、 迁移到 PROJ6/GDAL3 和这些研讨会笔记(mapview 在更新的版本中似乎以不同的方式处理此问题)
问题 1:
可能是一个幼稚的问题:
我知道需要在 PROJ6 中实现新的符号/格式(WKT)(例如,因为需要更高的精度),但我不明白为什么需要从旧的 proj4 字符串中删除数据部分符号。为什么不保持原样(并以新的 WKT 格式/符号实现新功能)
问题2 :
似乎我们有 3 个关于旧 proj4 格式的数据丢失的案例:
sf默认?)sp默认 ?? )下面的例子说明了我们有这些警告的不同情况。
为什么我们在同一个 CRS 上有这 3 个不同的案例(这里是 EPSG 31370)?
删除基准和/或+towgs84零件的后果是什么?
我应该对第二个警告比第三个更不担心吗? …
我已经readShapePoly在maptools包中读取了shapefile ,但无法读取同一个文件readOGR.我希望有人可以帮助我阅读shapefile readOGR.
我orcounty.shp从这里下载了文件:http://geography.uoregon.edu/geogr/topics/maps.htm
我也下载了相关文件:orcounty.shx,orcounty.sbx,orcounty.sbn,和orcounty.dbf,并把所有五个文件的文件夹中:c:/users/mark w miller/gis_in_R/shapefile_example/
以下代码读取shapefile并显示一些属性:
library(maptools)
setwd('c:/users/mark w miller/gis_in_R/shapefile_example/')
# Oregon county census data (polygons)
orcounty.poly <- readShapePoly('orcounty.shp', proj4string=CRS("+proj=longlat"))
orcounty.line <- readShapeLines('orcounty.shp', proj4string=CRS("+proj=longlat"))
# see projection
summary(orcounty.poly)
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
x -124.55840 -116.46944
y 41.98779 46.23626
Is projected: FALSE
proj4string : [+proj=longlat]
Data attributes:
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用以下代码读取相同的shapefile时,我收到一个错误:
library(rgdal)
# read shapefile
oregon.map <- readOGR(dsn="c:/users/mark …Run Code Online (Sandbox Code Playgroud) 如何在shapefile对象后面绘制"栅格"对象?两者都可以自己绘制,但是这些点不会覆盖栅格:
require(rgdal)
require(maptools)
require(raster)
myproj = "+proj=utm +zone=12 +north +ellps=WGS84 +units=m"
shp = readShapeSpatial(fn.shp, proj4string = CRS(myproj))
ras = raster(fn.tif)
plot(ras)
plot(shp, bg="transparent", add=TRUE)
Run Code Online (Sandbox Code Playgroud) 我rgdal adn rgoes在redhat linux机器上编译包时遇到错误.我试图做一些研究,但找不到可能的解决方案.能不能帮我解决这个问题,因为这对我来说非常重要.
**ERROR WHILE COMPILING RGDAL in R 3.0**
**strong text**
* installing *source* package ârgdalâ ...
** package ârgdalâ successfully unpacked and MD5 sums checked
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: rgdal: 0.8-10
checking for /usr/bin/svnversion... yes
configure: svn revision: 496
configure: gdal-config: gdal-config
checking gdal-config usability... ./configure: line 1397: gdal-config: command not found
no
Error: gdal-config not found
The gdal-config script distributed with GDAL could not be found.
If you have not …Run Code Online (Sandbox Code Playgroud) 当我加载 rgdal 包时,我一直注意到这条消息:
“请注意,rgdal 将于 2023 年底退役,计划尽早使用 GDAL 和 PROJ 过渡到 sf/stars/terra 功能。”
我不知道这意味着什么。这是否意味着有一些 sf/stars/terra 函数使用 rgdal 而其他函数则不使用?或者这是否意味着 sf/stars/terra 根本不使用 rgdal,并且我应该使用这些软件包而不是其他依赖 rgdal 的软件包?
哪些依赖 rgdal 的常见软件包会受到影响?