Geo icon indicating copy to clipboard operation
Geo copied to clipboard

GPX to GeoJson

Open HarelM opened this issue 8 years ago • 3 comments

I'm not sure I'm not missing something here but Assuming I have a GPX file and I want to convert it to geojson, how should I be doing it? I see a separation between GPSData and IO but I'm not sure how to bridge the gap...

HarelM avatar Oct 23 '15 11:10 HarelM

I want to archieve the same but can't figure out how to convert a Gps.GpsData type to an IGeometry.

toburger avatar Nov 15 '22 14:11 toburger

As this was never answered I did not choose to has this library. I suggest to use the net topology suite team packages, they have support for reading and writing GPX files along with ton of other features...

HarelM avatar Nov 15 '22 18:11 HarelM

Thanks for the hint to the other library @HarelM!

In the meantime I managed to transform the data with the following code but I will definitely have a look at the other library (F# code following):

#r "nuget: Geo, 1.0.0"

open Geo
open Geo.IO.GeoJson
open Geo.Abstractions.Interfaces
open Geo.Gps.Serialization

let readGpx filepath =
    let s = Gpx11Serializer()
    let stream = System.IO.File.OpenRead filepath
    s.DeSerialize(new StreamWrapper(stream))

let convertToGeoJson geometry =
    let writer = GeoJsonWriter()
    writer.Write(geometry: IGeometry)

let extractWaypoints (data: Gps.GpsData) =
    data.Waypoints

let extractCoordinates: seq<Gps.Waypoint> -> _ =
    Seq.map (fun x -> x.Coordinate)

"file.gpx"
|> readGpx
|> extractWaypoints
|> extractCoordinates
|> Geometries.LineString
|> convertToGeoJson

toburger avatar Nov 16 '22 07:11 toburger