Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create GPX file from GeoPoints

Is there any way to export GeoPoints into a GPX file?

@Override
public void onLocationChanged(android.location.Location location) {
        lat = location.getLatitude();
        lon = location.getLongitude();
        currGeo = new GeoPoint((int)(lat*1e6),(int)(lon*1e6));

        //Store GeoPoint to GPX file
    }

I've read How to parse and plot gpx file has an android MapView, but I'm looking for a more simpler solution.

like image 675
JiTHiN Avatar asked Aug 23 '12 11:08

JiTHiN


People also ask

How do you create a GPX file?

Go to 'routes → choose the route → click 'view' → Choose 'send to device' OR click on 'More', select 'Classic mode' 'export', select GPX Track (. gpx)direct to NEW FOLDER (if Garmin connected to PC) (OR save to a specific file for later use.)

Can you create a GPX file from Google maps?

To use Maps to GPX, paste your Google Maps URL into the box provided on the website, then press the Let's Go button (or hit enter on your keyboard). The site will instantly create a GPX file for you to download. Provide a suitable filename, then save it to your PC.

How do I convert shapefile to GPX?

Convert Shp to GPX – Using IGIS Map ToolGo to Igis Map Conversion Tool . Login with registered id and password or if you are new then register with valid email id. Then tap on Switch To button select conversion in the drop down list. Upload your file from system or drive or from drop box.


1 Answers

If you ONLY want to generate a GPX file from a list of geopoints, the simplest way would be to just blast strings into a file. Not knowing the exact format of GPX, I'm making a lot of the details up, but you should know the format you're generating. For Example, in pseudocode:

// open file handle
OutputStream fout = getFileOutputStream("gpxFile.gpx");
fout.write("<gpx>");
for (GeoPoint gp : listOfGeoPoints) {
    fout.write("<gpxPoint>" + getGeoPointAsStringForFile(gp) + "</gpxPoint>"); 
}
fout.write("</gpx>");
// close file, cleanup, etc

This would require you to implement the getFIleOutputStream() method and the getGeoPointAsStringForFile() method, but you know what format you're aiming for, and this'll let you just create the file without having to go through a lot of hoops.

  • It should be noted that this is incredibly fragile, so do it the right way before you go live, but this is a short version quick fix.
like image 62
Travis Avatar answered Sep 30 '22 11:09

Travis