All Projects → jenetics → Jpx

jenetics / Jpx

Licence: apache-2.0
JPX - Java GPX library

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Jpx

orange3-geo
🍊 🌍 Orange add-on for dealing with geography and geo-location
Stars: ✭ 22 (-82.4%)
Mutual labels:  gps, geolocation
Googleapi
C# .NET Core Google Api (Maps, Places, Roads, Search, Translate). Supports all endpoints and requests / responses.
Stars: ✭ 346 (+176.8%)
Mutual labels:  geolocation, geocoding
kirby-locator
A simple map & geolocation field, built on top of open-source services and Mapbox. Kirby 3 only.
Stars: ✭ 83 (-33.6%)
Mutual labels:  geocoding, geolocation
Atlas
🌎 Atlas is a set of APIs for looking up information about locations
Stars: ✭ 21 (-83.2%)
Mutual labels:  geocoding, gps
Spyme
Rails plugin that stores the browser geolocation
Stars: ✭ 108 (-13.6%)
Mutual labels:  geolocation, geocoding
trackanimation
Track Animation is a Python 2 and 3 library that provides an easy and user-adjustable way of creating visualizations from GPS data.
Stars: ✭ 74 (-40.8%)
Mutual labels:  gps, geolocation
Ulogger Server
μlogger • web viewer for tracks uploaded with μlogger mobile client
Stars: ✭ 315 (+152%)
Mutual labels:  gps, geolocation
radar-sdk-android
Android SDK for Radar, the leading geofencing and location tracking platform
Stars: ✭ 57 (-54.4%)
Mutual labels:  geocoding, geolocation
Geo On Fire
A library to create high performance geolocation queries for Firebase. Checkout the demos: https://run.plnkr.co/plunks/AYaN8ABEDcMntgbJyLVW/ and https://run.plnkr.co/plunks/xJgstAvXYcp0w7MbOOjm/
Stars: ✭ 54 (-56.8%)
Mutual labels:  geolocation, geocoding
Pelias Android Sdk
Android sdk for pelias
Stars: ✭ 20 (-84%)
Mutual labels:  geolocation, geocoding
Geocoding-with-Map-Vector
Resources for the ACL 2018 publication "Which Melbourne? Augmenting Geocoding with Maps", published in July 2018.
Stars: ✭ 24 (-80.8%)
Mutual labels:  geocoding, geolocation
Pgeocode
Postal code geocoding and distance calculation
Stars: ✭ 92 (-26.4%)
Mutual labels:  geolocation, geocoding
geocoder
Geocoder is a Typescript library which helps you build geo-aware applications by providing a powerful abstraction layer for geocoding manipulations
Stars: ✭ 28 (-77.6%)
Mutual labels:  geocoding, geolocation
React Native Radar
React Native module for Radar, the leading geofencing and location tracking platform
Stars: ✭ 104 (-16.8%)
Mutual labels:  geolocation, geocoding
cordova-plugin-radar
Cordova plugin for Radar, the leading geofencing and location tracking platform
Stars: ✭ 14 (-88.8%)
Mutual labels:  geocoding, geolocation
Rxgps
Finding current location cannot be easier on Android !
Stars: ✭ 307 (+145.6%)
Mutual labels:  gps, geocoding
Geolocation
Flutter geolocation plugin for Android and iOS.
Stars: ✭ 205 (+64%)
Mutual labels:  gps, geolocation
Skylift
Wi-Fi Geolocation Spoofing with the ESP8266
Stars: ✭ 223 (+78.4%)
Mutual labels:  gps, geolocation
Leaflet Geosearch
(Leaflet) GeoSearch / GeoCode provider
Stars: ✭ 666 (+432.8%)
Mutual labels:  geolocation, geocoding
P5.geolocation
a geolocation and geofencing library for p5.js
Stars: ✭ 75 (-40%)
Mutual labels:  gps, geolocation

JPX

