gpt4 book ai didi

gpx - 使用 writeOGR {rgdal} 写入 gpx 文件时出错

转载 作者:行者123 更新时间:2023-12-03 23:59:27 26 4
gpt4 key购买 nike

我正在尝试使用 writeOGR 创建点的 gpx 文件。 writeOGR() 将创建一个没有错误的 shp 文件,但如果我尝试编写 KML 或 GPX 文件,我会收到此错误。我在 Windows 上使用 R 3.1.1 和 rgdal 0.8-16(我在 7 和 8 上试过,同样的问题)。

writeOGR(points, driver="KML", layer="random_2014",dsn="C:/Users/amvander/Downloads")
Error in writeOGR(points, driver = "KML", layer = "random_2014", dsn = "C:/Users/amvander/Downloads") :
Creation of output file failed

它在地理坐标中,我已经发现这很重要

summary(points)
Object of class SpatialPointsDataFrame
Coordinates:
min max
x -95.05012 -95.04392
y 40.08884 40.09588
Is projected: FALSE
proj4string :
[+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0]
Number of points: 20
Data attributes:
x y ID
Min. :-95.05 Min. :40.09 Length:20
1st Qu.:-95.05 1st Qu.:40.09 Class :character
Median :-95.05 Median :40.09 Mode :character
Mean :-95.05 Mean :40.09
3rd Qu.:-95.05 3rd Qu.:40.09
Max. :-95.04 Max. :40.10

str(points)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 20 obs. of 3 variables:
.. ..$ x : num [1:20] -95 -95 -95 -95 -95 ...
.. ..$ y : num [1:20] 40.1 40.1 40.1 40.1 40.1 ...
.. ..$ ID: chr [1:20] "nvsanc_1" "nvsanc_2" "nvsanc_3" "nvsanc_4" ...
..@ coords.nrs : num(0)
..@ coords : num [1:20, 1:2] -95 -95 -95 -95 -95 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "x" "y"
..@ bbox : num [1:2, 1:2] -95.1 40.1 -95 40.1
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"

任何人都可以提供有关如何解决此错误的任何指导吗?

这是我使用的文件和代码。

https://www.dropbox.com/sh/r7kz3p68j58c189/AACH0U_PLH7Y6cZW1wdFLQTOa/random_2014

最佳答案

您已经知道这些格式将只接受地理坐标(lat-long,而不是投影)并且至少对于 GPX 文件,允许的字段非常有限,例如名称的“name”,高程的“ele”和“time”获取日期时间信息。您文件中的@data 字段与那些字段不匹配,因此会导致错误。可以使用

编写这些额外字段
dataset_options="GPX_USE_EXTENSIONS=yes"

在这种情况下,它们将作为子类添加到“扩展”字段中,但许多简单的 gps 接收器不会读取或使用这些字段。要创建一个带有名称的非常​​简单的航点文件,请使用以下过程。

#I will use your dataset points

#if not already re-project your points as lat-long
ll_points <- spTransform(points, CRS("+proj=longlat + ellps=WGS84"))

# use the ID field for the names
ll_points@data$name <- ll_points@data$ID

#Now only write the "name" field to the file
writeOGR(ll_points["name"], driver="GPX", layer="waypoints",
dsn="C:/whateverdir/gpxfile.gpx")

对我来说,这执行并创建了一个工作的 gpx 文件,我的 gps 接受了显示的名称。

关于gpx - 使用 writeOGR {rgdal} 写入 gpx 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25064823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com