Ask Your Question

Revision history [back]

As geodesy seems to be the most official way to convert between geographic and UTM coordinates, here are some code snippets, which worked for me. Start with:

#include <geodesy/utm.h>

For coordinate conversions, you need data of type geographic_msgs::GeoPoint and geodesy::UTMPoint:

  geographic_msgs::GeoPoint geo_pt;
  geo_pt.latitude = latitude;
  geo_pt.longitude = longitude;
  geo_pt.altitude = altitude;
  geodesy::UTMPoint utm_pt(geo_pt);

Don't forget to add geodesy to your CMakeLists.txt:

find_package(catkin REQUIRED COMPONENTS geodesy)

Now you are good to go with your UTM data.

As geodesyGeodesy seems to be the most official way to convert between geographic latitude/logitude and UTM coordinates, coordinates. As I wasn't able to find any code examples, here are some code snippets, lines, which worked for me. Start with:

#include <geodesy/utm.h>

For coordinate conversions, you need data of type geographic_msgs::GeoPoint and geodesy::UTMPoint:geodesy::UTMPoint.

Example for Lat/Lon -> UTM conversion:

  geographic_msgs::GeoPoint geo_pt;
  geo_pt.latitude = latitude;
  geo_pt.longitude = longitude;
  geo_pt.altitude = altitude;
  geodesy::UTMPoint utm_pt(geo_pt);

Example for UTM -> Lat/Lon conversion:

  geodesy::UTMPoint utm_pt(easting, northing, altitude, zone, band);
  geographic_msgs::GeoPoint geo_pt;
  geo_pt = geodesy::toMsg(utm_pt);

Don't forget to add geodesy to your CMakeLists.txt:

find_package(catkin REQUIRED COMPONENTS geodesy)

Now you are good to go with your UTM data.