Exemple #1
0
        public static string latlongCoordinates(IFeatureClass SiteLayer)
        {
            // Get the feature and its geometry given an Object ID.
            IFeature  stateFeature  = SiteLayer.GetFeature(0);
            IGeometry shapeGeometry = stateFeature.Shape;

            IArea pArea;

            pArea = shapeGeometry as IArea;

            IPoint pPoint;

            pPoint = pArea.Centroid;

            IGeometry pGeometry = (IGeometry)pPoint;
            ISpatialReferenceFactory    pSpatFactory   = new SpatialReferenceEnvironment();
            IGeographicCoordinateSystem pGeoSystem     = pSpatFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);
            ISpatialReference           pSpatReference = (ISpatialReference)pGeoSystem;

            pSpatReference.SetFalseOriginAndUnits(-180, -90, 1000000);
            pGeometry.Project(pSpatReference);

            double Longitude = Math.Abs(pPoint.X);
            double Latitude  = Math.Abs(pPoint.Y);

            return(Longitude.ToString("#.######") + "° W, " + Latitude.ToString("#.######") + "° N");
        }
Exemple #2
0
        public void Test()
        {
            //Create source spatial reference.

            Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");

            System.Object obj = Activator.CreateInstance(factoryType);

            ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;



            ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)

                                                                                                          esriSRGeoCSType.esriSRGeoCS_WGS1984);

            spatialReference.SetFalseOriginAndUnits(-80.0000000232831, 39.9999999767169, 42949672.9);

            //Create an envelope and define its spatial reference.

            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(-68.6076204314651, 49.6186709634653, -68.5531907607304, 49.6530789785679);

            envelope.SpatialReference = spatialReference;

            //Destination spatial reference.

            ISpatialReference projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)

                                                                                                                  esriSRProjCSType.esriSRProjCS_NAD1927UTM_19N);

            //Define the XYDomain equivalent to SetFalseOriginAndUnits.

            projectedCoordinateSystem.SetDomain(500000, 600000, 5300000, 5600000);

            String report = "Print envelope coordinates before projection:\n" +

                            envelope.XMin + " , " + envelope.YMin + " , " + envelope.XMax + " , " +

                            envelope.YMax + "\n\n\n";

            //Project envelope.

            IGeometry geometry = envelope as IGeometry2;

            geometry.Project(projectedCoordinateSystem as ISpatialReference);

            report = report + "Print envelope coordinates after projection:\n" +

                     envelope.XMin + " , " + envelope.YMin + " , " + envelope.XMax + " , " +

                     envelope.YMax;

            System.Windows.Forms.MessageBox.Show(report);
        }
Exemple #3
0
        /// <summary>
        /// Creates a WGS84 Spatial Reference
        /// </summary>
        /// <returns>ISpatialReference WGS84</returns>
        public static ISpatialReference WGS84SpatialReference()
        {
            SpatialReferenceEnvironment spatialReferenceEnv = new SpatialReferenceEnvironmentClass();

            IGeographicCoordinateSystem geoCS            = spatialReferenceEnv.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            ISpatialReference           spatialReference = geoCS;

            spatialReference.SetFalseOriginAndUnits(-180, -90, 1000000);

            return(spatialReference);
        }
Exemple #4
0
        public IPoint ConvertToDecimalDegrees(IPoint point, CoordinateSystemModel coordinateSystemModel)
        {
            var spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            //Create Spatial Reference
            ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem(coordinateSystemModel.ESRIWellKnownID);

            spatialReference.SetFalseOriginAndUnits(coordinateSystemModel.FalseOriginX, coordinateSystemModel.FalseOriginY, coordinateSystemModel.Units);
            point.Project(spatialReference);

            return(point);
        }
Exemple #5
0
        public IPoint ConvertFromUtm(string utmInputValue, CoordinateSystemModel coordinateSystemModel)
        {
            var resultPoint = new Point();
            //Create Spatial Reference Factory
            var spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            //Create Spatial Reference
            ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem(coordinateSystemModel.ESRIWellKnownID);

            spatialReference.SetFalseOriginAndUnits(coordinateSystemModel.FalseOriginX, coordinateSystemModel.FalseOriginY, coordinateSystemModel.Units);
            resultPoint.SpatialReference = spatialReference;
            (resultPoint as IConversionNotation).PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMAddSpaces, utmInputValue);
            return(resultPoint);
        }
