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); }
//public bool m_bModifiedFlag = false; //标识模型参数是否已经被修改,是否需要重新生成模型文件 public FrmManualSetModelPara(Pt2d nCurrentPos, string szModelType) { InitializeComponent(); //m_CurrentPos = nCurrentPos; m_pModel.x = nCurrentPos.X; m_pModel.y = nCurrentPos.Y; if (szModelType.ToLower().Contains("crater")) { m_pModel.szModelType = "Crater"; } else { m_pModel.szModelType = "Rock"; } m_pModel.dbSize = 5; m_pModel.dbDepth = 1; }
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); }
private void CreatePolyline() { try { //建立shape字段 IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields; IField pField = new FieldClass(); IFieldEdit pFieldEdit = (IFieldEdit)pField; pFieldEdit.Name_2 = "Shape"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; //设置Geometry definition IGeometryDef pGeometryDef = new GeometryDefClass(); IGeometryDefEdit pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef; pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline; //点、线、面 pGeometryDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass(); pGeometryDefEdit.SpatialReference.SetDomain(-8000000, 8000000, -800000, 8000000); pFieldEdit.GeometryDef_2 = pGeometryDef; pFieldsEdit.AddField(pField); IFeatureClass pFeatureClass = null; DirectoryInfo di = new DirectoryInfo(textBoxX1.Text); string filefolder = di.Parent.FullName; ClsGDBDataCommon comm = new ClsGDBDataCommon(); IWorkspace inmemWor = comm.OpenFromShapefile(filefolder); // ifeatureworkspacee IFeatureWorkspace pFeatureWorkspace = inmemWor as IFeatureWorkspace; try { pFeatureClass = pFeatureWorkspace.CreateFeatureClass(di.Name, pFields, null, null, esriFeatureType.esriFTSimple, "shape", ""); } catch (SystemException eee) { if (eee.Message == "The table already exists.") { pFeatureClass = pFeatureWorkspace.OpenFeatureClass(textBoxX1.Text); ITable ptable = pFeatureClass as ITable; ptable.DeleteSearchedRows(null); } //MessageBox.Show(eee.Message); } List <Pt2d> ImagePoint = new List <Pt2d>(); IQueryFilter pQF = new QueryFilterClass(); IFeatureCursor pFC = pPointFeatureclass.Search(null, false); IFeature pF = pFC.NextFeature(); while (pF != null) { IPoint pPoint = pF.Shape as IPoint; Pt2d imgpoint = new Pt2d(); imgpoint.X = pPoint.X; imgpoint.Y = pPoint.Y; ImagePoint.Add(imgpoint); pF = pFC.NextFeature(); } Pt2d[] originPt = new Pt2d[ImagePoint.Count]; for (int i = 0; i < ImagePoint.Count; i++) { Pt2d pttemp = new Pt2d(); pttemp.X = ImagePoint[i].X; pttemp.Y = ImagePoint[i].Y; originPt[i] = pttemp; } // Pt2d[] ptImagePos = new Pt2d[ImagePoint.Count]; Pt2d[] ptImagePos = null; calImagePos(pRaster, originPt, textBoxX2.Text, out ptImagePos); IPointCollection pPointC = new PolylineClass(); for (int i = 0; i < ptImagePos.Length; i++) { if (ptImagePos[i] == null) { continue; } IPoint pPoint = new PointClass(); pPoint.X = ptImagePos[i].X; pPoint.Y = ptImagePos[i].Y; pPointC.AddPoint(pPoint); } ISegmentCollection pSegC = new PolylineClass(); pSegC.AddSegment(pPointC as ISegment); IFeature pFeatureTemp = pFeatureClass.CreateFeature(); pFeatureTemp.Shape = pPointC as IGeometry; pFeatureTemp.Store(); } catch (Exception ee) { MessageBox.Show(ee.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
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); } }
public double[,] getSubDem(IRaster pSrcRaster, Pt3d ptCenter, double nGeoRange, ref Pt2i ptImageTopLeft) { //IRaster pDstRaster = null; if (pSrcRaster == null) { return(null); } IRasterProps pProps = pSrcRaster as IRasterProps; IEnvelope pEnvelop = pProps.Extent; Pt2d[] ptRange = new Pt2d[4]; for (int i = 0; i < 4; i++) { ptRange[i] = new Pt2d(); } ptRange[0].X = ptCenter.X - nGeoRange; //lefttop ptRange[0].X = Math.Max(ptRange[0].X, pEnvelop.UpperLeft.X); ptRange[0].Y = ptCenter.Y + nGeoRange; ptRange[0].Y = Math.Min(ptRange[0].Y, pEnvelop.UpperLeft.Y); ptRange[1].X = ptCenter.X + nGeoRange; //righttop ptRange[1].Y = ptCenter.Y + nGeoRange; ptRange[1].X = Math.Min(ptRange[1].X, pEnvelop.UpperRight.X); ptRange[1].Y = Math.Min(ptRange[1].Y, pEnvelop.UpperRight.Y); ptRange[2].X = ptCenter.X - nGeoRange; //leftbottom ptRange[2].Y = ptCenter.Y - nGeoRange; ptRange[2].X = Math.Max(ptRange[2].X, pEnvelop.LowerLeft.X); ptRange[2].Y = Math.Max(ptRange[2].Y, pEnvelop.LowerLeft.Y); ptRange[3].X = ptCenter.X + nGeoRange; //rightbottom ptRange[3].Y = ptCenter.Y - nGeoRange; ptRange[3].X = Math.Min(ptRange[3].X, pEnvelop.LowerRight.X); ptRange[3].Y = Math.Max(ptRange[3].Y, pEnvelop.LowerRight.Y); Pt2i[] ptImageRange = new Pt2i[4]; for (int i = 0; i < 4; i++) { ptImageRange[i] = new Pt2i(); } IRaster2 pRaster2 = pSrcRaster as IRaster2; ptImageRange[0].X = pRaster2.ToPixelColumn(ptRange[0].X); ptImageRange[0].Y = pRaster2.ToPixelRow(ptRange[0].Y); ptImageRange[1].X = pRaster2.ToPixelColumn(ptRange[1].X); ptImageRange[1].Y = pRaster2.ToPixelRow(ptRange[1].Y); ptImageRange[2].X = pRaster2.ToPixelColumn(ptRange[2].X); ptImageRange[2].Y = pRaster2.ToPixelRow(ptRange[2].Y); ptImageRange[3].X = pRaster2.ToPixelColumn(ptRange[3].X); ptImageRange[3].Y = pRaster2.ToPixelRow(ptRange[3].Y); ptImageTopLeft.X = Math.Min(Math.Min(Math.Min(ptImageRange[0].X, ptImageRange[1].X), ptImageRange[2].X), ptImageRange[3].X); ptImageTopLeft.Y = Math.Min(Math.Min(Math.Min(ptImageRange[0].Y, ptImageRange[1].Y), ptImageRange[2].Y), ptImageRange[3].Y); int[] nSize = new int[2]; nSize[0] = Math.Max(Math.Max(Math.Max(ptImageRange[0].X, ptImageRange[1].X), ptImageRange[2].X), ptImageRange[3].X) - ptImageTopLeft.X; nSize[1] = Math.Max(Math.Max(Math.Max(ptImageRange[0].Y, ptImageRange[1].Y), ptImageRange[2].Y), ptImageRange[3].Y) - ptImageTopLeft.Y; double[,] dbData = new double[nSize[0], nSize[1]]; Point2D ptLeftTop = new Point2D(); ptLeftTop.X = ptImageTopLeft.X; ptLeftTop.Y = ptImageTopLeft.Y; //double[,] dbData = new double[pProps.Width,pProps.Height]; //Point2D ptLeftTop = new Point2D(); //ptImageTopLeft.X = pRaster2.ToPixelColumn(pEnvelop.UpperLeft.X); //(int)pEnvelop.UpperLeft.X; //ptImageTopLeft.Y = pRaster2.ToPixelRow(pEnvelop.UpperLeft.Y); //(int)pEnvelop.UpperLeft.X;//(int)pEnvelop.UpperLeft.Y; //ptLeftTop.X = ptImageTopLeft.X;// pEnvelop.UpperLeft.X; //ptLeftTop.Y = ptImageTopLeft.Y;// pEnvelop.UpperLeft.Y; readBlockDataToFile(ptLeftTop, ref dbData, pSrcRaster); return(dbData); }