xml 文件中的值

Values from xml file

我有一个 xml 文件,其中包含图像路径名称、GPS 位置和方向。它是一个更大的 xml 文件的子集,该文件 link 将 GPS 位置添加到无人机系统拍摄的图像中。

我感兴趣的 xml 部分看起来像这样的 2 张图片(总共有 180 张左右):

<?xml version="1.0" encoding="UTF8"?>
<images>
    <image path="D:\DCIM0MEDIA\AMBA1124.jpg">
        <time value="2018:04:20 14:47:55"/>
        <gps lat="+05.90003016" lng="-055.22443772" alt="-0069.752" />
        <ori yaw="+124.65" pitch="-090.00" roll="-003.80    " />
    </image>
        <time value="2018:04:20 14:47:57"/>
        <gps lat="+05.89998104" lng="-055.22442246" alt="-0069.802" />
        <ori yaw="+179.79" pitch="-090.00" roll="-005.43    " />
    <image path="D:\DCIM0MEDIA\AMBA1125.jpg">
        <time value="2018:04:20 14:47:59"/>
        <gps lat="+05.89998104" lng="-055.22442246" alt="-0069.802" />
        <ori yaw="+179.79" pitch="-090.00" roll="-005.43    " />
    </image>
        <time value="2018:04:20 14:48:02"/>
        <gps lat="+05.90014408" lng="-055.22444534" alt="-0069.480" />
        <ori yaw="+179.51" pitch="-090.00" roll="-006.32    " />
</images>

xml格式是否正确?我想到了这个:

geofile <- xmlParse(file = "../../../GEOFILE3.xml")
data <- xmlToDataFrame(nodes = getNodeSet(geofile, "/images/image"))

但它一直给我一个空数据 table,尺寸正确...

原文件在这里:link

我使用的提取文件是 geofile3: link

最终我想 link 从 xml 文件到图像的坐标,以便在 Agisoft 中进行图像处理,为此我需要导出为 CSV 格式,如下所示:

Label           X/East      Y/North     Z/Altitude

IMG_0002.JPG    261.638147  46.793178   391.780913  
IMG_0003.JPG    261.638176  46.793470   391.980780  
IMG_0004.JPG    261.638278  46.793908   393.313226  

此致!

我认为您在提取时遇到问题,因为您要查找的值存储为 xml 节点的属性而不是值。

这是一个简单的问题。找到图像节点并提取出感兴趣的属性。我更喜欢使用 xml2 包而不是 XML 包。

library(xml2)

page<-read_xml('<images><image path="D:/DCIM/100MEDIA/AMBA1124.jpg">
        <time value="2018:04:20 14:47:55"/>
               <gps lat="+05.90003016" lng="-055.22443772" alt="-0069.752" />
               <ori yaw="+124.65" pitch="-090.00" roll="-003.80    " />
               </image>
               <time value="2018:04:20 14:47:57"/>
               <gps lat="+05.89998104" lng="-055.22442246" alt="-0069.802" />
               <ori yaw="+179.79" pitch="-090.00" roll="-005.43    " />
               <image path="D:/DCIM/100MEDIA/AMBA1125.jpg">
               <time value="2018:04:20 14:47:59"/>
               <gps lat="+05.89998104" lng="-055.22442246" alt="-0069.802" />
               <ori yaw="+179.79" pitch="-090.00" roll="-005.43    " />
               </image>
               <time value="2018:04:20 14:48:02"/>
               <gps lat="+05.90014408" lng="-055.22444534" alt="-0069.480" />
               <ori yaw="+179.51" pitch="-090.00" roll="-006.32    " />
               </images>')

#extract the image nodes
images<-xml_find_all(page, "image")
#extract out the desired attributes
names<-xml_attr(images, "path")
locations<-xml_find_first(images, "gps")
latitude<-xml_attr(locations, "lat")
longitude<-xml_attr(locations, "lng")
alt<-xml_attr(locations, "alt")

#pack into a dataframe
answer<-data.frame(names, latitude, longitude, alt)