Class GPX.Writer

java.lang.Object
io.jenetics.jpx.GPX.Writer
Enclosing class:
GPX

public static final class GPX.Writer extends Object
Class for writing GPX files. A writer instance can be created by the GPX.writer factory methods.
Since:
1.3
Version:
3.0
  • Field Details

  • Method Details

    • indent

      Return the indentation string this GPX writer is using.
      Returns:
      the indentation string
      Since:
      3.0
    • maximumFractionDigits

      public int maximumFractionDigits()
      Return the maximum number of digits allowed in the fraction portion of the written numbers like latitude and longitude.
      Returns:
      the maximum number of digits allowed in the fraction portion of the written numbers
    • write

      public void write(GPX gpx, Result result) throws IOException
      Writes the given gpx object to the given result. This is the most general way for writing GPX objects.

      The following example shows how to create an XML-Document from a given GPX object.

      final GPX gpx = ...; final Document doc = XMLProvider.provider() .documentBuilderFactory() .newDocumentBuilder() .newDocument(); // The GPX data are written to the empty `doc` object. GPX.Writer.DEFAULT.write(gpx, new DOMResult(doc));
      Parameters:
      gpx - the GPX object to write to the output
      result - the output document
      Throws:
      IOException - if the writing of the GPX object fails
      NullPointerException - if one of the given arguments is null
      Since:
      3.0
    • write

      public void write(GPX gpx, OutputStream output) throws IOException
      Writes the given gpx object (in GPX XML format) to the given output stream. The caller of this method is responsible for closing the given output stream.
      Parameters:
      gpx - the GPX object to write to the output
      output - the output stream where the GPX object is written to
      Throws:
      IOException - if the writing of the GPX object fails
      NullPointerException - if one of the given arguments is null
    • write

      public void write(GPX gpx, Path path) throws IOException
      Writes the given gpx object (in GPX XML format) to the given path.
      Parameters:
      gpx - the GPX object to write to the output
      path - the output path where the GPX object is written to
      Throws:
      IOException - if the writing of the GPX object fails
      NullPointerException - if one of the given arguments is null
    • write

      public void write(GPX gpx, File file) throws IOException
      Writes the given gpx object (in GPX XML format) to the given file.
      Parameters:
      gpx - the GPX object to write to the output
      file - the output file where the GPX object is written to
      Throws:
      IOException - if the writing of the GPX object fails
      NullPointerException - if one of the given arguments is null
    • write

      public void write(GPX gpx, String path) throws IOException
      Writes the given gpx object (in GPX XML format) to the given path.
      Parameters:
      gpx - the GPX object to write to the output
      path - the output path where the GPX object is written to
      Throws:
      IOException - if the writing of the GPX object fails
      NullPointerException - if one of the given arguments is null
    • toString

      public String toString(GPX gpx)
      Create an XML string representation of the given gpx object.
      Parameters:
      gpx - the GPX object to convert to a string
      Returns:
      the XML string representation of the given gpx object
      Throws:
      NullPointerException - if the given GPX object is null
      See Also:
    • of

      public static GPX.Writer of(GPX.Writer.Indent indent, int maximumFractionDigits)
      Return a new GPX writer with the given indent and number formatter, which is used for formatting WayPoint.getLatitude(), WayPoint.getLongitude(), ...

      The example below shows the lat and lon values with maximal 5 fractional digits.

      <trkpt lat="45.78068" lon="12.55368"> <ele>1.2</ele> <time>2009-08-30T07:08:21Z</time> </trkpt>
      The following table should give you a feeling about the accuracy of a given fraction digits count, at the equator.
      Maximum fraction digits accuracy
      Fraction digits Degree Distance
      0 1 111.31 km
      1 0.1 11.13 km
      2 0,01 1.1 km
      3 0.001 111.3 m
      4 0.0001 11.1 m
      5 0.00001 1.11 m
      6 0.000001 0.1 m
      7 0.0000001 11.1 mm
      8 0.00000001 1.1 mm
      9 0.000000001 0.11 mm
      Parameters:
      indent - the element indentation
      maximumFractionDigits - the maximum number of digits allowed in the fraction portion of a number
      Returns:
      a new GPX writer
      Since:
      3.0
      See Also:
    • of

      public static GPX.Writer of(GPX.Writer.Indent indent)
      Return a new GPX writer with the given indent and with maximum fraction digits of DEFAULT_FRACTION_DIGITS.
      Parameters:
      indent - the element indentation
      Returns:
      a new GPX writer
      Since:
      3.0
      See Also: