Ejemplo n.º 1
0
        static public double CalculateDistanceBetween84TwoPoints(IPoint pt1, IPoint pt2)
        {
            ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatialReferenceFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
            //wgs 84
            IGeographicCoordinateSystem wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326) as IGeographicCoordinateSystem;
            IUnit             meterUnit       = spatialReferenceFactory.CreateUnit((int)ESRI.ArcGIS.Geometry.esriSRUnitType.esriSRUnit_Meter);
            ISpatialReference pSR             = wgs84 as ISpatialReference;
            IGeometryServer2  pGS             = new GeometryServerClass();
            double            dis             = pGS.GetDistanceGeodesic(wgs84, pt1, pt2, (ILinearUnit)meterUnit);
            IZAware           z1 = pt1 as IZAware;
            IZAware           z2 = pt2 as IZAware;

            if (double.IsNaN(pt1.Z) == false && double.IsNaN(pt2.Z) == false)
            {
                double deltaZ = Math.Abs(pt1.Z - pt2.Z);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pGS);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory);
                return(Math.Sqrt(dis * dis + deltaZ * deltaZ));
            }
            else
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pGS);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory);
                return(dis);
            }
        }
Ejemplo n.º 2
0
        private void btnPrjPath_Click(object sender, EventArgs e)
        {
            //选择prj文件
            OpenFileDialog filedialog = new OpenFileDialog();

            filedialog.Multiselect = false;
            filedialog.Title       = "选择prj文件";
            filedialog.Filter      = "*.prj|*.prj";
            if (filedialog.ShowDialog() == DialogResult.OK)
            {
                string str = filedialog.FileName;
                this.txtPrjPath.Text = str;

                ESRI.ArcGIS.Geometry.ISpatialReferenceFactory pPrjFac = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
                pSR = pPrjFac.CreateESRISpatialReferenceFromPRJFile(txtPrjPath.Text);
                if (pSR == null)
                {
                    return;
                }
                if (pSR.Name == txtName.Text)
                {
                    return;
                }
                txtName.Text = pSR.Name;
                fillRtxt();
            }
        }
Ejemplo n.º 3
0
        public static ESRI.ArcGIS.Geometry.ISpatialReference get_spatialReference(OSGeo.OSR.SpatialReference ogrSR)
        {
            ogrSR.MorphToESRI();

            string wkt;
            ogrSR.ExportToWkt(out wkt);

            ISpatialReferenceFactory4 spatialReferenceFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
            ISpatialReference sr;

            int bytesRead;
            spatialReferenceFactory.CreateESRISpatialReference(wkt, out sr, out bytesRead);

            return sr;
        }
Ejemplo n.º 4
0
        public static ESRI.ArcGIS.Geometry.ISpatialReference get_spatialReference(OSGeo.OSR.SpatialReference ogrSR)
        {
            ogrSR.MorphToESRI();

            string wkt;

            ogrSR.ExportToWkt(out wkt);

            ISpatialReferenceFactory4 spatialReferenceFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
            ISpatialReference         sr;

            int bytesRead;

            spatialReferenceFactory.CreateESRISpatialReference(wkt, out sr, out bytesRead);

            return(sr);
        }
Ejemplo n.º 5
0
        private void btnPrjFile_Click(object sender, EventArgs e)
        {
            string sInstall = ReadRegistry("SOFTWARE\\ESRI\\CoreRuntime");

            if (sInstall == "") //added by chulili 2012-11-13 平台由ArcGIS9.3换成ArcGIS10,相应的注册表路径要修改
            {
                sInstall = ReadRegistry("SOFTWARE\\ESRI\\Engine10.0\\CoreRuntime");
            }
            if (sInstall == "")
            {
                sInstall = ReadRegistry("SOFTWARE\\ESRI\\Desktop10.0\\CoreRuntime");
            }   //added by chulili 2012-11-13  end
            sInstall = sInstall + "\\Coordinate Systems";

            OpenFileDialog filedialog = new OpenFileDialog();

            filedialog.Multiselect      = false;
            filedialog.InitialDirectory = sInstall;
            filedialog.Filter           = "*.prj|*.prj";
            filedialog.Title            = "选择prj文件";
            if (filedialog.ShowDialog() == DialogResult.OK)
            {
                string str = filedialog.FileName;
                this.txtPrjFile.Text = str;

                //直接读取坐标系统
                try
                {
                    ESRI.ArcGIS.Geometry.ISpatialReferenceFactory pPrjFac = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
                    ESRI.ArcGIS.Geometry.ISpatialReference        pSpa    = pPrjFac.CreateESRISpatialReferenceFromPRJFile(str);

                    m_strOutPrj = ExportToESRISpatialReference(pSpa);
                }
                catch
                {
                }
            }
        }