Build Status Maven Central Javadoc Code Quality: Java Total Alerts

JPX is a Java library for creating, reading and writing GPS data in GPX format. It is a full implementation of version 1.1 and version 1.0 of the GPX format. The data classes are completely immutable and allows a functional programming style. They are working also nicely with the Java 8 Stream API. It is also possible to convert the location information into strings which are compatible to the ISO 6709 standard.

Beside the basic functionality of reading and writing GPX files, the library also allows to manipulate the read GPX object in a functional way.

Dependencies

No external dependencies are needed by the JPX library. It only needs Java 11 to compile and run.

Building JPX

For building the JPX library you have to check out the master branch from Github.

$ git clone https://github.com/jenetics/jpx.git

Executing the tests:

$ cd jpx
$ ./gradlew test

Building the library:

$ ./gradlew jar

Examples

Creating new GPX object with 3 track-points

final GPX gpx = GPX.builder()
    .addTrack(track -> track
        .addSegment(segment -> segment
            .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(160))
            .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(161))
            .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(162))))
    .build();

Writing GPX object to a file

GPX.write(gpx, "track.gpx");

GPX output

<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="JPX - Java GPX library" xmlns="http://www.topografix.com/GPX/1/1">
    <trk>
        <trkseg>
            <trkpt lat="48.2081743" lon="16.3738189">
                <ele>160.0</ele>
            </trkpt>
            <trkpt lat="48.2081743" lon="16.3738189">
                <ele>161.0</ele>
            </trkpt>
            <trkpt lat="48.2081743" lon="16.3738189">
                <ele>162.0</ele>
            </trkpt>
        </trkseg>
    </trk>
</gpx>

Reading GPX object from file

This example writes a given GPX object to a file, reads it again and prints the WayPoints of all tracks and all track-segments to the console.

GPX.write(gpx, "track.gpx");
GPX.read("gpx.xml").tracks()
    .flatMap(Track::segments)
    .flatMap(TrackSegment::points)
    .forEach(System.out::println);

Console output

$ [lat=48.2081743, lon=48.2081743, ele=160]
$ [lat=48.2081743, lon=48.2081743, ele=161]
$ [lat=48.2081743, lon=48.2081743, ele=162]

Reading GPX extensions

The library is also able to read arbitrary GPX extensions.

<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="JPX - Java GPX library" xmlns="http://www.topografix.com/GPX/1/1">
    ...
    <extensions>
        <gpxdata:lap xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0">
            <gpxdata:index>1</gpxdata:index>
            <gpxdata:startPoint lat="51.219983" lon="6.765224"/>
            <gpxdata:endPoint lat="51.220137" lon="6.765098" />
        </gpxdata:lap>
    </extensions>
</gpx>

The extensions are available via a org.w3c.dom.Document object, with an extensions root element.

final Optional<Document> extensions = gpx.getExtensions();

Reading GPX 1.0 and writing GPX 1.1

By default, JPX is reading and writing the GPX files in version 1.1. But it is possible to read and write GPX files in version 1.0 as well.

// Reading GPX 1.0 file.
final GPX gpx10 = GPX.reader(GPX.Version.V10).read("track-v10.gpx");

// Changing GPX version to 1.1.
final GPX gpx11 = gpx10.toBuilder()
	.version(GPX.Version.V11)
	.build();

// Writing GPX to file.
GPX.write(gpx11, "track-v11.gpx");

ISO 6709 location strings

With the LocationFormatter class it is possible to create ISO 6709 compatible strings.

final Point p = WayPoint.of(...);
final Location loc = Location.of(p);
final LocationFormatter format = LocationFormatter.ISO_HUMAN_LONG;
System.out.println(format.format(loc));

The printed location will look like this

24°59'15.486"N 65°14'03.390"W 65.23m

It is also possible to define your own formatter from a given pattern string,

final LocationFormatter format = 
    LocationFormatter.ofPattern("DD°MMSS dd°mmss");

