Map3d point3d to Coordinate in C#

dwattersQJ39E
Explorer
Explorer

Map3d point3d to Coordinate in C#

dwattersQJ39E
Explorer
Explorer

Hello, 
I am looking to get the Lat/Long value of a point3d (x,y,0) 

I have a coordinate system set (AZ83-CF for this example) 
and I am using a blocks position as my point3d. 

I have done this in LISP before but now need to perform this as part of a larger C# program. 

 

(setq ename (car ent))
(setq start_pnt (cadr ent))
(setq PROJECTIONSOURCE (ade_projgetwscode))
(ade_projsetsrc PROJECTIONSOURCE)
(ade_projsetdest "LL84")
(setq longlat (ade_projptforward start_pnt))

 

 

Thanks for any help. 

0 Likes
Reply
Accepted solutions (1)
330 Views
3 Replies
Replies (3)

hosneyalaa
Advisor
Advisor
Accepted solution
0 Likes

dwattersQJ39E
Explorer
Explorer

this looks promising! 
i believe what i am actually looking for is TransformToLonLatAlt
but this looks like it will put me on the right path. 
thanks! 

0 Likes

dwattersQJ39E
Explorer
Explorer

 for anyone else :

private static bool HasGeoData(Database db)

{

    // Check whether the drawing already has geolocation data



    bool hasGeoData = false;

    try

    {

        var gdId = db.GeoDataObject;

        hasGeoData = true;

    }

    catch { }

    return hasGeoData;

}
private static Tuple<Point3d, string> TranslateGeoPoint(Database db, Point3d inPt, bool fromDwg)
{
    using (var tr = db.TransactionManager.StartOpenCloseTransaction())
    {
        var gd =tr.GetObject(db.GeoDataObject, OpenMode.ForRead)as GeoLocationData;
        var outPt =(fromDwg ? gd.TransformToLonLatAlt(inPt) : gd.TransformFromLonLatAlt(inPt));
        var cs = gd.CoordinateSystem;
        tr.Commit();
        return new Tuple<Point3d, string>(outPt, cs);
    }
}







using (Transaction tr = db.TransactionManager.StartTransaction())
{
    if (!HasGeoData(db))
    {
        ed.WriteMessage("\nCurrent drawing has no geo-location information.");
        return;
    }
    var res = TranslateGeoPoint(db, placementPoint, true);
    var lonlat = res.Item1;
    double pointLat = Math.Round(lonlat.Y, 5);
    double pointLong = Math.Round(lonlat.X, 5);
    LatLong = pointLat.ToString() + "," + pointLong.ToString();

    tr.Commit();
}

 

0 Likes