Coder Social home page Coder Social logo

kb0 / dart-gpx Goto Github PK

View Code? Open in Web Editor NEW
23.0 6.0 27.0 344 KB

Dart package for load, manipulate, and save GPS data in GPX format (a light-weight XML data format for the interchange of GPS data - waypoints, routes, and tracks).

License: Apache License 2.0

Dart 100.00%
dart-library gpx gpx-reader gpx-writer

dart-gpx's Introduction

gpx

Pub Package Build Status Coverage Status GitHub Issues GitHub Forks GitHub Stars GitHub License

A library for or load, manipulate, and save GPS data in GPX format (https://www.topografix.com/gpx.asp, a light-weight XML data format for the interchange of GPS data - waypoints, routes, and tracks). View the official GPX 1.1 Schema at https://www.topografix.com/GPX/1/1/gpx.xsd.

Also support export from Gpx into:

Getting Started

In your dart/flutter project add the dependency:

 dependencies:
   ...
   gpx: ^2.2.2

Reading XML

To read XML input use the GpxReader object and function Gpx fromString(String input):

import 'package:gpx/gpx.dart';

main() {
  // create gpx from xml string
  var xmlGpx = GpxReader().fromString('<?xml version="1.0" encoding="UTF-8"?>'
      '<gpx version="1.1" creator="dart-gpx library">'
      '<wpt lat="-25.7996" lon="-62.8666"><ele>10.0</ele><name>Monte Quemado</name><desc>Argentina</desc></wpt>'
      '</gpx>');

  print(xmlGpx);
  print(xmlGpx.wpts);
}

Writing XML

To write object to XML use the GpxWriter object and function String asString(Gpx gpx, {bool pretty = false}):

import 'package:gpx/gpx.dart';

main() {
  // create gpx object
  var gpx = Gpx();
  gpx.creator = "dart-gpx library";
  gpx.wpts = [
    Wpt(lat: 36.62, lon: 101.77, ele: 10.0, name: 'Xining', desc: 'China'),
  ];

  // generate xml string
  var gpxString = GpxWriter().asString(gpx, pretty: true);
  print(gpxString);
}

Export to KML

To export object to KML use the KmlWriter object and function String asString(Gpx gpx, {bool pretty = false}):

import 'package:gpx/gpx.dart';

main() {
  // create gpx object
  var gpx = Gpx();
  gpx.creator = "dart-gpx library";
  gpx.wpts = [
    Wpt(lat: 36.62, lon: 101.77, ele: 10.0, name: 'Xining', desc: 'China'),
  ];

  // generate xml string
  var kmlString = KmlWriter().asString(gpx, pretty: true);
  print(kmlString);

  // generate xml string with altitude mode - clampToGround
  var kmlString = KmlWriter(altitudeMode: AltitudeMode.clampToGround)
      .asString(gpx, pretty: true);
  print(kmlString);
}

Limitations

This is just an initial version of the package. There are still some limitations:

  • No support for GPX 1.0.
  • Read/write only from strings.
  • Doesn't validate schema declarations.

Features and bugs

Please file feature requests and bugs at the issue tracker.

License

The Apache 2.0 License, see LICENSE.

dart-gpx's People

Contributors

arthurbcd avatar brvier avatar gabeschine avatar hugoheneault avatar kb0 avatar kimlet avatar sprechen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dart-gpx's Issues

CDATA in name is not working

Hi,
If we have a waypoint with a string as CDATA, then it is not working.
Example:

<wpt lat="42.410045" lon="9.411127">
<ele>710.7</ele>
<time>2022-04-14T08:50:34.924+02:00</time>
<name><![CDATA[Parking]]></name>
<desc><![CDATA[]]></desc>
<type><![CDATA[]]></type>
</wpt>

It is read by the library as a XmlCDATAEvent, with the correct text, but then in the "_readString" method in gpx_reader.dart, it doesn't take this case into account.

Can you fix it?
I can do a PR if you want.

Thank you for your job !

Save GPX file and upload to Strava

Hello,

Kindly need your help how to save a file GPX because I wanna write the GPX file then upload to Strava. Is this library support to Strava?

Thank you

Update xml dependency to 6.0.1

It would be nice if we could update the xml dependency to 6.0.1.
Is there a reason not to do it?

I would love to contribute and create a PR for this.

SDK is Incompatible

Hi,

I tried using "gpx: ^1.1.1" and pub-get returns this error :

Because every version of flutter from sdk depends on meta 1.1.8 and xml >=4.3.0 depends on meta ^1.2.0, flutter from sdk is incompatible with xml >=4.3.0.
And because gpx >=1.0.1+2 depends on xml ^4.3.0, flutter from sdk is incompatible with gpx >=1.0.1+2.
So, because flutter_app depends on both flutter any from sdk and gpx ^1.1.1, version solving failed.
pub get failed (1; So, because flutter_app depends on both flutter any from sdk and gpx ^1.1.1, version solving failed.)

flutter doctor -v

[√] Flutter (Channel stable, 1.20.2, on Microsoft Windows [Version 10.0.18363.1016], locale en-US)
    • Flutter version 1.20.2 at C:\src\flutter
    • Framework revision bbfbf1770c (6 days ago), 2020-08-13 08:33:09 -0700
    • Engine revision 9d5b21729f
    • Dart version 2.9.1

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\LK\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 48.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.

XML 5

Please, give us an update, that allows XML 5.0.0!!!

polygon with points

please, help me with creation of polygon with coordinates on the map. i use flutter google maps package. i need export kml or gpx archive for others programs.

"The file is empty" when uploading to Strava [trkpt vs wpt]

Hi there,

When I upload the file to Strava I get the error message "The file is empty". I think it is because the package uses 'wpt' rather than 'trkpt'. I think Strava only recognizes 'trkpt'. Are there plans to support 'trk' which more represents a track rather than just 'wpt; waypoints?

NB When I manually recreate the same file and replace all 'wpt' references to 'trkpt' and upload manually to Strava it works which is why I think this is the issue.

Any pointers to get around this or plans to add the functionality.

Many thanks..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.