• table内存Featureclassreal FeatureClass


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;


    using ESRI.ArcGIS.Geodatabase;
    using ESRI.ArcGIS.SystemUI;
    using ESRI.ArcGIS.esriSystem;
    using ESRI.ArcGIS.Carto;
    using ESRI.ArcGIS.Controls;
    using ESRI.ArcGIS.DataSourcesGDB;
    using ESRI.ArcGIS.DataSourcesFile;
    using ESRI.ArcGIS.Geometry;
    using ESRI.ArcGIS.Display;
    using ESRI.ArcGIS.AnalysisTools; //使用GP工具
    using ESRI.ArcGIS.Geoprocessing;
    using ESRI.ArcGIS.Geoprocessor;



    namespace SearchAndDisplay
    {
        public partial class Form1 : Form
        {
            //传递数据之用
            private IFeatureClass pCommonPolygonClass;
            private IFeatureClass pCommonPolylineClass;
            private IFeatureClass pCommonPointClass;
            private IFeatureWorkspace pPublicFeatureWorkspace=null;

            private IArray pArray;
            private bool isFileExist;
            private bool isGDBExist;

            //传递数据库中的数据
            private string XY;
            private string Globle;


            public Form1()
            {
                InitializeComponent();
            }

            //Create GCS:Beijing54
            private ISpatialReference GetGCSBeijing54()
            {
                ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
                ISpatialReference pSR = pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                return pSR;
     
            }


            //Create GCS:Xi'an80
            private ISpatialReference GetGCSXian80()
            {
                ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
                //pSRF.CreateProjectedCoordinateSystem(esriSRProjCS4Type.esriSRProjCS_Xian1980_GK_Zone_19);
                //pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980);
                ISpatialReference pSR = pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980);
                return pSR;
            }


            //Create GCS:WGS1984
            private ISpatialReference GetGCSWGS1984()
            {
                ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
                ISpatialReference pSR = pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                return pSR;
            }
            //Create PCS:Xian80 zone19
            private ISpatialReference GetPCSXian80()
            {
                ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
                ISpatialReference pSR = pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Xian1980_GK_Zone_19);
                return pSR;
            }


           //Create PCS:Beijng54 zone19
           private ISpatialReference GetPCSBeijing54()
           {
               ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
               ISpatialReference pSR = pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_Beijing1954GK_19);
               return pSR;

            }
            
           //Create PCS:WGS1984 zong49
           private ISpatialReference    GetPCSWGS1984()
           {
               ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
               ISpatialReference pSR = pSRF.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_49N);
               return pSR;

            }
           
            //Load 3 featureClasses with different spatial reference
            private void Form1_Load(object sender, EventArgs e)
            {
                axMapControl1.Map.SpatialReference = GetPCSBeijing54();
                axMapControl2.Map.SpatialReference = GetPCSXian80();
                axMapControl3.Map.SpatialReference = GetPCSWGS1984();

            }
            private void TabsChanged()
            {
              
            }
            
            //add 3 layers to 3 mapcontrols with the different spatial reference
            private void button8_Click(object sender, EventArgs e)
            {
                IPoint pPoint=null ;
                IPolyline pL = null;
                object _missing = Type.Missing;


                IWorkspaceFactory pSdeWorkspaceFactory = new SdeWorkspaceFactory();
                IPropertySet pPropertySet= new PropertySetClass();
                pPropertySet.SetProperty("Server","siwei-gr7bzmd3q");
                pPropertySet.SetProperty("Instance","5008");
                pPropertySet.SetProperty("Database","sdeTest");
                pPropertySet.SetProperty("user","sa");
                pPropertySet.SetProperty("password","zhangjun1130");
                pPropertySet.SetProperty("version","sde.DEFAULT");
                IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pSdeWorkspaceFactory.Open(pPropertySet, 0);
                pPublicFeatureWorkspace =pFeatureWorkspace;
                
                IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pFeatureWorkspace;
                IFeatureClass pFeatureClass;
                IFeatureLayer pFeatureLayer;

                pFeatureClass = pFeatureWorkspace.OpenFeatureClass("sdeTest.DBO.DomBeijing54");
                pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                axMapControl1.AddLayer(pFeatureLayer);

                pFeatureClass = pFeatureWorkspace.OpenFeatureClass("sdeTest.DBO.DomXian80");
                pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                axMapControl2.AddLayer(pFeatureLayer);

                pFeatureClass = pFeatureWorkspace.OpenFeatureClass("sdeTest.DBO.DomWGS84");
                pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                axMapControl3.AddLayer(pFeatureLayer);




                #region 暂时不用
                //// 摄区
                //#region 搞摄区
                //pWorkspaceEdit.StartEditing(true);
                //pWorkspaceEdit.StartEditOperation();

                //    IFeatureClass pPolygonsClassOld = pFeatureWorkspace.OpenFeatureClass("polygons");
                //    ITable pTable = (ITable)pPolygonsClassOld;
                //    if (pTable != null)
                //    {
                //        pTable.DeleteSearchedRows(null);

                //    }

                //IFeatureClass pPolygonsClass = pFeatureWorkspace.OpenFeatureClass("polygons");
                //isGDBExist = true;

                //IFeature pPolygonsFeaure;
                //pPolygonsFeaure= pPolygonsClass.CreateFeature();

                //IPolygon pPolygon = new PolygonClass();
                //IPointCollection pPointCollection = (IPointCollection)pPolygon;
                //pPoint = new PointClass();
                //pPoint.PutCoords(10, 10);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(15, 10);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(15, 8);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(18, 8);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(18, 4);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(10, 4);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPolygonsFeaure.Shape = pPolygon;
                //pPolygon.Close();
                //pPolygonsFeaure.Store();



                //pPolygonsFeaure = pPolygonsClass.CreateFeature();
                //pPolygon = new PolygonClass();
                //pPointCollection = (IPointCollection)pPolygon;
                //pPoint = new PointClass();
                //pPoint.PutCoords(20, 8);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(25, 8);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(25, 4);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(20, 4);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPolygonsFeaure.Shape = pPolygon;
                //pPolygon.Close();
                //pPolygonsFeaure.Store();


                //#endregion

                //// 航线
                //#region 搞航线
                //IFeatureClass pPolylineClass = pFeatureWorkspace.OpenFeatureClass("polylines");
                //IFeature pPolylinesFeature = null;

                //pPolylinesFeature = pPolylineClass.CreateFeature();
                //pL = new PolylineClass();
                //pPointCollection = (IPointCollection)pL;
                //pPoint = new PointClass();
                //pPoint.PutCoords(9.5, 9.5);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(15.5, 9.5);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPolylinesFeature.Shape = pL;
                //pPolylinesFeature.Store();

                //pPolylinesFeature = pPolylineClass.CreateFeature();
                //pL = new PolylineClass();
                //pPointCollection = (IPointCollection)pL;
                //pPoint = new PointClass();
                //pPoint.PutCoords(9.5, 6.5);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(15.5, 6.5);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPolylinesFeature.Shape = pL;
                //pPolylinesFeature.Store();

                //pPolylinesFeature = pPolylineClass.CreateFeature();
                //pL = new PolylineClass();
                //pPointCollection = (IPointCollection)pL;
                //pPoint = new PointClass();
                //pPoint.PutCoords(9.5, 4.5);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPoint.PutCoords(15.5, 4.5);
                //pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                //pPolylinesFeature.Shape = pL;
                //pPolylinesFeature.Store();
                //#endregion

                //// 像点
                //#region 搞像点
                //IFeatureClass pPointClass = pFeatureWorkspace.OpenFeatureClass("points");
                //IFeature pPointFeature = null;

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(9.7, 9.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(12.7, 9.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(14.7, 9.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(9.7, 6.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(12.7, 6.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(14.7, 6.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(9.7, 4.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(12.7, 4.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //pPointFeature = pPointClass.CreateFeature();
                //pPoint = new PointClass();
                //pPoint.PutCoords(14.7, 4.5);
                //pPointFeature.Shape = pPoint;
                //pPointFeature.Store();

                //#endregion

                //pWorkspaceEdit.StopEditOperation();
                //pWorkspaceEdit.StopEditing(true);

                //pCommonPolygonClass = pPolygonsClass;
                //pCommonPolylineClass = pPolylineClass;
                //pCommonPointClass = pPointClass;
                #endregion

            }

            private void button9_Click(object sender, EventArgs e)
            {


                IWorkspaceFactory pFeatureWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pFeatureWorkspaceFactory.OpenFromFile("D:/Work", 0);
                IFields pFields = pCommonPolygonClass.Fields;
                if (isFileExist == true)
                {
                    IFeatureClass pPolygonsFeatureClassOld = pFeatureWorkspace.OpenFeatureClass("Newpolygons");
                    ITable pTable = (ITable)pPolygonsFeatureClassOld;
                    if (pTable != null)
                    {
                        pTable.DeleteSearchedRows(null);
                    }
                }
                #region 摄区出库
        
                IFeatureClass pPolygonsFeatureClass = pFeatureWorkspace.CreateFeatureClass("Newpolygons", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                isFileExist = true;
                IFeature pPolygonFeaure;
                IFeature pConvertFeature;
                //IFeatureCursor pPolygonCursor = pCommonPolygonClass.Search(null, true);
                //IFeature pFeaure = pPolygonCursor.NextFeature();

                for (int i = 0; i < pArray.Count;i++ )
                {
                    pPolygonFeaure = pPolygonsFeatureClass.CreateFeature();
                    pConvertFeature = (IFeature)pArray.get_Element(i);
                    pPolygonFeaure.Shape = pConvertFeature.Shape;
                    pPolygonFeaure.Store();

                }
                #endregion

                #region 航线出库
                //pFields = pCommonPolylineClass.Fields;
                //IFeatureClass pPolylineFeatureClass = pFeatureWorkspace.CreateFeatureClass("Newpolines", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                //IFeature pPloylineFeature;

                //IFeatureCursor pPolylineCursor = pCommonPolylineClass.Search(null, true);
                //IFeature pFeature1 = pPolylineCursor.NextFeature();
                //while (pFeature1!= null)
                //{
                //    pPloylineFeature = pPolylineFeatureClass.CreateFeature();
                //    pPloylineFeature.Shape = pFeature1.Shape;
                //    pPloylineFeature.Store();
                //    pFeature1 = pPolylineCursor.NextFeature();

                //}

                #endregion

                #region 像点
                //pFields = pCommonPointClass.Fields;
                //IFeatureClass pPointsFeatureClass = pFeatureWorkspace.CreateFeatureClass("Newpoints", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                //IFeature pPointFeaure;

                //IFeatureCursor pPointCursor = pCommonPointClass.Search(null, true);
                //IFeature pFeature2 = pPointCursor.NextFeature();
                
                //while(pFeature2!=null)
                //{
                //    pPointFeaure=pPointsFeatureClass.CreateFeature();
                //    pPointFeaure.Shape = pFeature2.Shape;
                //    pPointFeaure.Store();
                //    pFeature2 = pPointCursor.NextFeature();



                //}


                #endregion


            }

            private void radioButton2_CheckedChanged(object sender, EventArgs e)
            {

            }

            private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
            {

            }

            private void button1_Click(object sender, EventArgs e)
            {
                IFeatureLayer pPolygonLayer=new FeatureLayerClass();
                IFeatureLayer pPolylineLayer= new FeatureLayerClass();
                IFeatureLayer pPointLayer= new FeatureLayerClass();
                pPolygonLayer.FeatureClass=pCommonPolygonClass;
                pPolylineLayer.FeatureClass=pCommonPolylineClass;
                pPointLayer.FeatureClass=pCommonPointClass;

                axMapControl1.AddLayer(pPolygonLayer);
                axMapControl1.AddLayer(pPolylineLayer);
                axMapControl1.AddLayer(pPointLayer);





            }

            private void axMapControl1_OnMouseDown_1(object sender, IMapControlEvents2_OnMouseDownEvent e)
            {
                if (e.button == 2)
                {
                    ISpatialReference pSR = axMapControl1.Map.SpatialReference;
                    ILayer pLayer = axMapControl1.Map.get_Layer(0);
                    IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
                    int count = pFeatureLayer.FeatureClass.FeatureCount(null);
                    MessageBox.Show("投影名字是:" + pSR.Name + "  图层Feature个数是:" + count);
                }
            }

            private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
            {
                if (e.button == 2)
                {
                    ISpatialReference pSR = axMapControl2.Map.SpatialReference;
                    ILayer pLayer = axMapControl2.Map.get_Layer(0);
                    IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
                    int count = pFeatureLayer.FeatureClass.FeatureCount(null);
                    MessageBox.Show("投影名字是:" + pSR.Name + "  图层Feature个数是:" + count);
                }
            }

            private void axMapControl3_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
            {
                if (e.button == 2)
                {
                    ISpatialReference pSR = axMapControl3.Map.SpatialReference;
                    ILayer pLayer = axMapControl3.Map.get_Layer(0);
                    IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
                    int count = pFeatureLayer.FeatureClass.FeatureCount(null);
                    MessageBox.Show("投影名字是:" + pSR.Name + "  图层Feature个数是:" + count);
                }
            }

            private void tabControl1_Selected(object sender, TabControlEventArgs e)
            {


            }

            private void tabControl1_Click(object sender, EventArgs e)
            {
               

            }

            private void axMapControl3_TabIndexChanged(object sender, EventArgs e)
            {



            }

            //切换Tabs使用的方法
            private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
            {
                switch (tabControl1.SelectedIndex)
                {
                    case 0:
                        axToolbarControl1.SetBuddyControl(axMapControl1);
                        Console.WriteLine("0");
                        break;
                    case 1:

                        axToolbarControl1.SetBuddyControl(axMapControl2);
                        Console.WriteLine("1");
                        break;
                    case 2:
                        axToolbarControl1.SetBuddyControl(axMapControl3);
                        Console.WriteLine("2");
                        break;
                    default:
                        break;
                }

            }

            private void button2_Click(object sender, EventArgs e)
            {
                IEnvelope pEnvelop = new EnvelopeClass();
                ILayer pLayer=axMapControl1.Map.get_Layer(0);
                IFeatureLayer pFeatureLayer=(IFeatureLayer)pLayer;
                IFeatureClass pFeatureClass=pFeatureLayer.FeatureClass;
                IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                IFeature pFeature = pFeatureCursor.NextFeature();
                while (pFeature != null)
                {
                    pEnvelop.Union(pFeature.Shape.Envelope);
                    pFeature = pFeatureCursor.NextFeature();
                }
                pEnvelop.Expand(1.2, 1.2, true);
                axMapControl1.ActiveView.Extent = pEnvelop.Envelope;
                axMapControl1.Refresh();
            }

            private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
            {
                label2.Text = e.mapX.ToString();
                label3.Text = e.mapY.ToString();
            }

            private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
            {
                label2.Text = e.mapX.ToString();
                label3.Text = e.mapY.ToString();
            }

            private void axMapControl3_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
            {
                label2.Text = e.mapX.ToString();
                label3.Text = e.mapY.ToString();
            }

            private void button3_Click(object sender, EventArgs e)
            {
                ICommand command = new ControlsAddDataCommandClass();
                command.OnCreate(axMapControl1.Object);
                command.OnClick();
            }


            //新建类似西安80PCS
            private IProjectedCoordinateSystem CreatePCSSimilarToXianan80(IGeographicCoordinateSystem pGCS, double falseEasting, double fasleNorthing,
               double centralMeridian, double scaleFactor, double latitudeOfOrigion)//
            {       
                 ISpatialReferenceFactory2 pSpatialReferenceFactory2=new SpatialReferenceEnvironmentClass();
                 IProjectionGEN pProjectionGEN=(IProjectionGEN)pSpatialReferenceFactory2.CreateProjection((int)esriSRProjectionType.esriSRProjection_GaussKruger);
                 IGeographicCoordinateSystem pGeographicCoordinateSystem = pSpatialReferenceFactory2.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type.esriSRGeoCS_Xian1980);  
                 ILinearUnit pLinearUnit=(ILinearUnit)pSpatialReferenceFactory2.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter);
                 IParameter[] pParameters=pProjectionGEN.GetDefaultParameters();
                 for( int i=0;i< pParameters.Length;i++)
                 {
                      IParameter currentParameter=pParameters[i];
                  }
                    //修改parameters
                IParameter falseEastingParameter = pParameters[0];
                falseEastingParameter.Value = falseEasting;
                IParameter fasleNorthingParameter = pParameters[1];
                fasleNorthingParameter.Value = fasleNorthing;
                IParameter centralMeridianParameter = pParameters[2];
                centralMeridianParameter.Value =centralMeridian;
                IParameter scaleFactorParameter = pParameters[3];
                scaleFactorParameter.Value =scaleFactor;
                IParameter latitudeOfOrigionParameter = pParameters[4];
                latitudeOfOrigionParameter.Value =latitudeOfOrigion;
                IProjectedCoordinateSystemEdit pPCSE = new ProjectedCoordinateSystemClass();
                object name = "new Dom Project cooridinate system";
                object alias="nDPos";
                object abbreviation="NDPCS";
                object remarks = "most eastern province in China";
                object usage="when making maps of new Dom";
                object gcsobject = pGeographicCoordinateSystem as object;
                object unitobject = pLinearUnit as object;
                object projection = pProjectionGEN as object;
                object parameters = pParameters as object;

                pPCSE.Define(ref name,ref alias,ref abbreviation,ref remarks,ref usage,ref gcsobject,ref unitobject,ref projection,ref parameters);
                IProjectedCoordinateSystem pPCS = (IProjectedCoordinateSystem)pPCSE;
                return pPCS;
                


             }

            //新建类似北京54PCS
            private IProjectedCoordinateSystem CreatePCSSimilarToBeijing54(IGeographicCoordinateSystem pGCS, double falseEasting, double fasleNorthing,
              double centralMeridian, double scaleFactor, double latitudeOfOrigion)//
            {
                ISpatialReferenceFactory2 pSpatialReferenceFactory2 = new SpatialReferenceEnvironmentClass();
                IProjectionGEN pProjectionGEN = (IProjectionGEN)pSpatialReferenceFactory2.CreateProjection((int)esriSRProjectionType.esriSRProjection_GaussKruger);
                IGeographicCoordinateSystem pGeographicCoordinateSystem = pSpatialReferenceFactory2.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
                ILinearUnit pLinearUnit = (ILinearUnit)pSpatialReferenceFactory2.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter);
                IParameter[] pParameters = pProjectionGEN.GetDefaultParameters();
                for (int i = 0; i < pParameters.Length; i++)
                {
                    IParameter currentParameter = pParameters[i];
                }
                //修改parameters
                IParameter falseEastingParameter = pParameters[0];
                falseEastingParameter.Value = falseEasting;
                IParameter fasleNorthingParameter = pParameters[1];
                fasleNorthingParameter.Value = fasleNorthing;
                IParameter centralMeridianParameter = pParameters[2];
                centralMeridianParameter.Value = centralMeridian;
                IParameter scaleFactorParameter = pParameters[3];
                scaleFactorParameter.Value = scaleFactor;
                IParameter latitudeOfOrigionParameter = pParameters[4];
                latitudeOfOrigionParameter.Value = latitudeOfOrigion;
                IProjectedCoordinateSystemEdit pPCSE = new ProjectedCoordinateSystemClass();
                object name = "new Dom Project cooridinate system";
                object alias = "nDPos";
                object abbreviation = "NDPCS";
                object remarks = "most eastern province in China";
                object usage = "when making maps of new Dom";
                object gcsobject = pGeographicCoordinateSystem as object;
                object unitobject = pLinearUnit as object;
                object projection = pProjectionGEN as object;
                object parameters = pParameters as object;

                pPCSE.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcsobject, ref unitobject, ref projection, ref parameters);
                IProjectedCoordinateSystem pPCS = (IProjectedCoordinateSystem)pPCSE;
                return pPCS;



            }


            //新建类似WGS1984PCS
            private IProjectedCoordinateSystem CreatePCSSimilarToWGS1984(IGeographicCoordinateSystem pGCS, double falseEasting, double fasleNorthing,
              double centralMeridian, double scaleFactor, double latitudeOfOrigion)//
            {
                ISpatialReferenceFactory2 pSpatialReferenceFactory2 = new SpatialReferenceEnvironmentClass();
                IProjectionGEN pProjectionGEN = (IProjectionGEN)pSpatialReferenceFactory2.CreateProjection((int)esriSRProjectionType.esriSRProjection_GaussKruger);
                IGeographicCoordinateSystem pGeographicCoordinateSystem = pSpatialReferenceFactory2.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                ILinearUnit pLinearUnit = (ILinearUnit)pSpatialReferenceFactory2.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter);
                IParameter[] pParameters = pProjectionGEN.GetDefaultParameters();
                for (int i = 0; i < pParameters.Length; i++)
                {
                    IParameter currentParameter = pParameters[i];
                }
                //修改parameters
                IParameter falseEastingParameter = pParameters[0];
                falseEastingParameter.Value = falseEasting;
                IParameter fasleNorthingParameter = pParameters[1];
                fasleNorthingParameter.Value = fasleNorthing;
                IParameter centralMeridianParameter = pParameters[2];
                centralMeridianParameter.Value = centralMeridian;
                IParameter scaleFactorParameter = pParameters[3];
                scaleFactorParameter.Value = scaleFactor;
                IParameter latitudeOfOrigionParameter = pParameters[4];
                latitudeOfOrigionParameter.Value = latitudeOfOrigion;
                IProjectedCoordinateSystemEdit pPCSE = new ProjectedCoordinateSystemClass();
                object name = "new Dom Project cooridinate system";
                object alias = "ndpos";
                object abbreviation = "NDPCS";
                object remarks = "most eastern province in China";
                object usage = "when making maps of new Dom";
                object gcsobject = pGeographicCoordinateSystem as object;
                object unitobject = pLinearUnit as object;
                object projection = pProjectionGEN as object;
                object parameters = pParameters as object;

                pPCSE.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcsobject, ref unitobject, ref projection, ref parameters);

                IProjectedCoordinateSystem pPCS = (IProjectedCoordinateSystem)pPCSE;
                return pPCS;
            }


            private void button1_Click_1(object sender, EventArgs e)
            {
                ITable pTable=pPublicFeatureWorkspace.OpenTable("DomDataTest");
                int indexofArea=pTable.Fields.FindField("AreaDefinition");
                int indexofGCS = pTable.Fields.FindField("Globle");
                ICursor pCursor=pTable.Search(null,false);
                IRow pRow=pCursor.NextRow();
                string StrXY=string.Empty;
                string StrGCS = string.Empty;
                while(pRow!=null)
                 {
                     StrGCS = (string)pRow.get_Value(indexofGCS);
                     //如果pRow的“数据坐标系”是北京54  
                    switch ( StrGCS )
                    {
                        case "北京54":

                            Globle = "北京54";
                            StrXY = (string)pRow.get_Value(indexofArea);
                            XY = StrXY;
                            break;
                        case  "西安80":
                            StrXY = (string)pRow.get_Value(indexofArea);
                            XY = StrXY;

                            break;
                        case  "WGS84":
                            StrXY = (string)pRow.get_Value(indexofArea);
                            XY=StrXY;

                            break;
                        default:
                            break;

                    }           




                     //如果pRow的“数据坐标系”是西安80                                   




                     //如果pRow的“数据坐标系”是WGS84
                    pRow = pCursor.NextRow();

                  }

     


            }

            //解析字符串
            private string[] ParseAreaDefinition(string AreaStr)
            {
                int begin;
                int end;
                string[] split2;
                string[] split1;
                string sub = string.Empty;
                    
                split1 = AreaStr.Split(new char[] { '+', '-' });
                foreach (string a in split1)
                {
                    if (a.Trim() != "")
                    {
                        begin = a.IndexOf('(');
                        end = a.IndexOf(')');
                        sub = a.Substring(begin + 1, end - begin - 1);
                        split2 = sub.Split(new char[] { ';' });
                      

                    }

                }
                return split2;

            }

            private void button2_Click_1(object sender, EventArgs e)
            {


                IWorkspaceFactory pInMemoryWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
                IWorkspaceName pWorkspaceName = pInMemoryWorkspaceFactory.Create("", "InMemoryWorkspace", null, 0);
                IName pName = (IName)pWorkspaceName;
                IWorkspace pInMemoryWorkspace = (IWorkspace)pName.Open();
                IFeatureWorkspace pInMemoryFeatureWorkspace = (IFeatureWorkspace)pInMemoryWorkspace;
                //-----------------------------------------------------------------------------

                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = (IFieldEdit)pField;

                pFieldEdit.Name_2 = "Globle";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldEdit.Length_2 = 50;
                pFieldsEdit.AddField(pField);

                 IFeatureClass pInMemoryFeatureClass = pInMemoryFeatureWorkspace.CreateFeatureClass("InMemory", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

                //--------------------------------------------------------------------------------

                 IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pInMemoryFeatureWorkspace;

                 pWorkspaceEdit.StartEditing(true);
                 pWorkspaceEdit.StartEditOperation();


                 //设置几何字段

                 string[] strXY = ParseAreaDefinition(XY);

                 IPolygon pPolygon = new PolygonClass();
                 IPointCollection pPointCollection = (IPointCollection)pPolygon;
                 IPoint pPoint;
                 object _missing = Type.Missing;
                 double x, y;
                 for (int i = 0; i < strXY.Length; i++)
                 {
                     XY = strXY[i].Split(new char[] { ',', ',' });
                     x = double.Parse(XY[0]);
                     y = double.Parse(XY[1]);
                     pPoint = new PointClass();
                     pPoint.PutCoords(x, y);
                     pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
                 }
                 pPolygon.Close();
                 pPolygonsFeaure.Shape = pPolygon;

    //------------------------------------------------------------------------
                
                IFeatureBuffer pFeatureBuffer = pInMemoryFeatureClass.CreateFeatureBuffer();
                 IFeatureCursor pFeatureCursor = pInMemoryFeatureClass.Insert(true);
                 int index;
                {


                    pFeatureBuffer.Shape = pPolygon;
                    index = pInMemoryFeatureClass.Fields.FindField("Globle");
                    pFeatureBuffer.set_Value(index, Globle);
     
                }
                pFeatureCursor.InsertFeature(pFeatureBuffer);
                pFeatureCursor.Flush();
                //-----------------------------------------------------------------------






            }


            //复制字段,包括几何字段、非几何字段和空间参考的设置
            private IFields CloneFeatureClassFields(IFeatureClass pFeatureClass, ISpatialReference pSpatialReference)
            {
                IFields pInputFields = pFeatureClass.Fields;
                IFields pOutputFields = null;
                IField pShapeField = null;
                IGeometryDefEdit pSFGeoDefEdit = null;
                IFieldChecker pFieldChecker = new FieldCheckerClass();
                IEnumFieldError obj = null;
                pFieldChecker.Validate(pInputFields, out obj, out pOutputFields);
                pShapeField = pOutputFields.get_Field(pOutputFields.FindField(pFeatureClass.ShapeFieldName));
                pSFGeoDefEdit = (IGeometryDefEdit)pShapeField.GeometryDef;
                pSFGeoDefEdit.SpatialReference_2 = pSpatialReference;
                return pOutputFields;

            }
            //创建内存FeatureClass
            private IFeatureClass CreateInMemoryFeatureClass(string name, IFields pInputFields)
            {
                IWorkspaceFactory pInMemoryWorkspaceFactory = new InMemoryWorkspaceFactoryClass();
                IWorkspaceName pWorkspaceName = pInMemoryWorkspaceFactory.Create("", "InMemoryWorkspace", null, 0);
                IName pName = (IName)pWorkspaceName;
                IWorkspace pInMemoryWorkspace = (IWorkspace)pName.Open();
                IFeatureWorkspace pInMemoryFeatureWorkspace = (IFeatureWorkspace)pInMemoryWorkspace;
                IFeatureClass pInMemoryFeatureClass = pInMemoryFeatureWorkspace.CreateFeatureClass(name, pInputFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                return pInMemoryFeatureClass;

            }
            //解析字符串






        }
    }
  • 相关阅读:
    SpringBoot集成RocketMQ报错:Bad annotation definition in @ExtRocketMQTemplateConfiguration...
    RocketMQ分析
    SpringBoot 自定义 health Actuator 原理
    【质量】容错机制
    【Java】ByteBuffer介绍
    【AWS】Essentials
    【QA123】NFR 非功能性需求
    【JVM123】OOM分析和解决
    【网络123】Http返回码
    【网络123】HTTP连接
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1457057.html
Copyright © 2020-2023  润新知