which leads to the following output

24°5915 65°1403

This string can then also be parsed to a location.

final Location location = format.parse("24°5915 65°1403");

Geodetic calculations

Distance between two points

final Point start = WayPoint.of(47.2692124, 11.4041024);
final Point end = WayPoint.of(47.3502, 11.70584);
final Length distance = Geoid.WGS84.distance(start, end);
System.out.println(distance);

Console output

$ 24528.356073554987 m

Path length

Calculate the path length of the first track-segment.

final Length length = gpx.tracks()
    .flatMap(Track::segments)
    .findFirst()
    .map(TrackSegment::points).orElse(Stream.empty())
    .collect(Geoid.WGS84.toPathLength());

GPX manipulation/filtering

Filtering

The following example filters empty tracks and track-segments from an existing GPX object.

final GPX gpx = GPX.read("track.gpx");

// Filtering empty tracks.
final GPX gpx1 = gpx.toBuilder()
    .trackFilter()
        .filter(Track::nonEmpty)
        .build()
    .build();

// Filtering empty track-segments.
final GPX gpx2 = gpx.toBuilder()
    .trackFilter()
        .map(track -> track.toBuilder()
            .filter(TrackSegment::nonEmpty)
            .build())
        .build()
    .build();

// Filtering empty tracks and track-segments.
final GPX gpx3 = gpx.toBuilder()
    .trackFilter()
        .map(track -> track.toBuilder()
            .filter(TrackSegment::nonEmpty)
            .build())
        .filter(Track::nonEmpty)
        .build()
    .build();

Changing GPX object

Fixing the time of all track way-points by adding one hour.

final GPX gpx = GPX.read("track.gpx");

final GPX gpx1 = gpx.toBuilder()
    .trackFilter()
        .map(track -> track.toBuilder()
            .map(segment -> segment.toBuilder()
                .map(wp -> wp.toBuilder()
                    .time(wp.getTime()
                        .map(t -> t.plusHours(1))
                        .orElse(null))
                    .build())
                .build())
            .build())
        .build()
    .build();

Doing the same only for the GPX way-points.

final GPX gpx = GPX.read("track.gpx");

final GPX gpx1 = gpx.toBuilder()
    .wayPointFilter()
        .map(wp -> wp.toBuilder()
            .time(wp.getTime()
                .map(t -> t.plusHours(1))
                .orElse(null))
            .build())
        .build()
    .build();

XML configuration

The JPX library uses the XML classes available in the Java java.xml module. This API is highly configurable and it is possible to replace the underlying implementation. Especially for Android, using different XML implementation is a necessity. JPX uses three factory classes for reading/writing GPX files:

  1. XMLInputFactory: This class is needed for reading GPX files.
  2. XMLOutputFactory: This class is needed for writing GPX files.
  3. DocumentBuilderFactory: This class is used for creating XML-documents for the GPX extensions data.

You can change the used classes by implementing and registering a different XMLProvider class. The following code show how to change the configuration of the DocumentBuilderFactory class.

package org.acme;
final class ValidatingDocumentBuilder extends XMLProvider { 
    @Override
    public DocumentBuilderFactory documentBuilderFactory() { 
        final DocumentBuilderFactory factory = 
            DocumentBuilderFactory.newInstance();
        factory.setValidating(true);
        factory.setNamespaceAware(true);
        return factory; 
    }
}

And don't forget to create a META-INF/services/io.jenetics.jpx.XMLProvider file with the following content:

org.acme.NonValidatingDocumentBuilder

License

The library is licensed under the Apache License, Version 2.0.

Copyright 2016-2021 Franz Wilhelmstötter

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Release notes

2.2.0

Improvements

  • #72: Parsing of ISO 6709 location strings (thanks to bunkenburg). This also contains fixes in the ISO 6709 location formatter.
  • #140: Add WayPoint factory methods taking Instant.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].