public bool DrawPolygon(IRaster pRaster, ExOriPara pExOriPara, InOriPara pInOriPara, IFeatureClass pFeatureClass, int nID) { try { Point2D[,] ptResult = null; ClsGetCameraView CGetCameraView = new ClsGetCameraView(); if (CGetCameraView.ImageReprojectionRange(pRaster, out ptResult, pExOriPara, pInOriPara, 50)) { IPointCollection pPointCollection = new PolygonClass(); for (int j = 0; j < ptResult.GetLength(1); j++) { if (ptResult[0, j] == null) { continue; } IPoint pPoint1 = new PointClass(); pPoint1.X = ptResult[0, j].X; pPoint1.Y = ptResult[0, j].Y; pPointCollection.AddPoint(pPoint1); } for (int k = ptResult.GetLength(1) - 1; k >= 0; k--) { if (ptResult[1, k] == null) { continue; } IPoint pPoint2 = new PointClass(); pPoint2.X = ptResult[1, k].X; pPoint2.Y = ptResult[1, k].Y; pPointCollection.AddPoint(pPoint2); } IFeature pFeatureTemp = pFeatureClass.CreateFeature(); IPolygon pPolygon = new PolygonClass(); pPolygon = pPointCollection as IPolygon; pPolygon.Close(); pFeatureTemp.Shape = pPolygon as IGeometry; pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("PointID"), nID); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("X"), pExOriPara.pos.X); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("Y"), pExOriPara.pos.Y); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("Z"), pExOriPara.pos.Z); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("omg"), pExOriPara.ori.omg); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("phi"), pExOriPara.ori.phi); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("kap"), pExOriPara.ori.kap); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("width"), pInOriPara.nW); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("height"), pInOriPara.nH); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("fx"), pInOriPara.dfx); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("fy"), pInOriPara.dfy); pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("f"), pInOriPara.df); pFeatureTemp.Store(); } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
private Pt2d getProjectBackwardPoint(IPoint pGeoCoords, IRaster pDemRaster, ClsGetCameraView pGetCameraView, Matrix pRotateMatrix, ClsCameraPara cameraPara) { Pt3d ptFeaturePoint = new Pt3d(); ptFeaturePoint.X = pGeoCoords.X; ptFeaturePoint.Y = pGeoCoords.Y; //从DEM上得到相应高程 IRasterProps pDemRasterProps = pDemRaster as IRasterProps; double nGeoRange = pDemRasterProps.MeanCellSize().X * 10; Pt2i ptLeftTop = new Pt2i(); double[,] dbSubData = pGetCameraView.getSubDem(pDemRaster, ptFeaturePoint, nGeoRange, ref ptLeftTop); if (dbSubData == null) { return(null); } if (pGetCameraView.GetGeoZ(pDemRaster, dbSubData, ptLeftTop, ptFeaturePoint.X, ptFeaturePoint.Y, ref ptFeaturePoint.Z)) { Pt2d pt2d = new Pt2d(); double dbX, dbY, dbZ; Pt3d ptCurrentFeaturePoint = ptFeaturePoint; //判断是否在视场前方 if (!IsInCameraFrontArea(ptCurrentFeaturePoint, pRotateMatrix, cameraPara)) { return(null); } dbX = pRotateMatrix.getNum(0, 0) * (ptCurrentFeaturePoint.X - cameraPara.dX) + pRotateMatrix.getNum(1, 0) * (ptCurrentFeaturePoint.Y - cameraPara.dY) + pRotateMatrix.getNum(2, 0) * (ptCurrentFeaturePoint.Z - cameraPara.dZ); dbY = pRotateMatrix.getNum(0, 1) * (ptCurrentFeaturePoint.X - cameraPara.dX) + pRotateMatrix.getNum(1, 1) * (ptCurrentFeaturePoint.Y - cameraPara.dY) + pRotateMatrix.getNum(2, 1) * (ptCurrentFeaturePoint.Z - cameraPara.dZ); dbZ = pRotateMatrix.getNum(0, 2) * (ptCurrentFeaturePoint.X - cameraPara.dX) + pRotateMatrix.getNum(1, 2) * (ptCurrentFeaturePoint.Y - cameraPara.dY) + pRotateMatrix.getNum(2, 2) * (ptCurrentFeaturePoint.Z - cameraPara.dZ); Pt2d ptImageTmp = new Pt2d(); ptImageTmp.X = (int)Math.Round(-cameraPara.dFocus * dbX / dbZ); ptImageTmp.Y = (int)Math.Round(-cameraPara.dFocus * dbY / dbZ); //ptImageTmp.Y *= -1; //像主点坐标系===>笛卡尔坐标系(以东为X,以北为Y) ptImageTmp.X += cameraPara.dPx; ptImageTmp.Y += (-1 * cameraPara.dPy); //ptImageTmp.Y *= -1; //arcgis显示时把左上角放于原点 //ptImageTmp.Y -= cameraPara.nH; return(ptImageTmp); } return(null); }
//获取图层属性 private void ReadLayerProperties(ILayer layer, AdvTree tree) { tree.BeginUpdate(); tree.Nodes.Clear(); if (layer is IFeatureLayer) { ILayerGeneralProperties layerProperties = layer as ILayerGeneralProperties; AddChildNode(tree.Nodes, "LastMaximumScale", layerProperties.LastMaximumScale.ToString()); AddChildNode(tree.Nodes, "LastMinimumScale", layerProperties.LastMinimumScale.ToString()); AddChildNode(tree.Nodes, "LayerDescription ", layerProperties.LayerDescription); } else if (layer is IRasterLayer) { IRasterLayer rasterLayer = layer as IRasterLayer; if (rasterLayer.Raster != null) { IRaster raster = rasterLayer.Raster; IRaster2 raster2 = raster as IRaster2; IRasterBandCollection coll = raster2 as IRasterBandCollection; IRasterProps rasterProps = raster2 as IRasterProps; //基本信息 Node node = AddChildNode(tree.Nodes, "基本信息", null); AddChildNode(node.Nodes, "行数,列数", rasterProps.Height.ToString() + "," + rasterProps.Width.ToString()); AddChildNode(node.Nodes, "波段数", coll.Count.ToString()); AddChildNode(node.Nodes, "像元大小(x,y)", rasterProps.MeanCellSize().X.ToString() + "," + rasterProps.MeanCellSize().Y.ToString()); AddChildNode(node.Nodes, "波段数", coll.Count.ToString()); AddChildNode(node.Nodes, "像素类型", rasterProps.PixelType.ToString()); AddChildNode(node.Nodes, "无效值", ClsGetCameraView.getNoDataValue(rasterProps.NoDataValue).ToString()); node = AddChildNode(tree.Nodes, "坐标范围", null); AddChildNode(node.Nodes, "上", rasterProps.Extent.YMax.ToString()); AddChildNode(node.Nodes, "左", rasterProps.Extent.XMin.ToString()); AddChildNode(node.Nodes, "右", rasterProps.Extent.XMax.ToString()); AddChildNode(node.Nodes, "下", rasterProps.Extent.YMin.ToString()); node = AddChildNode(tree.Nodes, "统计信息", null); ClsGDBDataCommon cls = new ClsGDBDataCommon(); for (int i = 0; i < coll.Count; i++) { double[] dValue = cls.GetRasterStatistics(m_pLayer, i); Node nodeBand = AddChildNode(node.Nodes, "Band_" + (i + 1).ToString(), null); AddChildNode(nodeBand.Nodes, "最大值", dValue[0].ToString()); AddChildNode(nodeBand.Nodes, "最小值", dValue[1].ToString()); AddChildNode(nodeBand.Nodes, "平均值", dValue[2].ToString()); AddChildNode(nodeBand.Nodes, "标准差", dValue[3].ToString()); } } } tree.EndUpdate(true); tree.ExpandAll(); }
private void drawRaster(IRaster pRaster, ExOriPara pExOriPara, InOriPara pInOriPara) { IRaster pRasterResult; IRasterLayer pRasterLayer = new RasterLayerClass(); ClsGetCameraView CGetCameraView = new ClsGetCameraView(); if (CGetCameraView.ImageReprojectionRange(pRaster, out pRasterResult, pExOriPara, pInOriPara.df, pInOriPara.dx, pInOriPara.dy, pInOriPara.nW, pInOriPara.nH, 50)) { pRasterLayer.CreateFromRaster(pRasterResult); pMapControl.AddLayer(pRasterLayer as ILayer); pMapControl.Refresh(); } }
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); }
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); }
public void calImagePos(IRaster pRaster, Pt2d[] ptGeoPos, string szXmlFile, out Pt2d[] ptImagePos) { ptImagePos = null; if (pRaster == null) { return; } try { ClsCameraPara cameraPara = ParseXmlFileToGetPara(szXmlFile); if (cameraPara == null) { return; } ClsGetCameraView getCameraView = new ClsGetCameraView(); Pt2i ptLeftTop = new Pt2i(); IRasterProps pProps = pRaster as IRasterProps; int nWidth = pProps.Width; int nHeight = pProps.Height; double[,] dbData = new double[nWidth, nHeight]; Point2D ptTmpLeftTop = new Point2D(); ptTmpLeftTop.X = 0; ptTmpLeftTop.Y = 0; if (!getCameraView.readBlockDataToFile(ptTmpLeftTop, ref dbData, pRaster)) { return; } //double[,] dbData = getCameraView.getSubDem(pRaster, new Pt3d(), 0, ref ptLeftTop); int nCount = ptGeoPos.Length; ptImagePos = new Pt2d[nCount]; for (int i = 0; i < nCount; i++) { Pt2d pt2d = new Pt2d(); OriAngle oriAngle = new OriAngle(); oriAngle.kap = cameraPara.dKappa; oriAngle.omg = cameraPara.dOmg; oriAngle.phi = cameraPara.dPhi; Matrix pRMat = new Matrix(3, 3); ClsGetCameraView.OPK2RMat(oriAngle, ref pRMat); double dbTmpZ = double.NaN; getCameraView.GetGeoZ(pRaster, dbData, ptLeftTop, ptGeoPos[i].X, ptGeoPos[i].Y, ref dbTmpZ); if (dbTmpZ == double.NaN) { ptImagePos[i] = null; continue; } double dbX, dbY, dbZ; dbX = pRMat.getNum(0, 0) * (ptGeoPos[i].X - cameraPara.dX) + pRMat.getNum(1, 0) * (ptGeoPos[i].Y - cameraPara.dY) + pRMat.getNum(2, 0) * (dbTmpZ - cameraPara.dZ); dbY = pRMat.getNum(0, 1) * (ptGeoPos[i].X - cameraPara.dX) + pRMat.getNum(1, 1) * (ptGeoPos[i].Y - cameraPara.dY) + pRMat.getNum(2, 1) * (dbTmpZ - cameraPara.dZ); dbZ = pRMat.getNum(0, 2) * (ptGeoPos[i].X - cameraPara.dX) + pRMat.getNum(1, 2) * (ptGeoPos[i].Y - cameraPara.dY) + pRMat.getNum(2, 2) * (dbTmpZ - cameraPara.dZ); Pt2d ptImageTmp = new Pt2d(); ptImageTmp.X = (int)Math.Round(-cameraPara.dFocus * dbX / dbZ); ptImageTmp.Y = (int)Math.Round(-cameraPara.dFocus * dbY / dbZ); ptImagePos[i] = ptImageTmp; } return; } catch (System.Exception ee) { MessageBox.Show(ee.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }