示例#1
0
 /// <summary>
 /// return Spatial Reference
 /// </summary>
 /// <returns>ISpatialReference of wgs84</returns>
 internal static ESRI.ArcGIS.Geometry.ISpatialReference returnSR()
 {
     // wgs84
     ESRI.ArcGIS.Geometry.ISpatialReferenceFactory    spatialReferenceFactory    = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
     ESRI.ArcGIS.Geometry.ISpatialReference           spatialReference           = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
     ESRI.ArcGIS.Geometry.ISpatialReferenceResolution spatialReferenceResolution = (ESRI.ArcGIS.Geometry.ISpatialReferenceResolution)spatialReference;
     return(spatialReference);
 }
示例#2
0
        private void InsertValueAndGetPos2(string FieldName)//位置和要素要同时获取,否则值和位置可能不对应
        {
            //try
            //{
            if (fatherform.MFGridView2 != null)
            {
                //添加列
                if (fatherform.MFGridView2.ColumnCount == 0)
                {
                    if (TitleField == "")
                    {
                        fatherform.MFGridView2.Columns.Add("FeatureID", "FeatureID");
                    }
                    else
                    {
                        fatherform.MFGridView2.Columns.Add(TitleField, TitleField);
                    }
                    fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                }
                else
                {
                    fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                }
                //添加值
                ILayer61 SlctdLyr    = Program.sgworld.ProjectTree.GetLayer(LayerID);
                string[] ExtractFile = SlctdLyr.DataSourceInfo.ConnectionString.Split(';');
                string   FilePath    = ExtractFile[0].Substring(9);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(FilePath), 0);
                IFeatureClass     pFeatureClass     = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(FilePath));

                bool   ReProjectOrNot = false;  //标记是否需要重投影
                string LayerCord      = SlctdLyr.CoordinateSystem.WktDescription;
                string TerrainCord    = Program.sgworld.Terrain.CoordinateSystem.WktDescription;
                if (LayerCord != TerrainCord)
                {
                    ReProjectOrNot = true;
                }

                string             AValue    = "";
                IPosition61        cPos      = null;
                List <IPosition61> Positions = new List <IPosition61>();
                double             dXCoord;
                double             dYCoord;
                double             dAltitude         = 0;
                AltitudeTypeCode   eAltitudeTypeCode = AltitudeTypeCode.ATC_ON_TERRAIN;
                double             dYaw      = 0.0;
                double             dPitch    = 0.0;
                double             dRoll     = 0.0;
                double             dDistance = 20000;
                for (int i = 0; i < pFeatureClass.FeatureCount(null); i++)
                {
                    //插入值
                    AValue = pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(FieldName)).ToString();
                    if (fatherform.MFGridView2.ColumnCount == 2)
                    {
                        if (fatherform.MFGridView2.Columns[0].Name == "FeatureID")
                        {
                            this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).OID, AValue);
                        }
                        else
                        {
                            this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(TitleField)).ToString(), AValue);
                        }
                    }
                    else
                    {
                        if (this.fatherform.MFGridView2.RowCount > 0)
                        {
                            fatherform.MFGridView2.Rows[i].Cells[FieldName].Value = AValue;
                        }
                    }
                    //获取位置
                    ESRI.ArcGIS.Geometry.IGeometry pGeometry = pFeatureClass.GetFeature(i).Shape;
                    if (ReProjectOrNot)
                    {
                        ESRI.ArcGIS.Geometry.ISpatialReferenceFactory    srFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
                        ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem gcs       = srFactory.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
                        ESRI.ArcGIS.Geometry.ISpatialReference           sr1       = gcs;
                        pGeometry.Project(sr1);
                    }
                    ESRI.ArcGIS.Geometry.IPoint pPoint = null;
                    switch (pFeatureClass.ShapeType)
                    {
                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                        pPoint = (ESRI.ArcGIS.Geometry.IPoint)pGeometry;

                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                        pPoint = ((ESRI.ArcGIS.Geometry.IPolyline)pGeometry).ToPoint;
                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                        pPoint = ((ESRI.ArcGIS.Geometry.IArea)(ESRI.ArcGIS.Geometry.IPolygon) pGeometry).Centroid;
                        break;

                    default:
                        break;
                    }
                    dXCoord = pPoint.X;
                    dYCoord = pPoint.Y;
                    cPos    = Program.sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
                    Positions.Add(cPos);
                }
                if (Positions != null)
                {
                    fatherform.StaThemePos = Positions;
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("Unexpected Error:" + ex.Message);
            //}
            /***20130227杨漾(去掉trycatch,抛给上层trycatch处理异常)****/
        }
示例#3
0
        //位置和要素要同时获取,否则值和位置可能不对应
        private void InsertValueAndGetPos2(string FieldName)
        {
            //try
            //{
                if (fatherform.MFGridView2 != null)
                {
                    //添加列
                    if (fatherform.MFGridView2.ColumnCount == 0)
                    {
                        if(TitleField == "")
                            fatherform.MFGridView2.Columns.Add("FeatureID", "FeatureID");
                        else
                            fatherform.MFGridView2.Columns.Add(TitleField, TitleField);
                        fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                    }
                    else
                    {
                        fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                    }
                    //添加值
                    ILayer61 SlctdLyr = Program.sgworld.ProjectTree.GetLayer(LayerID);
                    string[] ExtractFile = SlctdLyr.DataSourceInfo.ConnectionString.Split(';');
                    string FilePath = ExtractFile[0].Substring(9);

                    IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(FilePath), 0);
                    IFeatureClass pFeatureClass = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(FilePath));

                    bool ReProjectOrNot = false;//标记是否需要重投影
                    string LayerCord = SlctdLyr.CoordinateSystem.WktDescription;
                    string TerrainCord = Program.sgworld.Terrain.CoordinateSystem.WktDescription;
                    if (LayerCord != TerrainCord)
                        ReProjectOrNot = true;

                    string AValue = "";
                    IPosition61 cPos = null;
                    List<IPosition61> Positions = new List<IPosition61>();
                    double dXCoord;
                    double dYCoord;
                    double dAltitude = 0;
                    AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_ON_TERRAIN;
                    double dYaw = 0.0;
                    double dPitch = 0.0;
                    double dRoll = 0.0;
                    double dDistance = 20000;
                    for (int i = 0; i < pFeatureClass.FeatureCount(null); i++)
                    {
                        //插入值
                        AValue = pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(FieldName)).ToString();
                        if (fatherform.MFGridView2.ColumnCount == 2)
                        {
                            if (fatherform.MFGridView2.Columns[0].Name == "FeatureID")
                                this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).OID, AValue);
                            else
                                this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(TitleField)).ToString(), AValue);
                        }
                        else
                        {
                            if (this.fatherform.MFGridView2.RowCount > 0)
                                fatherform.MFGridView2.Rows[i].Cells[FieldName].Value = AValue;
                        }
                        //获取位置
                        ESRI.ArcGIS.Geometry.IGeometry pGeometry = pFeatureClass.GetFeature(i).Shape;
                        if (ReProjectOrNot)
                        {
                            ESRI.ArcGIS.Geometry.ISpatialReferenceFactory srFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
                            ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
                            ESRI.ArcGIS.Geometry.ISpatialReference sr1 = gcs;
                            pGeometry.Project(sr1);
                        }
                        ESRI.ArcGIS.Geometry.IPoint pPoint = null;
                        switch (pFeatureClass.ShapeType)
                        {
                            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                                pPoint = (ESRI.ArcGIS.Geometry.IPoint)pGeometry;

                                break;
                            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                                pPoint = ((ESRI.ArcGIS.Geometry.IPolyline)pGeometry).ToPoint;
                                break;
                            case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                                pPoint = ((ESRI.ArcGIS.Geometry.IArea)(ESRI.ArcGIS.Geometry.IPolygon)pGeometry).Centroid;
                                break;
                            default:
                                break;
                        }
                        dXCoord = pPoint.X;
                        dYCoord = pPoint.Y;
                        cPos = Program.sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
                        Positions.Add(cPos);
                    }
                    if (Positions != null)
                        fatherform.StaThemePos = Positions;
                }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("Unexpected Error:" + ex.Message);
            //}
            /***20130227杨漾(去掉trycatch,抛给上层trycatch处理异常)****/
        }