ARCGIS 小工具

将经纬度点转换为平面坐标。
        private IPoint GCStoPRJ(double x, double y)
        {
            IPoint cPoint = new ESRI.ArcGIS.Geometry.Point();
            cPoint.PutCoords(x, y);
            ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironment();
            cPoint.SpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem(4326);
            cPoint.Project(pSpatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Beijing1954_3_Degree_GK_CM_117E));
            return cPoint;
        }

将米为单位的坐标投射为经纬度
        private IPoint PRJtoGCS(double x, double y)
        {
            IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
            pPoint.PutCoords(x, y);
            ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironment();
            pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Beijing1954_3_Degree_GK_CM_117E);
            //pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_GEM10C));
            pPoint.Project(pSRF.CreateGeographicCoordinateSystem(4326));
            return pPoint;
        }

 通常需要将经纬度坐标与投影坐标相互转换,下面是一些源码,在ArcEngine中实现。

投影转经纬度

 private IPoint PRJtoGCS(double x, double y)  
        {  
          IPoint pPoint = new PointClass();  
          pPoint.PutCoords(x, y);  
          ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();  
          pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem(2428);  
          pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954));  
          return pPoint;  
        }

    其中,pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem( 2428 );

    这行代码是设置pPoint 的空间参考,也就是要转化的点的投影坐标。如果不知道投影坐标的话,转化会报异常。2428 为该投影的enum 值

    pPoint.Project(pSRF.CreateGeographicCoordinateSystem(( int)esriSRGeoCSType.esriSRGeoCS_Beijing1954));
将该点的投影坐标转化为经纬度。

经纬度到投影

         private IPoint GCStoPRJ(IPoint pPoint, int GCSType,int PRJType)
         {    
             ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();    
             pPoint.SpatialReference = pSRF.CreateGeographicCoordinateSystem(GCSType);    
             pPoint.Project(pSRF.CreateProjectedCoordinateSystem(PRJType));    

             return pPoint;  
        }

//同样的一个函数

private IPoint GCStoPRJ(IPoint pPoint)
{

            ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironment();

            pPoint.SpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Krasovsky1940);

            IProjectedCoordinateSystem pProjectCoodinateSys = pSpatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Xian1980_GK_Zone_17);

            ISpatialReference pSpatialReference = (ISpatialReference)pProjectCoodinateSys;

            pSpatialReference.SetDomain(17352988.066800, 18230892.557100, 2326007.173500, 3237311.062300);

            pPoint.Project(pSpatialReference);

}

//球面坐标
//esriSRGeoCS_WGS1984 4326 WGS 1984. 
//esriSRGeoCS_Beijing1954 4214 Beijing 1954.

//平面坐标
////北京54六度带
//esriSRProjCS_Beijing1954GK_13 21413 Beijing 1954 GK Zone 13. 
//esriSRProjCS_Beijing1954GK_14 21414 Beijing 1954 GK Zone 14. 
//esriSRProjCS_Beijing1954GK_15 21415 Beijing 1954 GK Zone 15. 
//esriSRProjCS_Beijing1954GK_16 21416 Beijing 1954 GK Zone 16. 
//esriSRProjCS_Beijing1954GK_17 21417 Beijing 1954 GK Zone 17. 
//esriSRProjCS_Beijing1954GK_18 21418 Beijing 1954 GK Zone 18. 
//esriSRProjCS_Beijing1954GK_19 21419 Beijing 1954 GK Zone 19. 
//esriSRProjCS_Beijing1954GK_20 21420 Beijing 1954 GK Zone 20. 
//esriSRProjCS_Beijing1954GK_21 21421 Beijing 1954 GK Zone 21. 
//esriSRProjCS_Beijing1954GK_22 21422 Beijing 1954 GK Zone 22. 
//esriSRProjCS_Beijing1954GK_23 21423 Beijing 1954 GK Zone 23. 
//esriSRProjCS_Beijing1954GK_13N 21473 Beijing 1954 GK Zone 13N. 
//esriSRProjCS_Beijing1954GK_14N 21474 Beijing 1954 GK Zone 14N. 
//esriSRProjCS_Beijing1954GK_15N 21475 Beijing 1954 GK Zone 15N. 
//esriSRProjCS_Beijing1954GK_16N 21476 Beijing 1954 GK Zone 16N. 
//esriSRProjCS_Beijing1954GK_17N 21477 Beijing 1954 GK Zone 17N. 
//esriSRProjCS_Beijing1954GK_18N 21478 Beijing 1954 GK Zone 18N. 
//esriSRProjCS_Beijing1954GK_19N 21479 Beijing 1954 GK Zone 19N. 
//esriSRProjCS_Beijing1954GK_20N 21480 Beijing 1954 GK Zone 20N. 
//esriSRProjCS_Beijing1954GK_21N 21481 Beijing 1954 GK Zone 21N. 
//esriSRProjCS_Beijing1954GK_22N 21482 Beijing 1954 GK Zone 22N. 
//esriSRProjCS_Beijing1954GK_23N 21483 Beijing 1954 GK Zone 23N. 
////北京54三度带
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_102E 2431 Beijing 1954 3 Degree GK CM 102E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_105E 2432 Beijing 1954 3 Degree GK CM 105E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_108E 2433 Beijing 1954 3 Degree GK CM 108E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_111E 2434 Beijing 1954 3 Degree GK CM 111E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_114E 2435 Beijing 1954 3 Degree GK CM 114E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_117E 2436 Beijing 1954 3 Degree GK CM 117E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_120E 2437 Beijing 1954 3 Degree GK CM 120E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_123E 2438 Beijing 1954 3 Degree GK CM 123E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_126E 2439 Beijing 1954 3 Degree GK CM 126E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_129E 2440 Beijing 1954 3 Degree GK CM 129E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_132E 2441 Beijing 1954 3 Degree GK CM 132E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_135E 2442 Beijing 1954 3 Degree GK CM 135E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_25 2401 Beijing 1954 3 Degree GK Zone 25. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_26 2402 Beijing 1954 3 Degree GK Zone 26. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_27 2403 Beijing 1954 3 Degree GK Zone 27. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_28 2404 Beijing 1954 3 Degree GK Zone 28. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_29 2405 Beijing 1954 3 Degree GK Zone 29. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_30 2406 Beijing 1954 3 Degree GK Zone 30. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_31 2407 Beijing 1954 3 Degree GK Zone 31. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_32 2408 Beijing 1954 3 Degree GK Zone 32. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_33 2409 Beijing 1954 3 Degree GK Zone 33. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_34 2410 Beijing 1954 3 Degree GK Zone 34. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_35 2411 Beijing 1954 3 Degree GK Zone 35. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_36 2412 Beijing 1954 3 Degree GK Zone 36. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_37 2413 Beijing 1954 3 Degree GK Zone 37. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_38 2414 Beijing 1954 3 Degree GK Zone 38. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_39 2415 Beijing 1954 3 Degree GK Zone 39. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_40 2416 Beijing 1954 3 Degree GK Zone 40. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_41 2417 Beijing 1954 3 Degree GK Zone 41. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_42 2418 Beijing 1954 3 Degree GK Zone 42. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_43 2419 Beijing 1954 3 Degree GK Zone 43. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_44 2420 Beijing 1954 3 Degree GK Zone 44. 
//esriSRProjCS_Beijing1954_3_Degree_GK_Zone_45 2421 Beijing 1954 3 Degree GK Zone 45. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_75E 2422 Beijing 1954 3 Degree GK CM 75E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_78E 2423 Beijing 1954 3 Degree GK CM 78E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_81E 2424 Beijing 1954 3 Degree GK CM 81E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_84E 2425 Beijing 1954 3 Degree GK CM 84E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_87E 2426 Beijing 1954 3 Degree GK CM 87E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_90E 2427 Beijing 1954 3 Degree GK CM 90E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_93E 2428 Beijing 1954 3 Degree GK CM 93E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_96E 2429 Beijing 1954 3 Degree GK CM 96E. 
//esriSRProjCS_Beijing1954_3_Degree_GK_CM_99E 2430 Beijing 1954 3 Degree GK CM 99E.

 

根据两点生成一条线
        private IPolyline CreatePolyLineByTwoPoint(IPoint p1, IPoint p2)
        {
            INewLineFeedback m_LineFeed = new NewLineFeedback();
            m_LineFeed.Start(p1);
            m_LineFeed.AddPoint(p2);
            IPolyline m_PolyLine = m_LineFeed.Stop();
            return m_PolyLine;
        }

画点
        public void newPoint(double lngg, double latt)
        {
            FormMain main = (FormMain)this.Owner;

            double XPoint = lngg;
            double YPoint = latt;

            IActiveView pActiveView = main.axMapControl1.ActiveView;
            IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
            pPoint.PutCoords(XPoint, YPoint);
            IMarkerElement pMarkerElement;
            pMarkerElement = new MarkerElementClass();
            ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol();
            pMarkerSymbol.Size = 6;
            IElement pElement;
            pElement = pMarkerElement as IElement;
            pElement.Geometry = pPoint;
            pMarkerElement.Symbol = pMarkerSymbol;
            main.endIElement.Add(pElement);//添加到终点起点list

            //建立文字符号对象,并设置相应的属性
            ITextElement pTextEle;
            IElement pEles;
            pTextEle = new TextElementClass();
            pTextEle.Text = "[" + lngg + "," + latt + "]";

            //symbol
            ITextSymbol pTextSymbol = new TextSymbol();
            pTextSymbol.Color = GetRGBColor(255, 0, 0);
            pTextSymbol.Size = 10;
            pTextEle.Symbol = pTextSymbol;
            pEles = pTextEle as IElement;
            pEles.Geometry = pPoint;
            main.endTextIElement.Add(pEles);//添加到终点起点list

            IGraphicsContainer pGraphicsContainer = main.axMapControl1.ActiveView as IGraphicsContainer;
            pGraphicsContainer.AddElement((IElement)pEles, 0);
            pGraphicsContainer.AddElement((IElement)pMarkerElement, 0);
            pActiveView.Refresh();


        }

posted @ 2016-09-30 15:50  JaneAi  阅读(1494)  评论(0编辑  收藏  举报