Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.
/ dart-gpx Public archive
forked from kb0/dart-gpx

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

Notifications You must be signed in to change notification settings

sun-jiao/dart-gpx

 
 

Repository files navigation

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 import to and export from Gpx into:

Getting Started

In your dart/flutter project add the dependency:

 dependencies:
   ...
   gpx: ^2.2.1

Reading GPX

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

import 'package:gpx/gpx.dart';

main() async {
  // create gpx from xml string
  var xmlGpx = await 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);
}

To read GPX from a Stream<String>:

import 'package:gpx/gpx.dart';

main() async {
  // create gpx from xml string stream
  final stream = File('test/assets/wpt.gpx').openRead()
      .transform(utf8.decoder);
  final kml = await KmlReader()
      .fromStream(stream);

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

Writing GPX

To write object to GPX 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);
}

Reading KML

To read KML input use the KmlReader object and function Gpx fromString(String input):

import 'package:gpx/gpx.dart';

main() async {
  // create gpx from xml string
  var xmlGpx = await KmlReader().fromString('<?xml version="1.0" encoding="UTF-8"?> '
      '<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Placemark><name>Monte Quemado</name>'
      '<description>Argentina</description> <ExtendedData/>'
      '<Point><altitudeMode>absolute</altitudeMode>'
      '<coordinates>-62.8666,-25.7996,10.0</coordinates></Point></Placemark>'
      '</Document></kml>');

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

To read KML from a Stream<String>:

import 'package:gpx/gpx.dart';

main() async {
  // create gpx from xml string stream
  final stream = File('test/assets/wpt.kml').openRead()
      .transform(utf8.decoder);
  final kml = await KmlReader()
      .fromStream(stream);

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

Writing 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.
  • 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.

About

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).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 100.0%