Exemple #6
0
        public IPoint ConvertFromMgrs(string mgrsInputValue, CoordinateSystemModel coordinateSystemModel)
        {
            var resultPoint = new Point();
            //Create Spatial Reference Factory
            var spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            //Create Spatial Reference
            ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem(coordinateSystemModel.ESRIWellKnownID);

            spatialReference.SetFalseOriginAndUnits(coordinateSystemModel.FalseOriginX, coordinateSystemModel.FalseOriginY, coordinateSystemModel.Units);
            resultPoint.SpatialReference = spatialReference;
            (resultPoint as IConversionMGRS).PutCoordsFromMGRS(mgrsInputValue, esriMGRSModeEnum.esriMGRSMode_Automatic);
            return(resultPoint);
        }
        /// <summary>
        /// Creates a WGS84 Spatial Reference
        /// </summary>
        /// <returns>ISpatialReference WGS84</returns>
        private ISpatialReference WGS84SpatialReference()
        {
            Trace.WriteLine("OpenGoogleStreetView_WGS84SpatialReference");

            SpatialReferenceEnvironment spatialReferenceEnv = new SpatialReferenceEnvironmentClass();

            IGeographicCoordinateSystem geoCS            = spatialReferenceEnv.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            ISpatialReference           spatialReference = geoCS;

            spatialReference.SetFalseOriginAndUnits(-180, -90, 1000000);

            return(spatialReference);
        }
Exemple #8
0
        /// <summary>
        /// Creates a WGS1984 Spatial Reference.
        /// </summary>
        /// <returns></returns>
        public static ISpatialReference CreateGeographicSR()
        {
            ISpatialReference           pSR = null;
            ISpatialReferenceFactory    pSpatialRefFactory = new SpatialReferenceEnvironment();
            IGeographicCoordinateSystem pGeogCoorSystem    = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

            try
            {
                pSR = pGeogCoorSystem;
                pSR.SetFalseOriginAndUnits(-180, -90, 1000000);
            }

            catch (Exception oErr)
            {
                MessageBox.Show(oErr.ToString(), "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //clean up
            pGeogCoorSystem    = null;
            pSpatialRefFactory = null;
            return(pSR);
        }
Exemple #9
0
        /// <summary>
        /// Creates a WGS1984 Spatial Reference.
        /// </summary>
        /// <returns></returns>
        private ISpatialReference CreateGeographicSR()
        {
            ISpatialReference           pSR = null;
            ISpatialReferenceFactory    pSpatialRefFactory = new SpatialReferenceEnvironment();
            IGeographicCoordinateSystem pGeogCoorSystem    = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

            try
            {
                pSR = pGeogCoorSystem;
                pSR.SetFalseOriginAndUnits(-180, -90, 1000000);
            }

            catch (Exception ex)
            {
                clsStatic.ShowErrorMessage(ex.ToString());
            }

            //clean up
            pGeogCoorSystem    = null;
            pSpatialRefFactory = null;
            return(pSR);
        }
Exemple #10
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                IMxDocument doc = (IMxDocument)m_application.Document;

                if (doc.FocusMap.SpatialReference != null || doc.FocusMap.SpatialReference is IUnknownCoordinateSystem)
                {
                    ISpatialReference srWGS84 = Umbriel.ArcMap.Editor.Util.Geohasher.WGS84SpatialReference();
                    ISpatialReference srMap   = doc.FocusMap.SpatialReference;

                    IEnvelope env = doc.ActiveView.Extent;

                    IPoint pt;

                    double metersPerUnit = 1;

                    if (srMap is IProjectedCoordinateSystem)
                    {
                        IProjectedCoordinateSystem pcs = (IProjectedCoordinateSystem)srMap;
                        metersPerUnit = pcs.CoordinateUnit.MetersPerUnit;
                    }

                    srWGS84.SetFalseOriginAndUnits(-180, -90, 1000000);

                    env.Project(srWGS84);

                    IArea extentArea = (IArea)env;

                    pt = extentArea.Centroid;

                    QueryStringBuilder querystring = new QueryStringBuilder();

                    querystring.MapCenterLatitude  = pt.Y;
                    querystring.MapCenterLongitude = pt.X;

                    QueryStringBuilder.StreetViewParameter streetviewParameter = new QueryStringBuilder.StreetViewParameter(pt.Y, pt.X);

                    querystring.StreetView = streetviewParameter;

                    string url = querystring.ToString();

                    Trace.WriteLine("url=" + url);

                    Process.Start(url);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show(
                        "A data frame spatial reference must be specified in order to use this tool.",
                        "Umbriel Google Street View",
                        System.Windows.Forms.MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);

                System.Windows.Forms.MessageBox.Show(
                    "GoogleStreetView Command Error: " + ex.Message + "\n\n" + ex.StackTrace,
                    "Umbriel.GoogleStreetView",
                    System.Windows.Forms.MessageBoxButtons.OK);
            }
        }