ios使用gpx_使用JavaScript处理GPX轨道

ios使用gpx

GPS data can be stored in a really long variety of formats, but GPX, Garmin’s TCX and google’s KML are the most widely used.

GPS数据可以很多种格式存储,但是GPX ,Garmin的TCX和google的KML是使用最广泛的格式。

Most of our GPS capable wearables let you export your data in GPX format, and that’s what we are going to analyze.

我们大多数具有GPS功能的可穿戴设备都可以让您以GPX格式导出数据,这就是我们要分析的内容。

GPX格式 (The GPX format)

GPX documents are just XML files that store geographical coordinates.

GPX文档只是存储地理坐标的XML文件。

They contain a metadata header, followed by waypoints, routes, and tracks. There’s also an extensions section for custom elements. You can check the whole schema here.

它们包含一个元数据标头,后跟路标路线track 。 还有一个自定义元素的扩展部分。 您可以在此处检查整个架构。

Routes are designed to be followed and tracks are more like breadcrumb trails, storing real data from an activity.

路线被设计成遵循和轨道更像面包屑小径,从活动存储的真实数据。

Image for post
A Route and one track exploring it.
一条路线和一条探索它的轨道。
  • Route: an ordered list of waypoints, representing a series of turn points leading to a destination. It also stores information about the route itself.

    路线:航点的有序列表,代表通往目的地的一系列转折点。 它还存储有关路线本身的信息。

  • Waypoint: basic element of a GPX track. It holds the latitude and longitude coordinates, elevation, timestamp and metadata for every point on a track/route. They may have a name, a description and all sorts of information under extensions.

    航点: GPX轨道的基本元素。 它保存轨迹/路线上每个点的纬度经度坐标 ,海拔,时间戳和元数据。 它们的扩展名下可能有名称,描述和各种信息。

  • Track: an ordered list of track points describing a path. They can (and should but it depends on the implementation) be divided in track segments if the GPS collection is lost.

    轨迹:描述路径的轨迹点的有序列表。 如果丢失了GPS采集,则可以(而且应该取决于实施方式)将它们划分为航迹。

  • Track point: Just a waypoint on a track.

    航迹点:只是航迹上的一个航路点。

One GPX file can contain multiple routes or tracks, each one consisting in multiple segments.

一个GPX文件可以包含多个路径或轨道,每个路径或轨道都包含多个段。

Tracks are the subject of our interest while parsing GPS data, because they are the raw information that may need processing.

在解析GPS数据时,轨迹是我们感兴趣的主题,因为它们是可能需要处理的原始信息。

解析GPX (Parsing the GPX)

Every manufacturer is responsible of generating valid GPX, but it is not always the case. The format even enforces including the URL of the software that generates it so people is able to contact its creator in case it fails to validate.

每个制造商都有责任生成有效的GPX,但并非总是如此。 该格式甚至强制包括生成该软件的软件的URL,因此人们可以在验证失败的情况下联系其创建者。

Even with valid GPX, there’s many ways a device can generate the file, different time intervals between track points, different extensions, precision, divided track segments…

即使使用有效的GPX,设备也可以通过多种方式生成文件,跟踪点之间的时间间隔不同,扩展名,精度,分割的轨道段……

In this example we will center our parsing on Amazfit Bip’s exported data. This cheap GPS device stores just one track with a track point every 1 (or more seconds) with decent accuracy except for the elevation. It also gives you your heart rate measurement in extensions.

在此示例中,我们将以Amazfit Bip的导出数据为中心进行解析。 这种便宜的GPS设备每隔1(或更多秒)就可以存储一条轨迹,且轨迹点具有很高的精度(海拔高度除外)。 它还可以扩展您的心率测量。

The format depends on the exporting tool used. In this case it’s more or less well formatted and valid GPX, but I’ve seen tools generating invalid code.

格式取决于使用的导出工具。 在这种情况下,它的格式或多或少是有效的GPX,但我见过生成无效代码的工具。

You can could just use any XML parser, but I’d recommend gpx-parser-builder.

您可以只使用任何XML解析器,但我建议使用gpx-parser-builder

Every export tools I tested on my Amazfit Bip / Bip S stored all the information in one track (<trk>) with one track segment (<trkseg>) so I’ll be getting just those track points. We’ll be doing calculations that may not be accurate if we mix separate track segment’s data (since devices should separate it in segments when the GPS signal is lost).

我在Amazfit Bip / Bip S上测试的每个导出工具都将所有信息存储在一个轨道( <trk> )中,并且具有一个轨道段( <trkseg> ),因此我将仅获得这些轨道点。 如果我们混合单独的航迹段的数据,我们将进行的计算可能不准确(因为当GPS信号丢失时,设备应将其分成几段)。

This is how our file looks after parsing.

这是我们的文件在解析后的外观。

使用您的GPX数据 (Using your GPX data)

So now that you have access to your track’s data… what?

那么现在您可以访问曲目的数据了……什么?

Well we can use it to enhance its information, the basic being calculating distances and speed. Some devices (for example the Bip S) give you the speed at each track point but it does not have to be the case.

好吧,我们可以使用它来增强其信息,其基本原理是计算距离和速度。 某些设备(例如Bip S )可为您提供每个跟踪点的速度,但并非必须如此。

There’s many ways of calculating distances with GPS coordinates, we’ll go with the Haversine formula which assumes the earth is a perfect spherical object.

使用GPS坐标计算距离的方法很多 ,我们将采用Haversine公式 ,该公式假设地球是一个完美的球形物体。

Using it and estimating Earth’s radius in 6371km we can calculate distances in meters between two waypoints like this.

使用它并估算6371 km中的地球半径,我们可以像这样计算两个航路点之间的距离(以米为单位)。

Now we can iterate over our waypoints and “enhance” them with more information, like the distance from the previous point or the average velocity of the segment, etc.

现在,我们可以遍历我们的航路点,并通过更多信息“增强”它们,例如到上一个点的距离或路段的平均速度等。

现在怎么办 (What now)

Now you could do any sort of calculations with this data depending on what you want to do. Extract analytics from your tracks, draw an elevation diagram or just show the track on a map with enhanced information.

现在,您可以根据需要对这些数据进行任何类型的计算。 从轨迹中提取分析数据,绘制立面图或仅在地图上显示带有增强信息的轨迹。

In my case I use my watch while I surf so I want to identify how many waves I catch, when I am riding a wave, how long it is, my average speed riding it and show all this information on a map of waves for a session.

在我的情况下,我在冲浪时使用手表,所以我想确定我捕捉了多少波浪,当我骑波浪时,它持续多长时间,我平均骑行速度,并在海浪地图上显示所有这些信息,会议。

翻译自: https://medium.com/trabe/processing-gpx-tracks-using-javascript-c2b0afa71e55

ios使用gpx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值