How to modify ESRI.ArcGIS.Geometry.IPoint to get decimal degrees?

1212
5
Jump to solution
04-30-2013 01:59 PM
TomMagdaleno
Occasional Contributor III
Hi All,
  I think I have a simple question.  This code returns the XY of the point clicked in feet.  I would like to get it in decimal degrees.  How would I modify the code?

using System; using System.Collections.Generic; using System.Text; using System.IO;  namespace ArcMapAddin1 {     public class HyperlinkIStreet : ESRI.ArcGIS.Desktop.AddIns.Tool     {         public HyperlinkIStreet()         {         }          protected override void OnUpdate()         {         }     //private const string USER_PROMPT_3 = "Are you sure you want to hyperlink to IStreetView?";     private const string CAPTION_3 = "Hyperlink to IStreet";     protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) {     //var result = System.Windows.Forms.MessageBox.Show(USER_PROMPT_3, CAPTION_3,      //      System.Windows.Forms.MessageBoxButtons.YesNo,      //      System.Windows.Forms.MessageBoxIcon.Question);     //if (result == System.Windows.Forms.DialogResult.Yes)     {  //Get coordinates from MouseEventArgs         ESRI.ArcGIS.ArcMapUI.IMxDocument mxDoc = ArcMap.Document;         ESRI.ArcGIS.Carto.IActiveView activeView = mxDoc.FocusMap as ESRI.ArcGIS.Carto.IActiveView;         ESRI.ArcGIS.Geometry.IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as ESRI.ArcGIS.Geometry.IPoint;         //Open IStreetView in default browser         System.Diagnostics.Process.Start("http://maps.google.com/maps?q=&layer=c&cbll="             + point.X + "," + point.Y + "&cbp=12,100,0,0,0&output=svembed&t=m&z=17");     } }                        }  }
0 Kudos
1 Solution

Accepted Solutions
TerryGiles
Occasional Contributor III
That code should go between the line where create your point object & opening StreetView.


On which line does it fail?  Do you have a Using directive for Esri.ArcGIS.Geometry? If not, try one of the following :
use the full namespace , ESRI.ArcGIS.Geometry.ISpatialReferenceFactory srFact = ESRI.ArcGIS.Geometry.new SpatialReferenceEnvironmentClass();
Other things to try -

  • if it's failing on Type factoryType = null, either adding a Using directive for System or qualify the name = System.Type factoryType = null;

  • instead of GetTypefromProgID try Type.GetTypeFromCLSID("") - the GUID for the SRfactory can be found here http://resources.arcgis.com/en/help/arcobjects-net/conceptualHelp/#/Interacting_with_singleton_objec...

  •   you can also use ISpatialReferenceFactory srFact = new SpatialReferenceEnvironmentClass(); but see the warnings of doing do one the same page I linked to in the above bullet

Updated code with namespaces here -
ESRI.ArcGIS.Geometry.IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as ESRI.ArcGIS.Geometry.IPoint; //project pt to WGS84 System.Type factoryType = null; factoryType = System.Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); ESRI.ArcGIS.Geometry.ISpatialReferenceFactory srFact = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass(); ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem srWGS84 = srFact.CreateGeographicCoordinateSystem(4326); point.Project(srWGS84);  //Open IStreetView in default browser System.Diagnostics.Process.Start("http://maps.google.com/maps?q=&layer=c&cbll="             + point.X + "," + point.Y + "&cbp=12,100,0,0,0&output=svembed&t=m&z=17");  

View solution in original post

0 Kudos
5 Replies
TerryGiles
Occasional Contributor III
something like this should do the trick -
Type factoryType = null;
factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
ISpatialReferenceFactory srFact = (ISpatialReferenceFactory)Activator.CreateInstance(factoryType);
IGeographicCoordinateSystem srWGS84 = srFact.CreateGeographicCoordinateSystem(4326);
point.Project(srWGS84);

0 Kudos
TomMagdaleno
Occasional Contributor III
something like this should do the trick -
Type factoryType = null;
factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
ISpatialReferenceFactory srFact = (ISpatialReferenceFactory)Activator.CreateInstance(factoryType);
IGeographicCoordinateSystem srWGS84 = srFact.CreateGeographicCoordinateSystem(4326);
point.Project(srWGS84);



The program doesn't understand the factory type references.  Where would I insert it in my code?
0 Kudos
TerryGiles
Occasional Contributor III
That code should go between the line where create your point object & opening StreetView.


On which line does it fail?  Do you have a Using directive for Esri.ArcGIS.Geometry? If not, try one of the following :
use the full namespace , ESRI.ArcGIS.Geometry.ISpatialReferenceFactory srFact = ESRI.ArcGIS.Geometry.new SpatialReferenceEnvironmentClass();
Other things to try -

  • if it's failing on Type factoryType = null, either adding a Using directive for System or qualify the name = System.Type factoryType = null;

  • instead of GetTypefromProgID try Type.GetTypeFromCLSID("") - the GUID for the SRfactory can be found here http://resources.arcgis.com/en/help/arcobjects-net/conceptualHelp/#/Interacting_with_singleton_objec...

  •   you can also use ISpatialReferenceFactory srFact = new SpatialReferenceEnvironmentClass(); but see the warnings of doing do one the same page I linked to in the above bullet

Updated code with namespaces here -
ESRI.ArcGIS.Geometry.IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as ESRI.ArcGIS.Geometry.IPoint; //project pt to WGS84 System.Type factoryType = null; factoryType = System.Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); ESRI.ArcGIS.Geometry.ISpatialReferenceFactory srFact = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass(); ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem srWGS84 = srFact.CreateGeographicCoordinateSystem(4326); point.Project(srWGS84);  //Open IStreetView in default browser System.Diagnostics.Process.Start("http://maps.google.com/maps?q=&layer=c&cbll="             + point.X + "," + point.Y + "&cbp=12,100,0,0,0&output=svembed&t=m&z=17");  
0 Kudos
TomMagdaleno
Occasional Contributor III
Thank you Terry I got it working now.  The only problem now is that X and Y need to be swapped for the Google syntax.  I tried changing it in the code but to no avail.  I can't figure out why.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;



namespace StreetViewAddin_Camarillo
{
    public class StreetViewHyperlink : ESRI.ArcGIS.Desktop.AddIns.Tool
    {
        public StreetViewHyperlink()
        {
        }

        protected override void OnUpdate()
        {
        }
            //private const string USER_PROMPT_3 = "Are you sure you want to hyperlink to IStreetView?";
    private const string CAPTION_3 = "Hyperlink to IStreet";
    protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
    //var result = System.Windows.Forms.MessageBox.Show(USER_PROMPT_3, CAPTION_3,
     //      System.Windows.Forms.MessageBoxButtons.YesNo,
     //      System.Windows.Forms.MessageBoxIcon.Question);
    //if (result == System.Windows.Forms.DialogResult.Yes)
    {
 //Get coordinates from MouseEventArgs
        ESRI.ArcGIS.ArcMapUI.IMxDocument mxDoc = ArcMap.Document;
        ESRI.ArcGIS.Carto.IActiveView activeView = mxDoc.FocusMap as ESRI.ArcGIS.Carto.IActiveView;
        ESRI.ArcGIS.Geometry.IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.Y, arg.X) as ESRI.ArcGIS.Geometry.IPoint;
        //project pt to WGS84
        System.Type factoryType = null;
        factoryType = System.Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
        ESRI.ArcGIS.Geometry.ISpatialReferenceFactory srFact = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment();
        ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem srWGS84 = srFact.CreateGeographicCoordinateSystem(4326);
        point.Project(srWGS84);
        //Open IStreetView in default browser
        System.Diagnostics.Process.Start("http://maps.google.com/maps?q=&layer=c&cbll="
                    + point.Y + "," + point.X + "&cbp=12,100,0,0,0&output=svembed&t=m&z=17");
        
    }
}
        

        
    }

}
    
0 Kudos
TerryGiles
Occasional Contributor III
so is it opening a browser window to google street view but still passing the coords as X,Y?

I've had problems with an older version of the addin is still in the arcgis assembly cache folder (on Win7 usually C:\Users\<user>\Documents\ArcGIS\AddIns\Desktop10.1).  Check to see if there's a folder with your addin's guid (you can find it in the config.esriaddinx file as the AddInID).  If so, you might delete that, rebuild in visual studio and try debugging again.
0 Kudos