소스 검색

add support for gpx upload

subDesTagesMitExtraKaese 4 달 전
부모
커밋
ba2734e251

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 7 - 0
static/gps_logger/GPXParser.js/GPXParser.min.js


+ 21 - 0
static/gps_logger/GPXParser.js/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Lucas Trebouet Voisin
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 164 - 0
static/gps_logger/GPXParser.js/README.md

@@ -0,0 +1,164 @@
+![GPXParser](https://raw.githubusercontent.com/Luuka/gpx-parser/feature/new-demo/demo/Logo.png)
+
+# GPXParser.js
+
+![](https://github.com/Luuka/gpx-parser/workflows/master-ci/badge.svg) ![](https://github.com/Luuka/gpx-parser/workflows/develop-ci/badge.svg)
+
+*GPXParser.js* is a lightweight JS library wich parse .gpx file and get or compute various datas like
+- GPX metadata
+- total and cumulate distances
+- min, max, average, positive and negative height différence
+
+# GPX ? What is this ?
+
+Wikipedia say :
+> GPX, or GPS Exchange Format, is an XML schema designed as a common GPS data format for software applications.
+
+gpx files are based on xml with specific tags and attributes
+
+For more information about gpx format see http://www.topografix.com/gpx_manual.asp
+
+# How to do
+
+### Install from npm
+`npm install --save gpxparser` 
+
+### Load JavaScript file
+
+From an HTML document :
+```html
+<script src="./js/GPXParser.js"></script>
+```
+
+From a node.js script :
+```js
+let gpxParser = require('gpxparser');
+```
+
+### Create and parse file
+```js
+var gpx = new gpxParser(); //Create gpxParser Object
+gpx.parse("<xml><gpx></gpx></xml>"); //parse gpx file from string data
+```
+
+### Use the gpx Object
+
+```js
+var totalDistance = gpx.tracks[0].distance.total;
+```
+
+### Export gpxParser Objecto to GeoJSON
+
+```js
+let geoJSON = gpx.toGeoJSON();
+```           
+
+# Documentation
+
+| Property  | Type | Description|
+| ------------- | ------------- | ------------- |
+| xmlSource | XML | XML Object parsed from gpx string file |
+| metadata | Metadata object | File metadata |
+| waypoints | Array of Waypoint object | Array of waypoints |
+| tracks | Array of Track object | Array of waypoints of tracks |
+| routes | Array of Route object | Array of waypoints of routes |
+
+## Metadata object
+
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| name      | String | File name |
+| desc      | String | Description |
+| link      | Link object | Web address  |
+| author    | Float  | Author object    |
+| time      | DateTime  | Time   |
+
+
+## Waypoint object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| name     | String | Point name |
+| cmt      | String | Comment           |
+| desc     | String | Point description |
+| lat      | Float  | Point latitute    |
+| lon      | Float  | Point longitude   |
+| ele      | Float  | Point elevation   |
+| time     | Date   | Point time        |
+
+## Track object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| name     | String | Point name |
+| cmt      | String | Comment           |
+| desc     | String | Point description |
+| src      | String | Used device           |
+| number      | String | Track identifier           |
+| link      | String | Link to a web address           |
+| type      | String | Track type           |
+| points      | Array | Points object array |
+| distance      | Distance Object | Distance informations about the Route |
+| elevation      | Elevation Object | Elevation informations about the Route |
+| slopes      | Float Array | Slope of each sub-segment|
+
+
+## Route object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| name     | String | Point name |
+| cmt      | String | Comment           |
+| desc     | String | Point description |
+| src      | String | Used device           |
+| number      | String | Track identifier           |
+| link      | String | Link to a web address           |
+| type      | String | Route type           |
+| points      | Array | Points object array    |
+| distance      | Distance Object | Distance informations about the Route |
+| elevation      | Elevation Object | Elevation informations about the Route |
+| slopes      | Float Array | Slope of each sub-segment|
+
+
+## Point object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| lat      | Float  | Point latitute    |
+| lon      | Float  | Point longitude   |
+| ele      | Float  | Point elevation   |
+| time     | Date   | Point time        |
+
+
+## Distance object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| total      | Float  | Total distance of the Route/Track    |
+| cumul      | Float  | Cumulative distance at each point of the Route/Track   |
+
+
+## Elevation object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| max      | Float  | Maximum elevation   |
+| min      | Float  | Minimum elevation  |
+| pos      | Float  | Positive elevation difference  |
+| neg      | Float  | Negative elevation difference  |
+| avg      | Float  | Average elevation |
+
+
+## Author object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| name      | String  | Author name   |
+| email      | Email object  | Email address of the author |
+| link      | Link object  | Web address |
+
+## Email object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| id      | String  | Email id   |
+| domain | String  | Email domain |
+
+## Link  object
+| Property | Type   | Description       |
+| -------- | ------ | ----------------- |
+| href      | String  | Web address |
+| text      | String  | Link text |
+| type      | String  | Link type |

+ 31 - 2
static/gps_logger/js/preprocessor.js

@@ -127,10 +127,15 @@ function importFiles(fileList) {
   plot = $.plot("#placeholder", d, options);
   markersToUpload = {}
   for (const file of fileList) {
-    if(file.name?.toLowerCase().endsWith(".txt"))
+    extension = file.name?.toLowerCase().split('.').pop()
+    if(extension === "txt")
       readTxtFile(file)
-    else if (file.name?.toLowerCase().endsWith(".nmea"))
+    else if (extension === "nmea")
       parseNmeaFile(file)
+    else if (extension === "gpx")
+      parseGpxFile(file)
+    else
+      console.log(`unsupported file type (${extension})`)
   }
   document.getElementById("upload-btn").style.display = "inline";
 }
@@ -205,6 +210,30 @@ function parseNmeaFile(file) {
   reader.readAsText(file)
 }
 
+function parseGpxFile(file) {
+  const reader = new FileReader()
+
+  reader.addEventListener('load', (event) => {
+    let gpx = new gpxParser()
+    gpx.parse(event.target.result)
+    let result = []
+    for (const track of gpx.tracks) {
+      for (const point of track.points) {
+        result.push({
+          timestamp: point.time,
+          lat: point.lat,
+          lng: point.lon,
+          alt: point.ele,
+          hdop: null,
+          speed: null
+        })
+      }
+    }
+    process(file.name, result)
+  });
+  reader.readAsText(file)
+}
+
 let markersToUpload;
 
 function process(name, markers) {

+ 1 - 0
templates/gps_logger/upload.html

@@ -55,4 +55,5 @@
 <script language="javascript" type="text/javascript" src="{% static 'gps_logger/flot/jquery.flot.navigate.min.js' %}"></script>
 <script src="{% static 'gps_logger/js/preprocessor.js' %}" type="text/javascript"></script>
 <script src="{% static 'gps_logger/GPS.js/GPS.min.js' %}" type="text/javascript"></script>
+<script src="{% static 'gps_logger/GPXParser.js/GPXParser.min.js' %}" type="text/javascript"></script>
 {% endblock %}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.