/// <summary>
        /// create a crazy coordinate system
        /// </summary>
        /// <returns></returns>
        private ISpatialReference CreateGeographicSpatialReference()
        {
            ISpatialReferenceFactory    spatialRefFatcory = new SpatialReferenceEnvironmentClass();
            IGeographicCoordinateSystem geoCoordSys;

            geoCoordSys = spatialRefFatcory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

            //assign a user defined datum to the SR (just for the test)
            IDatum     datum     = new DatumClass();
            IDatumEdit datumEdit = (IDatumEdit)datum;
            ISpheroid  spheroid  = spatialRefFatcory.CreateSpheroid((int)esriSRSpheroidType.esriSRSpheroid_Clarke1880);

            datumEdit.DefineEx("MyDatum", "My Datum", "MDTM", "", spheroid);

            IPrimeMeridian primeMeridian = spatialRefFatcory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich);
            IAngularUnit   angularUnits  = spatialRefFatcory.CreateUnit((int)esriSRUnitType.esriSRUnit_Degree) as IAngularUnit;
            IGeographicCoordinateSystemEdit geoCoordSysEdit = (IGeographicCoordinateSystemEdit)geoCoordSys;

            geoCoordSysEdit.DefineEx("MyGeoCoordSys", "MyGeoCoordSys", "MGCS", "", "", datum, primeMeridian, angularUnits);

            geoCoordSys.SetFalseOriginAndUnits(-180.0, -180.0, 5000000.0);
            geoCoordSys.SetZFalseOriginAndUnits(0.0, 100000.0);
            geoCoordSys.SetMFalseOriginAndUnits(0.0, 100000.0);

            return(geoCoordSys as ISpatialReference);
        }
Ejemplo n.º 2
0
        public IGeographicCoordinateSystem GetSpatialRefrence()
        {
            double num;

            if (this.int_0 > 0)
            {
                MessageBox.Show("请检查输入数据是否正确!");
                return(null);
            }
            if (this.textEditName.Text.Length == 0)
            {
                MessageBox.Show("未指定名字,必须为坐标系统指定一个名字!");
                return(null);
            }
            if (this.cboSpheres.SelectedIndex <= 0)
            {
                double num2;
                num = Convert.ToDouble(this.txtMajorAxis.Text);
                if (this.rdoFlattening.Checked)
                {
                    num2 = 1.0 / Convert.ToDouble(this.txtFlattening.Text);
                }
                else
                {
                    double num3 = Convert.ToDouble(this.txtMiniorAxis.Text);
                    num2 = (num - num3) / num;
                }
                ((ISpheroidEdit)this.ispheroid_0).DefineEx(this.cboSpheres.Text, null, null, null, ref num, ref num2);
            }
            if (this.cboDatumName.SelectedIndex <= 0)
            {
                ((IDatumEdit)this.idatum_0).DefineEx(this.cboDatumName.Text, null, null, null, this.ispheroid_0);
            }
            if (this.cboAngleName.SelectedIndex <= 0)
            {
                num = Convert.ToDouble(this.txtValue.Text);
                ((IAngularUnitEdit)this.iunit_0).DefineEx(this.cboAngleName.Text, null, null, null, ref num);
            }
            if (this.cboPrimeMeridians.SelectedIndex <= 0)
            {
                double num4 = Convert.ToDouble(this.txtDegree.Text);
                if (num4 < 0.0)
                {
                    num = (num4 - (Convert.ToDouble(this.txtMinute.Text) / 60.0)) -
                          (Convert.ToDouble(this.txtSecond.Text) / 3600.0);
                }
                else
                {
                    num = (num4 + (Convert.ToDouble(this.txtMinute.Text) / 60.0)) +
                          (Convert.ToDouble(this.txtSecond.Text) / 3600.0);
                }
                ((IPrimeMeridianEdit)this.iprimeMeridian_0).DefineEx(this.cboPrimeMeridians.Text, null, null, null,
                                                                     ref num);
            }
            this.igeographicCoordinateSystem_0 = new GeographicCoordinateSystemClass();
            IGeographicCoordinateSystemEdit edit = this.igeographicCoordinateSystem_0 as IGeographicCoordinateSystemEdit;
            IAngularUnit geographicUnit          = this.iunit_0 as IAngularUnit;
            string       alias = "";

            try
            {
                edit.DefineEx(this.textEditName.Text, alias, alias, alias, alias, this.idatum_0, this.iprimeMeridian_0,
                              geographicUnit);
            }
            catch
            {
                MessageBox.Show("无法定义地理坐标!");
                return(null);
            }
            return(this.igeographicCoordinateSystem_0);
        }