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

GPX to geoJson #45

Open
Svashta opened this issue Dec 23, 2021 · 2 comments
Open

GPX to geoJson #45

Svashta opened this issue Dec 23, 2021 · 2 comments

Comments

@Svashta
Copy link

Svashta commented Dec 23, 2021

Not really an issue, more like a question/help/feature request maybe.

I would like to convert a GPX file to geoJson format and then display it using MapBox.

Maybe it's just my limited knowledge, but I don't find any proper way of doing it, not with this gem or any other similar solutions.

Furthermore, would it be possible to extract, calculate elevation gains and drops from the data in GPX.

Generally, I am using Strava gpx from either activity or routes, and I would like to draw it on a MapBox enabled map plus have some additional information with it.

Sorry for maybe very simple question.
Thx

@niborg
Copy link
Collaborator

niborg commented Jan 24, 2022

This gem does allow you to convert GPX to Geojson. Did you look at the README?

@niborg
Copy link
Collaborator

niborg commented Jan 24, 2022

Woops got confused, converts GeoJSON to GPX.

If you create a GPX file using this library, you should be able to construct a GeoJSON object using the .tracks and/or .routes methods. Each of those methods will return objects that respond to .lat and .lon. E.g.

coords = gpx.tracks.each_with_object([]) do |point, coll|
  coll << [point.lon, point.lat]
end
geojson_feature = {
  type: 'LineString',
  geometry: {
    coordinates: coords
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants