In preparation for my class at AU 2012 Las Vegas, From Mobile and Through the Cloud to AutoCAD Civil 3D, I needed to convert the coordinates of a point captured with my phone to active project coordinate system. This is required to place the photo (taken with the phone camera) at the correct project location.
The basic code came from this blog post, but you may notice that this applies to Map 3D and do not work for Civil 3D. So below is the modified version. Note this requires some additional references not commonly used on Civil 3D development.
/// <summary>
/// Convert the point from LL84 (GPS Coordinate System) into
/// Civil 3D active document coordinate system
/// </summary>
/// <remarks>
/// Requires C:\Program Files\Autodesk\
/// AutoCAD Civil 3D 2013\OSGeo.MapGuide.Geometry.dll
/// Requires C:\Program Files\Autodesk\
/// AutoCAD Civil 3D 2013\OSGeo.MapGuide.Foundation.dll
/// </remarks>
public static Point3d ConvertPointCoordinate(
Point3d point_LL84)
{
MgCoordinate coord = null;
if (CSTransform != null &&
!double.IsNaN(point_LL84.Z))
coord = CSTransform.Transform(
point_LL84.X, point_LL84.Y, point_LL84.Z);
else
coord = CSTransform.Transform(
point_LL84.X, point_LL84.Y);
return new Point3d(
coord.X, coord.Y, coord.Z);
}
private static MgCoordinateSystemTransform
_cstransform = null;
/// <summary>
/// Get the Coordinate System Transform.
/// </summary>
private static
MgCoordinateSystemTransform
CSTransform
{
get
{
if (_cstransform != null)
return _cstransform;
// get Civil3D current coordinate system
CivilDocument civilDoc =
CivilApplication.ActiveDocument;
string code = civilDoc.Settings.
DrawingSettings.UnitZoneSettings.
CoordinateSystemCode;
// get the transformation
MgCoordinateSystemFactory coordSysFactory
= new MgCoordinateSystemFactory();
MgCoordinateSystem coordSys =
coordSysFactory.CreateFromCode(code);
MgCoordinateSystem wgs84Sys =
coordSysFactory.Create("LL84");
// convert the coordinates
_cstransform = coordSysFactory.
GetTransform(wgs84Sys, coordSys);
return _cstransform;
}
}
See you in Las Vegas!