ThinkGeo.com    |     Documentation    |     Premium Support

Convert Gpx file to shape file

Hi,

I would need a help in how to convert GPX file to Shape file. Is there any good example on how to achieve that?

Your help is highly appreciated.
Thanks,
Anwar

Hi Anwar,

Yes, we can read features from GPX feature layer and add these features to shape file.

Here’s the code snippet:

        GpxFeatureLayer gpxLayer = new GpxFeatureLayer("gpx_file");
        gpxLayer.Open();
        Collection<Feature> allFeatures = gpxLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);

        DbfColumn[] dbfColumns = new DbfColumn[] { new DbfColumn("column1", DbfColumnType.Character, 10, 0) };
        ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Point, "shape_file.shp", dbfColumns);

        ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer("point.shp", System.IO.FileAccess.ReadWrite);
        shapeFileLayer.Open();
        ShapeFileFeatureSource shapeFileFeatureSource = ((ShapeFileFeatureSource)shapeFileLayer.FeatureSource);
        shapeFileFeatureSource.BeginTransaction();
        foreach (var item in allFeatures.Take(10))
        {
            shapeFileFeatureSource.AddFeature(item);
        }
        shapeFileFeatureSource.CommitTransaction();

Thanks,
Leo

Hi Leo,

Thank you very much for the quick response and the code snippet.

I will try that out and get back to you if I would face any challenges.

Br,
Anwar

Hi Anwar,

Sure, just let me know if you have any questions.

Thanks,
Leo