Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support merging multiple paths together #16

Open
HarelM opened this issue Aug 11, 2018 · 3 comments
Open

Support merging multiple paths together #16

HarelM opened this issue Aug 11, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@HarelM
Copy link
Contributor

HarelM commented Aug 11, 2018

Some devices do not know how to handle GPX tracks well (Mainly Gramin).
I have some code in my site that converts all the tracks to a single route.
And some code to convert all track segments to a single segment.
I thought this library might be a good fit for this logic.
Below is the code - assuming issue #12 is resolved:
Single segment:

            var singleTrackGpx = new GpxMainObject
            {
                Waypoints = gpx.Waypoints,
                Routes = new List<GpxRoute>(),
                Tracks = (gpx.Tracks ?? new List<GpxTrack>()).Select(t => new GpxTrack(
                    name: t.Name,
                    description: t.Description,
                    comment: t.Comment,
                    segments: new [] { new GpxTrackSegment(new ImmutableGpxWaypointTable(t.Segments.SelectMany(s => s.Waypoints)), null) }.ToImmutableArray(),
                    source: t.Source,
                    links: t.Links,
                    number: t.Number,
                    classification: t.Classification,
                    extensions: t.Extensions)).ToList()
            };

Single route:

            var routes = gpx.Routes ?? new List<GpxRoute>();
            routes.AddRange((gpx.Tracks ?? new List<GpxTrack>()).Select(t => new GpxRoute(
                name: t.Name,
                description: t.Description,
                comment: t.Comment,
                waypoints: new ImmutableGpxWaypointTable(t.Segments.SelectMany(s => s.Waypoints)),
                source: null, links: ImmutableArray<GpxWebLink>.Empty, number: null, classification: null, extensions: null
            )));
            var routeGpx = new GpxMainObject
            {
                Waypoints = gpx.Waypoints,
                Routes = routes.ToList(),
                Tracks = new List<GpxTrack>(),
            };
@airbreather airbreather added the enhancement New feature or request label Aug 11, 2018
@HarelM
Copy link
Contributor Author

HarelM commented Aug 28, 2018

@airbreather Do you think this code will make it to this library or not?
I'm asking since I'm working on upgrading NTS libraries and would like to do it in a single commit, I don't mind waiting a bit for this to be implemented in order to remove the code from my repository.

@airbreather
Copy link
Member

Do you think this code will make it to this library or not?

Probably not for a while. The main purpose of NetTopologySuite.IO.GPX is to convert back and forth between NTS and GPX.

IMO, the data model here isn't a really great foundation to actually build on for your application's own domain model, since it's primarily driven by the constraints of having to match a >14-year-old XML schema. So I'd expect this use case to be handled somewhat "automatically", via a process like:

  • Load your own domain model, perhaps from a GPX file provided by the user
  • Do whatever your application does
  • Export your domain model, perhaps to a GPX file that you build via whatever constraints are imposed by your target device

@HarelM
Copy link
Contributor Author

HarelM commented Aug 28, 2018

I have my own domain model, don't worry :-), but I think it's easier to convert GPX data to GPX data when one need to save to file in a specific way, otherwise I'll need to write almost the same conversion logic on every "scenario" instead of simple manipulations.
GPX maybe old, but it's one of the most common formats I've seen to be used, so I'm guessing it's here to stay.

@airbreather airbreather changed the title Support GPX manipulation Support merging multiple paths together Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants