public bool projectBackward(IFeatureClass pInputFeatureClass, IRasterLayer pDemLayer, string szXmlFilename,
                                    ref IFeatureClass pOutputPolylineFeatureClass, ref IFeatureClass pOutputPointFeatureClass)
        {
            if (pInputFeatureClass == null || pDemLayer == null || string.IsNullOrEmpty(szXmlFilename) || pOutputPointFeatureClass == null || pOutputPolylineFeatureClass == null)
            {
                return(false);
            }

            #region 读取DEM文件
            IRasterLayer pRasterLayer = pDemLayer;// new RasterLayerClass();
            //pRasterLayer.CreateFromFilePath(szDemFilename);
            IRaster      pDemRaster      = pRasterLayer.Raster;
            IRasterProps pDemRasterProps = pDemRaster as IRasterProps;
            #endregion

            #region 读取相机姿态参数
            ClsCameraPara cameraPara = ParseXmlFileToGetPara(szXmlFilename);
            if (cameraPara == null)
            {
                return(false);
            }

            //根据姿态参数获得旋转矩阵
            OriAngle oriAngle      = new OriAngle();
            Matrix   pRotateMatrix = new Matrix(3, 3);

            oriAngle.kap = cameraPara.dKappa;
            oriAngle.omg = cameraPara.dOmg;
            oriAngle.phi = cameraPara.dPhi;
            if (!ClsGetCameraView.OPK2RMat(oriAngle, ref pRotateMatrix))
            {
                return(false);
            }
            #endregion

            #region 得到曲线信息
            List <ISegmentCollection> pSegmentCollection = new List <ISegmentCollection>();
            List <IFeature>           pFeatureList       = new List <IFeature>();
            IFeatureCursor            pFCursor           = pInputFeatureClass.Search(null, false);
            IFeature pFeature = null;// pFCursor.NextFeature();
            while ((pFeature = pFCursor.NextFeature()) != null)
            {
                IPolyline pPolyline = pFeature.Shape as IPolyline;
                if (pPolyline == null)
                {
                    //pFeature = pFCursor.NextFeature();
                    continue;
                }

                IFeature pTmpFeature = pFeature;
                pFeatureList.Add(pTmpFeature);

                ISegmentCollection pCurrentSegmentCollection = pPolyline as ISegmentCollection;
                pSegmentCollection.Add(pCurrentSegmentCollection);
            }
            #endregion

            #region 节点位置反投影
            List <List <Pt2d> > ptImageFeaturePoints            = new List <List <Pt2d> >();
            List <List <Pt2d> > ptImageFeaturePointsForPointShp = new List <List <Pt2d> >();
            ClsGetCameraView    pGetCameraView = new ClsGetCameraView();

            for (int i = 0; i < pSegmentCollection.Count; i++)
            {
                List <Pt2d> ptSingleImageFeaturePoints            = new List <Pt2d>();
                List <Pt2d> ptSingleImageFeaturePointsForPointShp = new List <Pt2d>();
                for (int j = 0; j < pSegmentCollection[i].SegmentCount; j++)
                {
                    ISegment pCurrentSegment = pSegmentCollection[i].get_Segment(j);
                    if (pCurrentSegment == null)
                    {
                        continue;
                    }

                    //直线
                    if (pCurrentSegment.GeometryType == esriGeometryType.esriGeometryLine)
                    {
                        ILine pLine = pCurrentSegment as ILine;

                        //起始点
                        IPoint ptFrom   = pLine.FromPoint;
                        Pt2d   ptFrom2d = getProjectBackwardPoint(ptFrom, pDemRaster, pGetCameraView, pRotateMatrix, cameraPara);
                        if (ptFrom2d != null)
                        {
                            ptSingleImageFeaturePoints.Add(ptFrom2d);
                            ptSingleImageFeaturePointsForPointShp.Add(ptFrom2d);
                        }

                        //终止点
                        IPoint ptTo   = pLine.ToPoint;
                        Pt2d   ptTo2d = getProjectBackwardPoint(ptTo, pDemRaster, pGetCameraView, pRotateMatrix, cameraPara);
                        if (ptTo2d != null)
                        {
                            if (j == pSegmentCollection[i].SegmentCount - 1)   //最后一条直线段
                            {
                                ptSingleImageFeaturePointsForPointShp.Add(ptTo2d);
                                ptSingleImageFeaturePoints.Add(ptTo2d);
                            }
                        }
                    }
                    else if (pCurrentSegment.GeometryType == esriGeometryType.esriGeometryCircularArc) //圆弧
                    {
                        ICircularArc pCircularArc  = pCurrentSegment as ICircularArc;
                        double       dbCurveLength = pCircularArc.Length;
                        int          nCount        = 15;
                        double       dbOffset      = dbCurveLength / nCount;
                        for (int nCurrent = 0; nCurrent <= nCount; nCurrent++)
                        {
                            IPoint ptCurrent = new Point();
                            pCircularArc.QueryPoint(esriSegmentExtension.esriNoExtension, nCurrent * dbOffset, false, ptCurrent);
                            Pt2d ptCurrentImagePoint = getProjectBackwardPoint(ptCurrent, pDemRaster, pGetCameraView, pRotateMatrix, cameraPara);
                            if (ptCurrentImagePoint != null)
                            {
                                ptSingleImageFeaturePoints.Add(ptCurrentImagePoint);

                                //只保留端点的信息,用于创建点SHP图层
                                if (nCurrent == 0 || nCurrent == nCount)
                                {
                                    ptSingleImageFeaturePointsForPointShp.Add(ptCurrentImagePoint);
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                ptImageFeaturePoints.Add(ptSingleImageFeaturePoints);
                ptImageFeaturePointsForPointShp.Add(ptSingleImageFeaturePointsForPointShp);
            }
            #endregion

            #region 把节点位置信息写入
            IDataset   dataset   = (IDataset)pOutputPolylineFeatureClass;
            IWorkspace workspace = dataset.Workspace;

            //Cast for an IWorkspaceEdit
            IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();

            //////////////////////////////////////////////////////////////////////////
            //整条路线的添加
            IFeatureCursor pOutFCursor = null;
            for (int i = 0; i < ptImageFeaturePoints.Count; i++)
            {
                int            nPtsCount      = ptImageFeaturePoints[i].Count;
                IFeatureBuffer pFeatureBuffer = pOutputPolylineFeatureClass.CreateFeatureBuffer();
                pOutFCursor = pOutputPolylineFeatureClass.Insert(true);

                IPolyline        pPolyline        = new PolylineClass();
                IPointCollection pPointCollection = pPolyline as IPointCollection;

                for (int j = 0; j < nPtsCount; j++)
                {
                    IPoint pt = new PointClass();
                    pt.PutCoords(ptImageFeaturePoints[i][j].X, ptImageFeaturePoints[i][j].Y);
                    pPointCollection.AddPoint(pt);
                }

                if (!ClsGDBDataCommon.CopyFeatureFieldValue(pFeatureList[i], pFeatureBuffer as IFeature))
                {
                    continue;
                }
                pFeatureBuffer.Shape = pPolyline as IGeometry;
                object featureOID = pOutFCursor.InsertFeature(pFeatureBuffer);
            }

            if (pOutFCursor != null)
            {
                pOutFCursor.Flush();
            }

            //分段路线的添加
            for (int i = 0; i < ptImageFeaturePoints.Count; i++)
            {
                int nPtsCount = ptImageFeaturePoints[i].Count;
                for (int j = 0; j < nPtsCount - 1; j++)
                {
                    IFeatureBuffer pFeatureBuffer = pOutputPolylineFeatureClass.CreateFeatureBuffer();
                    pOutFCursor = pOutputPolylineFeatureClass.Insert(true);
                    IPolyline        pPolyline        = new PolylineClass();
                    IPointCollection pPointCollection = pPolyline as IPointCollection;

                    IPoint pt = new PointClass();
                    pt.PutCoords(ptImageFeaturePoints[i][j].X, ptImageFeaturePoints[i][j].Y);
                    pPointCollection.AddPoint(pt);
                    pt.PutCoords(ptImageFeaturePoints[i][j + 1].X, ptImageFeaturePoints[i][j + 1].Y);
                    pPointCollection.AddPoint(pt);

                    if (!ClsGDBDataCommon.CopyFeatureFieldValue(pFeatureList[i], pFeatureBuffer as IFeature))
                    {
                        continue;
                    }
                    pFeatureBuffer.Shape = pPolyline as IGeometry;
                    object featureOID = pOutFCursor.InsertFeature(pFeatureBuffer);
                }
            }
            if (pOutFCursor != null)
            {
                pOutFCursor.Flush();
            }

            //featureCursor.Flush();
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            #endregion

            #region 点SHP文件的添加
            IDataset   pPointDataset   = (IDataset)pOutputPointFeatureClass;
            IWorkspace pPointWorkspace = pPointDataset.Workspace;

            //Cast for an IWorkspaceEdit
            IWorkspaceEdit pPointWorkspaceEdit = pPointWorkspace as IWorkspaceEdit;
            pPointWorkspaceEdit.StartEditing(true);
            pPointWorkspaceEdit.StartEditOperation();

            IFeatureCursor pOutPointFCursor = null;
            for (int i = 0; i < ptImageFeaturePointsForPointShp.Count; i++)
            {
                //int nSegmentCount = pSegmentCollection[i].SegmentCount;

                //IMultipoint pMultiPoint = new MultipointClass();
                for (int j = 0; j < ptImageFeaturePointsForPointShp[i].Count; j++)
                {
                    IFeatureBuffer pFeatureBuffer = pOutputPointFeatureClass.CreateFeatureBuffer();
                    pOutPointFCursor = pOutputPointFeatureClass.Insert(true);
                    IPoint pt   = new PointClass();
                    Pt2d   pt2d = ptImageFeaturePointsForPointShp[i][j];
                    pt.PutCoords(pt2d.X, pt2d.Y);

                    //CopyFeatureField(pFeatureList[i], pFeatureBuffer);
                    pFeatureBuffer.Shape = pt as IGeometry;
                    object featureOID = pOutPointFCursor.InsertFeature(pFeatureBuffer);
                }
            }

            if (pOutPointFCursor != null)
            {
                pOutPointFCursor.Flush();
            }

            //featureCursor.Flush();
            pPointWorkspaceEdit.StopEditOperation();
            pPointWorkspaceEdit.StopEditing(true);
            #endregion

            return(true);
        }
Beispiel #2
0
        //}

        /// <summary>
        /// 矢量转换函数
        /// </summary>
        private void exprotMatrix()
        {
            ClsGDBDataCommon comm = new ClsGDBDataCommon();

            if (!textOutData.Text.EndsWith("shp"))
            {
                //timerShow.Start();
                MessageBox.Show("输出文件名不是shp文件!");
                return;
            }
            object featureOID;

            String strFullName = textOutData.Text;
            string strPath     = System.IO.Path.GetDirectoryName(strFullName);
            string strName     = System.IO.Path.GetFileName(strFullName);

            ILayer player = null;

            for (int i = 0; i < pMapControl.Map.LayerCount; i++)
            {
                if (pMapControl.Map.Layer[i].Name == cmbLayer.Text)
                {
                    player = pMapControl.Map.Layer[i];
                    break;
                }
            }
            IFeatureLayer pFlayer = player as IFeatureLayer;
            IFeatureClass pFclass = pFlayer.FeatureClass;
            IFields       pFields = pFclass.Fields;
            //设置空间参考
            ISpatialReference pSpatialRef;
            IGeoDataset       pGeo = (IGeoDataset)pFlayer;

            pSpatialRef = pGeo.SpatialReference;

            IFeatureClass pFtClassNew = comm.CreateShapefile(strPath, strName, pFields, pSpatialRef);
            //for (int i = 0; i < pFtClassNew.Fields.FieldCount;i++ )
            //{
            //    if (pFtClassNew.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry &&
            //      pFtClassNew.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeOID)
            //    {
            //        pFtClassNew.Fields.get_Field(i).IsNullable = true;
            //    }
            //}


            IFeatureCursor pFC = pFlayer.FeatureClass.Search(null, false);
            IFeature       pF  = pFC.NextFeature();

            while (pF != null)
            {
                if (pFclass.ShapeType == esriGeometryType.esriGeometryMultipoint || pFclass.ShapeType == esriGeometryType.esriGeometryPoint)
                {
                    double[] oldarray = new double[3];
                    double[] newarray = new double[3];
                    Matrix   matrix   = new Matrix();

                    IPoint pPointOld = pF.Shape as IPoint;
                    IPoint pPointNew = new PointClass();
                    oldarray[0] = pPointOld.X;
                    oldarray[1] = pPointOld.Y;
                    if (pPointOld.Z.ToString() == "NaN" || pPointOld.Z.ToString() == "非数字")
                    {
                        oldarray[2] = 0;//pPointOld.Z;
                    }
                    else
                    {
                        oldarray[2] = pPointOld.Z;
                    }
                    matrix.coord_Trans(oldarray, rotateMat, tranVec, newarray);

                    pPointNew.X = newarray[0];
                    pPointNew.Y = newarray[1];
                    if (pPointOld.Z.ToString() == "NaN" || pPointOld.Z.ToString() == "非数字")
                    {
                        pPointNew.Z = 0;
                    }
                    else
                    {
                        pPointNew.Z = newarray[2];
                    }


                    IFeature pFeatureTemp = pFtClassNew.CreateFeature();
                    pFeatureTemp.Shape = pPointNew as IGeometry;
                    ClsGDBDataCommon.CopyFeatureFieldValue(pF, pFeatureTemp);
                    pFeatureTemp.Store();
                }
                else if (pFclass.ShapeType == esriGeometryType.esriGeometryLine || pFclass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    double[] oldarrayS = new double[3];
                    double[] oldarrayT = new double[3];
                    double[] newarrayS = new double[3];
                    double[] newarrayT = new double[3];
                    Matrix   matrix    = new Matrix();

                    ISegmentCollection pSegCOld = pF.Shape as ISegmentCollection;
                    ISegmentCollection pSegCNew = new PolylineClass();
                    // ISegment pSegmentNEW = new LineClass();
                    //ILine pLine = new LineClass();
                    IPoint pPointF = new PointClass();
                    IPoint pPointT = new PointClass();

                    for (int i = 0; i < pSegCOld.SegmentCount; i++)
                    {
                        ISegment pSegmentNEW = new LineClass();
                        ISegment pseg        = pSegCOld.Segment[i];
                        oldarrayS[0] = pseg.FromPoint.X;
                        oldarrayS[1] = pseg.FromPoint.Y;
                        if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字")
                        {
                            oldarrayS[2] = 0;
                        }
                        else
                        {
                            oldarrayS[2] = pseg.FromPoint.Z;
                        }
                        matrix.coord_Trans(oldarrayS, rotateMat, tranVec, newarrayS);
                        pPointF.X = newarrayS[0];
                        pPointF.Y = newarrayS[1];
                        if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字")
                        {
                            pPointF.Z = 0;
                        }
                        else
                        {
                            pPointF.Z = newarrayS[2];
                        }
                        pSegmentNEW.FromPoint = pPointF;
                        oldarrayT[0]          = pseg.ToPoint.X;
                        oldarrayT[1]          = pseg.ToPoint.Y;
                        if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字")
                        {
                            oldarrayT[2] = 0;
                        }
                        else
                        {
                            oldarrayT[2] = pseg.ToPoint.Z;
                        }
                        matrix.coord_Trans(oldarrayT, rotateMat, tranVec, newarrayT);
                        pPointT.X = newarrayT[0];
                        pPointT.Y = newarrayT[1];
                        if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字")
                        {
                            pPointT.Z = 0;
                        }
                        else
                        {
                            pPointT.Z = newarrayT[2];
                        }
                        pSegmentNEW.ToPoint = pPointT;

                        pSegCNew.AddSegment(pSegmentNEW);
                    }
                    IFeature pFeatureTemp = pFtClassNew.CreateFeature();
                    pFeatureTemp.Shape = pSegCNew as IGeometry;
                    ClsGDBDataCommon.CopyFeatureFieldValue(pF, pFeatureTemp);
                    pFeatureTemp.Store();
                }

                else if (pFclass.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                    double[] oldarrayS = new double[3];
                    double[] oldarrayT = new double[3];
                    double[] newarrayS = new double[3];
                    double[] newarrayT = new double[3];
                    Matrix   matrix    = new Matrix();

                    IGeometryCollection pGCollectionOld = pF.Shape as IGeometryCollection;
                    IGeometryCollection pGCollectionNew = new PolygonClass();
                    ISegmentCollection  psegCOld        = new RingClass();


                    //ILine pLine = new LineClass();
                    IPoint pPointF = new PointClass();
                    IPoint pPointT = new PointClass();

                    //IPointCollection pPointCOld = new PolygonClass();
                    //IPointCollection pPointCNew = new PolygonClass();
                    //pPointCOld=pF.Shape as IPointCollection;
                    //for (int i = 0; i < pPointCOld.PointCount;i++ )
                    //{
                    //    pPointF = pPointCOld.Point[i];
                    //    oldarrayS[0] = pPointF.X;
                    //    oldarrayS[0] = pPointF.Y;
                    //    if (pPointF.Z.ToString() == "NaN" || pPointF.Z.ToString() == "非数字")
                    //    {
                    //        oldarrayS[2] = 0;//pPointOld.Z;
                    //    }
                    //    else
                    //    {
                    //        oldarrayS[2] = pPointF.Z;
                    //    }
                    //    matrix.coord_Trans(oldarrayS, rotateMat, tranVec, newarrayT);
                    //    pPointT.X = newarrayT[0];
                    //    pPointT.Y = newarrayT[1];
                    //    if (pPointF.Z.ToString() == "NaN" || pPointF.Z.ToString() == "非数字")
                    //    {
                    //        pPointT.Z = 0;
                    //    }
                    //    else
                    //    {
                    //        pPointT.Z = newarrayT[2];
                    //    }
                    //    pPointCNew.AddPoint(pPointT);
                    //}
                    //IPolygon pPolygon = pPointCNew as IPolygon;
                    //pPolygon.Close();
                    //IFeature pFeatureTemp = pFtClassNew.CreateFeature();
                    //pFeatureTemp.Shape = pPolygon as IGeometry;
                    //CopyFeatureField(pF, pFeatureTemp);
                    //pFeatureTemp.Store();

                    ///方法一
                    //IPolygon pPolygon=pF.Shape as IPolygon;
                    //IRing pExterRingOld = new RingClass();
                    //IRing pExterRingNew = new RingClass();

                    //for (int i = 0; i<pPolygon.ExteriorRingCount;i++ )
                    //{
                    //    pExterRingOld = pPolygon.FindExteriorRing(null);
                    //}


                    //方法二
                    for (int i = 0; i < pGCollectionOld.GeometryCount; i++)
                    {
                        psegCOld = pGCollectionOld.Geometry[i] as ISegmentCollection;
                        ISegmentCollection pSegCNew = new RingClass();
                        for (int j = 0; j < psegCOld.SegmentCount - 1; j++)
                        {
                            ISegment pSegmentNEW = new LineClass();
                            ISegment pseg        = psegCOld.Segment[j];
                            oldarrayS[0] = pseg.FromPoint.X;
                            oldarrayS[1] = pseg.FromPoint.Y;
                            if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字")
                            {
                                oldarrayS[2] = 0;
                            }
                            else
                            {
                                oldarrayS[2] = pseg.FromPoint.Z;
                            }
                            matrix.coord_Trans(oldarrayS, rotateMat, tranVec, newarrayS);
                            pPointF.X = newarrayS[0];
                            pPointF.Y = newarrayS[1];
                            if (pseg.FromPoint.Z.ToString() == "NaN" || pseg.FromPoint.Z.ToString() == "非数字")
                            {
                                pPointF.Z = 0;
                            }
                            else
                            {
                                pPointF.Z = newarrayS[2];
                            }
                            pSegmentNEW.FromPoint = pPointF;
                            oldarrayT[0]          = pseg.ToPoint.X;
                            oldarrayT[1]          = pseg.ToPoint.Y;
                            if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字")
                            {
                                oldarrayT[2] = 0;
                            }
                            else
                            {
                                oldarrayT[2] = pseg.ToPoint.Z;
                            }
                            matrix.coord_Trans(oldarrayT, rotateMat, tranVec, newarrayT);
                            pPointT.X = newarrayT[0];
                            pPointT.Y = newarrayT[1];
                            if (pseg.ToPoint.Z.ToString() == "NaN" || pseg.ToPoint.Z.ToString() == "非数字")
                            {
                                pPointT.Z = 0;
                            }
                            else
                            {
                                pPointT.Z = newarrayT[2];
                            }
                            pSegmentNEW.ToPoint = pPointT;

                            pSegCNew.AddSegment(pSegmentNEW);
                        }
                        IRing pRing = pSegCNew as IRing;
                        pRing.Close();
                        object ob = Type.Missing;
                        pGCollectionNew.AddGeometry(pRing as IGeometry, ref ob, ref ob);
                    }
                    IFeature pFeatureTemp = pFtClassNew.CreateFeature();
                    pFeatureTemp.Shape = pGCollectionNew as IGeometry;
                    ClsGDBDataCommon.CopyFeatureFieldValue(pF, pFeatureTemp);
                    pFeatureTemp.Store();
                }


                pF = pFC.NextFeature();
            }

            IFeatureLayer ppFeatureLayer = new FeatureLayerClass();

            ppFeatureLayer.FeatureClass = pFtClassNew;
            ppFeatureLayer.Name         = strName;
            pMapControl.AddLayer(ppFeatureLayer as ILayer);
            //pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            this.Close();
        }
        public bool projectBackward(string szInputShpFilename, IRasterLayer pDemLayer, string szXmlFilename, string szOutShpFilename)
        {
            if (string.IsNullOrEmpty(szInputShpFilename) || pDemLayer == null || string.IsNullOrEmpty(szXmlFilename) || string.IsNullOrEmpty(szOutShpFilename))
            {
                return(false);
            }

            ClsGDBDataCommon processDataCommon = new ClsGDBDataCommon();
            string           strInputPath      = System.IO.Path.GetDirectoryName(szInputShpFilename);
            string           strInputName      = System.IO.Path.GetFileName(szInputShpFilename);

            #region 读取SHP文件
            IWorkspace        pWorkspace        = processDataCommon.OpenFromShapefile(strInputPath);
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass     pInputFC          = pFeatureWorkspace.OpenFeatureClass(strInputName);
            #endregion

            #region 读取DEM文件
            IRasterLayer pRasterLayer = pDemLayer;// new RasterLayerClass();
            //pRasterLayer.CreateFromFilePath(szDemFilename);
            IRaster      pDemRaster      = pRasterLayer.Raster;
            IRasterProps pDemRasterProps = pDemRaster as IRasterProps;
            #endregion

            #region 得到曲线信息
            List <ISegmentCollection> pSegmentCollection = new List <ISegmentCollection>();
            List <IFeature>           pFeatureList       = new List <IFeature>();
            IFeatureCursor            pFCursor           = pInputFC.Search(null, false);
            IFeature pFeature = null;// pFCursor.NextFeature();
            while ((pFeature = pFCursor.NextFeature()) != null)
            {
                IPolyline pPolyline = pFeature.Shape as IPolyline;
                if (pPolyline == null)
                {
                    //pFeature = pFCursor.NextFeature();
                    continue;
                }

                IFeature pTmpFeature = pFeature;
                pFeatureList.Add(pTmpFeature);

                ISegmentCollection pCurrentSegmentCollection = pPolyline as ISegmentCollection;
                pSegmentCollection.Add(pCurrentSegmentCollection);
            }
            #endregion

            #region 读取相机姿态参数
            ClsCameraPara cameraPara = ParseXmlFileToGetPara(szXmlFilename);
            if (cameraPara == null)
            {
                return(false);
            }

            //根据姿态参数获得旋转矩阵
            OriAngle oriAngle      = new OriAngle();
            Matrix   pRotateMatrix = new Matrix(3, 3);

            oriAngle.kap = cameraPara.dKappa;
            oriAngle.omg = cameraPara.dOmg;
            oriAngle.phi = cameraPara.dPhi;
            if (!ClsGetCameraView.OPK2RMat(oriAngle, ref pRotateMatrix))
            {
                return(false);
            }
            #endregion

            #region 创建输出SHP文件
            string strOutputPath      = System.IO.Path.GetDirectoryName(szOutShpFilename);
            string strOutputName      = System.IO.Path.GetFileName(szOutShpFilename);
            string strPointOutputName = System.IO.Path.GetFileNameWithoutExtension(szOutShpFilename) + "_point" + System.IO.Path.GetExtension(szOutShpFilename);

            //设置空间参考
            ISpatialReference pSpatialRef = new UnknownCoordinateSystemClass(); //没有这一句就报错,说尝试读取或写入受保护的内存。
            pSpatialRef.SetDomain(MIN_INT, MAX_INT, MIN_INT, MAX_INT);          //没有这句就抛异常来自HRESULT:0x8004120E。
            pSpatialRef.SetZDomain(MIN_INT, MAX_INT);

            //创建POLYLINE文件的字段
            IFields pFields = pInputFC.Fields;

            //创建点SHP文件的字段
            IFields     pPointFields = new FieldsClass();
            IFieldsEdit pFieldsEdit  = (IFieldsEdit)pPointFields;

            //设置字段
            IField     pField     = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;

            //创建类型为几何类型的字段
            pFieldEdit.Name_2 = "shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef     pGeoDef     = new GeometryDefClass();
            IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
            pGeoDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
            pGeoDefEdit.HasM_2             = false;
            pGeoDefEdit.HasZ_2             = false;
            pGeoDefEdit.SpatialReference_2 = pSpatialRef;
            //pFieldEdit.Name_2 = "SHAPE";
            //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            pFieldEdit.GeometryDef_2 = pGeoDef;
            pFieldEdit.IsNullable_2  = true;
            pFieldEdit.Required_2    = true;
            pFieldsEdit.AddField(pField);

            IFeatureClass pOutputFC      = processDataCommon.CreateShapefile(strOutputPath, strOutputName, pFields, pSpatialRef);
            IFeatureClass pOutputPointFC = processDataCommon.CreateShapefile(strOutputPath, strPointOutputName, pPointFields, pSpatialRef);
            if (pOutputFC == null || pOutputPointFC == null)
            {
                return(false);
            }
            #endregion

            #region 节点位置反投影
            List <List <Pt2d> > ptImageFeaturePoints            = new List <List <Pt2d> >();
            List <List <Pt2d> > ptImageFeaturePointsForPointShp = new List <List <Pt2d> >();
            ClsGetCameraView    pGetCameraView = new ClsGetCameraView();

            for (int i = 0; i < pSegmentCollection.Count; i++)
            {
                List <Pt2d> ptSingleImageFeaturePoints            = new List <Pt2d>();
                List <Pt2d> ptSingleImageFeaturePointsForPointShp = new List <Pt2d>();
                for (int j = 0; j < pSegmentCollection[i].SegmentCount; j++)
                {
                    ISegment pCurrentSegment = pSegmentCollection[i].get_Segment(j);
                    if (pCurrentSegment == null)
                    {
                        continue;
                    }

                    //直线
                    if (pCurrentSegment.GeometryType == esriGeometryType.esriGeometryLine)
                    {
                        ILine pLine = pCurrentSegment as ILine;

                        //起始点
                        IPoint ptFrom   = pLine.FromPoint;
                        Pt2d   ptFrom2d = getProjectBackwardPoint(ptFrom, pDemRaster, pGetCameraView, pRotateMatrix, cameraPara);
                        if (ptFrom2d != null)
                        {
                            ptSingleImageFeaturePoints.Add(ptFrom2d);
                            ptSingleImageFeaturePointsForPointShp.Add(ptFrom2d);
                        }

                        //终止点
                        IPoint ptTo   = pLine.ToPoint;
                        Pt2d   ptTo2d = getProjectBackwardPoint(ptTo, pDemRaster, pGetCameraView, pRotateMatrix, cameraPara);
                        if (ptTo2d != null)
                        {
                            ptSingleImageFeaturePoints.Add(ptTo2d);
                            if (j == pSegmentCollection[i].SegmentCount - 1)   //最后一条直线段
                            {
                                ptSingleImageFeaturePointsForPointShp.Add(ptTo2d);
                            }
                        }
                    }
                    else if (pCurrentSegment.GeometryType == esriGeometryType.esriGeometryCircularArc) //圆弧
                    {
                        ICircularArc pCircularArc  = pCurrentSegment as ICircularArc;
                        double       dbCurveLength = pCircularArc.Length;
                        int          nCount        = 15;
                        double       dbOffset      = dbCurveLength / nCount;
                        for (int nCurrent = 0; nCurrent < nCount; nCurrent++)
                        {
                            IPoint ptCurrent = new Point();
                            pCircularArc.QueryPoint(esriSegmentExtension.esriNoExtension, nCurrent * dbOffset, false, ptCurrent);
                            Pt2d ptCurrentImagePoint = getProjectBackwardPoint(ptCurrent, pDemRaster, pGetCameraView, pRotateMatrix, cameraPara);
                            if (ptCurrentImagePoint != null)
                            {
                                ptSingleImageFeaturePoints.Add(ptCurrentImagePoint);

                                //只保留端点的信息,用于创建点SHP图层
                                if (nCurrent == 0 || nCurrent == nCount - 1)
                                {
                                    ptSingleImageFeaturePointsForPointShp.Add(ptCurrentImagePoint);
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                ptImageFeaturePoints.Add(ptSingleImageFeaturePoints);
                ptImageFeaturePointsForPointShp.Add(ptSingleImageFeaturePointsForPointShp);
            }
            #endregion

            #region 写入POLYLINE节点信息
            IDataset   dataset   = (IDataset)pOutputFC;
            IWorkspace workspace = dataset.Workspace;

            //Cast for an IWorkspaceEdit
            IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();

            //////////////////////////////////////////////////////////////////////////
            //整条路线的添加
            IFeatureCursor pOutFCursor = null;
            for (int i = 0; i < ptImageFeaturePoints.Count; i++)
            {
                int            nPtsCount      = ptImageFeaturePoints[i].Count;
                IFeatureBuffer pFeatureBuffer = pOutputFC.CreateFeatureBuffer();
                pOutFCursor = pOutputFC.Insert(true);

                IPolyline        pPolyline        = new PolylineClass();
                IPointCollection pPointCollection = pPolyline as IPointCollection;

                for (int j = 0; j < nPtsCount; j++)
                {
                    IPoint pt = new PointClass();
                    pt.PutCoords(ptImageFeaturePoints[i][j].X, ptImageFeaturePoints[i][j].Y);
                    pPointCollection.AddPoint(pt);
                }

                if (!ClsGDBDataCommon.CopyFeatureFieldValue(pFeatureList[i], pFeatureBuffer as IFeature))
                {
                    continue;
                }

                pFeatureBuffer.Shape = pPolyline as IGeometry;
                object featureOID = pOutFCursor.InsertFeature(pFeatureBuffer);
            }
            pOutFCursor.Flush();

            //分段路线的添加
            for (int i = 0; i < ptImageFeaturePoints.Count; i++)
            {
                int nPtsCount = ptImageFeaturePoints[i].Count;
                for (int j = 0; j < nPtsCount - 1; j++)
                {
                    IFeatureBuffer pFeatureBuffer = pOutputFC.CreateFeatureBuffer();
                    pOutFCursor = pOutputFC.Insert(true);
                    IPolyline        pPolyline        = new PolylineClass();
                    IPointCollection pPointCollection = pPolyline as IPointCollection;

                    IPoint pt = new PointClass();
                    pt.PutCoords(ptImageFeaturePoints[i][j].X, ptImageFeaturePoints[i][j].Y);
                    pPointCollection.AddPoint(pt);
                    pt.PutCoords(ptImageFeaturePoints[i][j + 1].X, ptImageFeaturePoints[i][j + 1].Y);
                    pPointCollection.AddPoint(pt);

                    if (!ClsGDBDataCommon.CopyFeatureFieldValue(pFeatureList[i], pFeatureBuffer as IFeature))
                    {
                        continue;
                    }
                    pFeatureBuffer.Shape = pPolyline as IGeometry;
                    object featureOID = pOutFCursor.InsertFeature(pFeatureBuffer);
                }
            }
            pOutFCursor.Flush();
            //featureCursor.Flush();
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            #endregion

            #region 点SHP文件的添加
            IDataset   pPointDataset   = (IDataset)pOutputPointFC;
            IWorkspace pPointWorkspace = pPointDataset.Workspace;

            //Cast for an IWorkspaceEdit
            IWorkspaceEdit pPointWorkspaceEdit = pPointWorkspace as IWorkspaceEdit;
            pPointWorkspaceEdit.StartEditing(true);
            pPointWorkspaceEdit.StartEditOperation();

            IFeatureCursor pOutPointFCursor = null;
            for (int i = 0; i < ptImageFeaturePointsForPointShp.Count; i++)
            {
                //int nSegmentCount = pSegmentCollection[i].SegmentCount;

                //IMultipoint pMultiPoint = new MultipointClass();
                for (int j = 0; j < ptImageFeaturePointsForPointShp[i].Count; j++)
                {
                    IFeatureBuffer pFeatureBuffer = pOutputPointFC.CreateFeatureBuffer();
                    pOutPointFCursor = pOutputPointFC.Insert(true);
                    IPoint pt   = new PointClass();
                    Pt2d   pt2d = ptImageFeaturePointsForPointShp[i][j];
                    pt.PutCoords(pt2d.X, pt2d.Y);

                    //CopyFeatureField(pFeatureList[i], pFeatureBuffer);
                    pFeatureBuffer.Shape = pt as IGeometry;
                    object featureOID = pOutPointFCursor.InsertFeature(pFeatureBuffer);
                }
            }
            pOutPointFCursor.Flush();

            //featureCursor.Flush();
            pPointWorkspaceEdit.StopEditOperation();
            pPointWorkspaceEdit.StopEditing(true);
            #endregion

            return(true);
        }