Project Issue after Passing Military Grid System into Ipoint

2835
6
09-19-2013 01:16 PM
AdamDunlap
New Contributor III
Hi all,

I'm using ArcGIS Server 10.0 sp5 .NET WebADF and NITK toolkit.  I made a simple button to zoom to MGRS coordinates and would like the resulting X & Y values in UTM WGS84 14.  Executing PutCoordsFromMGRS (from the IConversionMGRS class) always returns a Lat/Long for a X,Y value.

When I go to project the value back to UTM WGS84 14N, I get no change....what am I missing?

private void ZoomToMGRSCoordinate(string MGRSValue)
        {
            //We finally get to start the conversion of MGRS to Points

            IServerContext serverContext = null;
            GISServerConnection serverConnection = new GISServerConnection();
            serverConnection.Connect("LocalHost");
            IServerObjectManager serverManager = serverConnection.ServerObjectManager;
            //Get GeometryServer Context
            serverContext = serverManager.CreateServerContext("Geometry",
                "GeometryServer");

            ISpatialReferenceFactory3 pSRF = serverContext.CreateObject(
                "esriGeometry.SpatialReferenceEnvironment") as ISpatialReferenceFactory3;

            ISpatialReference utmSpatialReference = pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_14N);
            ISpatialReference ddSpatialReference = pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

            ESRI.ArcGIS.Geometry.IPoint pnt = new PointClass();

            if (Map.PrimaryMapResource.ToString() == "FSC" || Map.PrimaryMapResource.ToString() == "FSR")
            {
              pnt.SpatialReference = ddSpatialReference;
              IConversionMGRS convertpnt = pnt as IConversionMGRS;
              convertpnt.PutCoordsFromMGRS(MGRSValue, esriMGRSModeEnum.esriMGRSMode_USNG);
           
              ESRI.ArcGIS.Geometry.IPoint pnt2 = new PointClass();
              pnt2.SpatialReference = ddSpatialReference;
              pnt2 = convertpnt as IPoint;
                
              pnt2.Project(utmSpatialReference);
              pnt2.SnapToSpatialReference();

              ESRI.ArcGIS.ADF.Web.Geometry.Point wpn = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Local.Converter.FromIPoint(pnt2)
             
              MapZoomer mapZoomer = new MapZoomer(Map, PointZoomFactor);
              mapZoomer.ZoomToGeometry(wpn);
              
           }
0 Kudos
6 Replies
MelitaKennedy
Esri Notable Contributor
I just tried a simpler version and the Project method worked. My test values were:

14SPH7560307702
-97.0000043106172  37.9999967618346
675602.999999999  4207702

My guess is that there's an issue with the input MGRS string or, if you're getting lat/lon values, something with them. Are you sure that the lat/lon value is within or near UTM zone 14 North?

Melita
0 Kudos
AdamDunlap
New Contributor III
Hi Melita,

Thanks for the quick response!  I'm actually passing a valid MGRS and getting a valid lat, long from the conversion.  Its after the "Project" metehodn and when I look at the pnt2.x and pnt2,y values...I still have lat long values.

pnt.SpatialReference = ddSpatialReference;
IConversionMGRS convertpnt = pnt as IConversionMGRS;
convertpnt.PutCoordsFromMGRS(MGRSValue, esriMGRSModeEnum.esriMGRSMode_USNG);

ESRI.ArcGIS.Geometry.IPoint pnt2 = new PointClass();
pnt2.SpatialReference = ddSpatialReference;
pnt2 = convertpnt as IPoint;

pnt2.Project(utmSpatialReference);

//During Debugging...Still haven't seen the change in the pnt2.X or pnt2.Y values to UTM 14 coordinates....//

ESRI.ArcGIS.ADF.Web.Geometry.Point wpn = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Local.Converter.FromIPoint(pnt2)

In other examples using Ipoint.project...I thought it immediately changes the Ipoint.x and Ipoint.y?

Adam
0 Kudos
NeilClemmons
Regular Contributor III
Is there a reason why you're doing the projection?  Why not assign the utm spatial reference to the point at the start?

pnt.SpatialReference = utmSpatialReference;
IConversionMGRS convertpnt = pnt as IConversionMGRS;
convertpnt.PutCoordsFromMGRS(MGRSValue, esriMGRSModeEnum.esriMGRSMode_USNG);
0 Kudos
AdamDunlap
New Contributor III
Hi Neil,

Thanks for the quick response also!  I tried that also...and I would receive X/Y values in the variables pnt and pnt2 that were in valid lat/long instead of UTM.  Of course, the webadf would zoom to the valid lat longs instead of the UTM meter coordinates.  To show, I did what you suggested and I've included 2 screen shots from my compiler to see what you think....

In the code, you'll see I'm passing in what I appear to be a valid MGRS.... 14SND5623735757


adam
0 Kudos
NeilClemmons
Regular Contributor III
You've got something going wrong somewhere.  Check that spatial reference to make sure it's UTM.  Here is a quick VBA macro I wrote that shows how it should work.  It creates the UTM spatial reference then uses the MGRS conversion interface to set the coordinates using the MGRS values.  This gives you the coordinates in UTM.  It then projects those coordinates back the geographic coordinates.

Sub test()
    Dim factory As ISpatialReferenceFactory3
    Set factory = New SpatialReferenceEnvironment
    
    Dim sr As ISpatialReference
    Set sr = factory.CreateProjectedCoordinateSystem(esriSRProjCS_WGS1984UTM_14N)
    
    Dim pt As IPoint
    Set pt = New Point
    Set pt.SpatialReference = sr
    
    Dim conv As IConversionMGRS
    Set conv = pt
    conv.PutCoordsFromMGRS "14SND5623735757", esriMGRSMode_USNG
    
    ' returns 556237, 3835757
    MsgBox pt.X & vbCrLf & pt.Y
    
    Dim sr2 As ISpatialReference
    Dim proj As IProjectedCoordinateSystem
    Set proj = sr
    Set sr2 = proj.GeographicCoordinateSystem
    pt.Project sr2
    
    ' returns -98.386, 34.662
    MsgBox pt.X & vbCrLf & pt.Y

End Sub
0 Kudos
AdamDunlap
New Contributor III
Hi Neil,

Yes, I agree..in times past I've been able to use the Project method and the X/Y coordinates are converted.  Anyway, I used a open source C# library called DotNetCoords and by adding an extra project..it quickly converts the coordinate w/o making a COM object call.  It lessened my frustration (and code)....and it appears to work with many different types of UTM/Lat Long issues.

project http://www.doogal.co.uk/Help/Index.html

                pnt.SpatialReference = utmSpatialReference;

                DotNetCoords.MGRSRef mg = new MGRSRef(MGRSValue);
                DotNetCoords.UTMRef utm = mg.ToUTMRef();

                double e = utm.Easting;
                double n = utm.Northing;

                pnt.X = e;
                pnt.Y = n;

adam
0 Kudos