public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName); ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass(); m_hookHelper.FocusMap.SpatialReference = m_psurface.Domain.SpatialReference; pMapPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (pMapPoint == null) { return; } pMapPoint.Project(m_psurface.Domain.SpatialReference); pMapPoint.Z = m_psurface.GetElevation(pMapPoint); IGroupElement pGroup = null; ClsMarkDraw.AddSimpleGraphic(pMapPoint, ClsMarkDraw.getRGB(71, 61, 255), 3, sPolyOutlineName, m_hookHelper.FocusMap, pGroup); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); m_Geometry = pMapPoint; EndDtrawd(true); } catch { return; } }
/// <summary> /// 获取点击地图上的点 /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X"></param> /// <param name="Y"></param> public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();; ISceneGraph pSceneGraph = m_sceneHookHelper.SceneGraph; object pOwner; object pObject; object before = Type.Missing; object after = Type.Missing; object StepSize = Type.Missing; IDisplay3D pDisplay; pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pMapPoint, out pOwner, out pObject); //获取鼠标点击的位置并转化为地理坐标 if (pMapPoint == null) { return; } pMapPoint.Z = pMapPoint.Z / m_sceneHookHelper.Scene.ExaggerationFactor; pMapPoint.Z = m_psurface.GetElevation(pMapPoint); pMapPoint.SpatialReference = pSceneGraph.Scene.SpatialReference; pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D; pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置 IGeometry pGeom = null; Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName); //根据绘制对象类型的不同定义不同的类型 switch (m_DrawType.ToString()) { case "esriGeometryPoint": m_Geometry = pMapPoint; break; case "esriGeometryLine": if (m_pPointColl == null) { m_pPointColl = new PolylineClass(); pGeom = new PolylineClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; case "esriGeometryPolygon": if (m_pPointColl == null) { m_pPointColl = new PolygonClass(); pGeom = new PolygonClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; } //BeginDrawed(true); IGroupElement pGroup = null; if (m_pPointColl.PointCount == 1) { //当为一个点时绘制点 Cls3DMarkDraw.AddSimpleGraphic(pMapPoint, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup); } else if (m_DrawType.ToString() == "esriGeometryLine") { pGeom = m_pPointColl as IGeometry; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup); m_pPointColl = pGeom as IPointCollection; } else { ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator; pGeom = pTopo.Boundary; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup); } m_sceneHookHelper.SceneGraph.RefreshViewers(); } catch { return; } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolAddCraterOnTIN.OnMouseDown implementation if (pTinLayer != null) { ITin pTin = pTinLayer.Dataset; ISurface pSurface = ((ITinAdvanced)pTin).Surface; IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; //在mapctr操作 if (pMapCtr != null) { IPoint mapPoint = pMapCtr.ToMapPoint(X, Y); IZAware za = mapPoint as IZAware; za.ZAware = true; double zVal; zVal = pSurface.GetElevation(mapPoint); if (double.IsNaN(zVal)) { MessageBox.Show("获取模型的高度失败!"); return; } if (m_listModels.Count == 0) { MessageBox.Show("请先生成模型!"); return; } mapPoint.Z = zVal; try { //IMultiPatch pMP = new MultiPatchClass(); IFeatureClass pFC = pFeatureLayer.FeatureClass; IFeature pF = pFC.CreateFeature(); IImport3DFile pI3D = new Import3DFileClass(); pI3D.CreateFromFile(m_listModels[m_listModels.Count - 1]); IMultiPatch pMP = pI3D.Geometry as IMultiPatch; ITransform3D pT3D = pMP as ITransform3D; pT3D.Move3D(mapPoint.X, mapPoint.Y, mapPoint.Z); pF.Shape = pMP as IGeometry; pF.Store(); if (pMapCtr != null) { pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } catch (SystemException e) { MessageBox.Show(e.Message); } //IMultiPatch pMP = new MultiPatchClass(); //for (int i = 0; i < 5; i++) //{ // IFeature pF = pFC.CreateFeature(); // IImport3DFile pI3D = new Import3DFileClass(); // pI3D.CreateFromFile(@"C:\Users\Administrator\Desktop\sampleAnalysis\1002.3ds"); // IMultiPatch pMP = pI3D.Geometry as IMultiPatch; // // ITransform3D pT3D = pMP as ITransform3D; // pF.Shape = pMP as IGeometry; // ITransform3D pT3D = pF.Shape as ITransform3D; // pT3D.Move3D(5293 + 1600, -20427 , 800 + i*400); // // pF.Shape = pI3D.Geometry; } } if (pRasterLayer != null) { //ITin pTin = pTinLayer.Dataset; //ISurface pSurface = ((ITinAdvanced)pTin).Surface; IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; //在mapctr操作 if (pMapCtr != null) { IPoint mapPoint = pMapCtr.ToMapPoint(X, Y); //添加手工编辑窗口 FrmManualSetModelPara pManualSetPara = null; if (m_pModel == null) { Pt2d ptCurrent = new Pt2d(); ptCurrent.X = mapPoint.X; ptCurrent.Y = mapPoint.Y; pManualSetPara = new FrmManualSetModelPara(ptCurrent, "Crater"); } else { m_pModel.x = mapPoint.X; m_pModel.y = mapPoint.Y; pManualSetPara = new FrmManualSetModelPara(m_pModel); } //FrmManualSetModelPara pManualSetPara = new FrmManualSetModelPara(ptCurrent, "Crater"); if (pManualSetPara.ShowDialog() == DialogResult.OK) { if (m_pModel == null) { m_pModel = new Model(); } bool bFlag = m_pModel.compareModelPara(pManualSetPara.m_pModel); if (!bFlag) //模型参数已经被修改,需要重新生成新的模型文件 { m_pModel.copyFromModel(pManualSetPara.m_pModel); //根据设置的参数生成相应的模型 TriType triType = TriType.TriForward; LibModelGen.MappingType mappingType = LibModelGen.MappingType.Flat; String szModelOutputFilename = System.IO.Path.GetTempFileName(); szModelOutputFilename = szModelOutputFilename.Substring(0, szModelOutputFilename.LastIndexOf('.')) + ".3ds"; ModelBase crater = new CraterGen(m_pModel.dbSize, m_pModel.dbDepth); crater.OutputFilename = szModelOutputFilename; crater.triype = triType; crater.mappingType = mappingType; //将撞击坑模型添加到相应图层 if (crater.generate()) { m_listModels.Add(szModelOutputFilename); } } //保存当前添加的模型参数 Model pTmpModel = new Model(); pTmpModel.copyFromModel(pManualSetPara.m_pModel); m_manualAddModels.Add(pTmpModel); } else { return; } IZAware za = mapPoint as IZAware; za.ZAware = true; double zVal; IRaster2 pRaster2 = pRasterLayer.Raster as IRaster2; int col, row; pRaster2.MapToPixel(mapPoint.X, mapPoint.Y, out col, out row); zVal = Convert.ToDouble(pRaster2.GetPixelValue(0, col, row)); if (double.IsNaN(zVal)) { MessageBox.Show("获取模型的高度失败!"); return; } if (m_listModels.Count == 0) { MessageBox.Show("请先生成模型!"); return; } mapPoint.Z = zVal; IFeature pfeature = null; try { //IMultiPatch pMP = new MultiPatchClass(); IFeatureClass pFC = pFeatureLayer.FeatureClass; IFeature pF = pFC.CreateFeature(); IImport3DFile pI3D = new Import3DFileClass(); pI3D.CreateFromFile(m_listModels[m_listModels.Count - 1]); IMultiPatch pMP = pI3D.Geometry as IMultiPatch; ITransform3D pT3D = pMP as ITransform3D; // pT3D.Move3D(mapPoint.X, mapPoint.Y, mapPoint.Z); pT3D.Move3D(pManualSetPara.m_pModel.x, pManualSetPara.m_pModel.y, mapPoint.Z); //IRasterProps pRasterProps = pRasterLayer.Raster as IRasterProps; //double xmax = pRasterProps.Extent.XMax; //double xmin = pRasterProps.Extent.XMin; //double ymax = pRasterProps.Extent.YMax; //double ymin = pRasterProps.Extent.YMin; ////生成地形的地理范围 //double dbGeoRangeX = xmax - xmin; //double dbGeoRangeY = ymax - ymin; //double dbModelRangeX = pMP.Envelope.Width; //double dbModelRangeY = pMP.Envelope.Height; //double dbModelRangeZ = pMP.Envelope.ZMax - pMP.Envelope.ZMin; //根据地形大小改变撞击坑大小 //double dbRandomSize = Math.Min(dbGeoRangeX, dbGeoRangeY) * (0.15); //[0.03 0.06] //double dbRandomSize = pRasterProps.MeanCellSize().X * 300; //double dbScale = pManualSetPara.m_pModel.dbSize;// / Math.Max(dbModelRangeX, dbModelRangeY); //pT3D.Scale3D(mapPoint, dbScale, dbScale, dbScale); pF.Shape = pMP as IGeometry; pfeature = pF as IFeature; pF.Store(); if (pMapCtr != null) { pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } catch (SystemException e) { if (e.Message == "The spatial index grid size is invalid.") { IFeatureClassLoad pFCL = pFeatureLayer.FeatureClass as IFeatureClassLoad; pFCL.LoadOnlyMode = true; pfeature.Store(); pFCL.LoadOnlyMode = false; } else { MessageBox.Show(e.Message); } } } } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { ITin pTin = pTinLayer.Dataset; ITinEdit pTinEdit = pTin as ITinEdit; ISurface pSurface = ((ITinAdvanced)pTin).Surface; IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; //在mapctr操作 if (pMapCtr != null) { IPoint mapPoint = pMapCtr.ToMapPoint(X, Y); IZAware za = mapPoint as IZAware; za.ZAware = true; double zVal; if (frmAddTINNode.bFromSurface == true) { zVal = pSurface.GetElevation(mapPoint); if (double.IsNaN(zVal)) { zVal = 0; } frmAddTINNode.SetdoubleInputHeightValue(zVal); } else { zVal = frmAddTINNode.dHeight; if (double.IsNaN(zVal)) { zVal = 0; } } mapPoint.Z = zVal; pAddedPoint = mapPoint; } //在layout控件操作取不到z值 else { IPageLayoutControl pLayoutCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IPageLayoutControl; //if (pLayoutCtr.ActiveView.FocusMap.Equals(pMap)) IPoint mapPoint = pLayoutCtr.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IZAware za = mapPoint as IZAware; za.ZAware = true; double zVal; if (frmAddTINNode.bFromSurface == true) { zVal = pSurface.GetElevation(mapPoint); if (double.IsNaN(zVal)) { zVal = 0; } frmAddTINNode.SetdoubleInputHeightValue(zVal); } else { zVal = frmAddTINNode.dHeight; if (double.IsNaN(zVal)) { zVal = 0; } } mapPoint.Z = zVal; pAddedPoint = mapPoint; } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();; object before = Type.Missing; object after = Type.Missing; object StepSize = Type.Missing; m_hookHelper.FocusMap.SpatialReference = m_psurface.Domain.SpatialReference; pMapPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (pMapPoint == null) { return; } pMapPoint.Project(m_psurface.Domain.SpatialReference); pMapPoint.Z = m_psurface.GetElevation(pMapPoint); //pMapPoint.SpatialReference = m_hookHelper.FocusMap.SpatialReference; //pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D; //pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置 IGeometry pGeom = null; ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName); //根据绘制对象类型的不同定义不同的类型 switch (m_DrawType.ToString()) { case "esriGeometryPoint": m_Geometry = pMapPoint; break; case "esriGeometryLine": if (m_pPointColl == null) { m_pPointColl = new PolylineClass(); pGeom = new PolylineClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; case "esriGeometryPolygon": if (m_pPointColl == null) { m_pPointColl = new PolygonClass(); pGeom = new PolygonClass(); } m_pPointColl.AddPoint(pMapPoint, ref before, ref after); break; } //BeginDrawed(true); IGroupElement pGroup = null; if (m_pPointColl.PointCount == 1) { //当为一个点时绘制点 ClsMarkDraw.AddSimpleGraphic(pMapPoint, ClsMarkDraw.getRGB(71, 61, 255), 3, sPolyOutlineName, m_hookHelper.FocusMap, pGroup); } else if (m_DrawType.ToString() == "esriGeometryLine") { pGeom = m_pPointColl as IGeometry; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup); m_pPointColl = pGeom as IPointCollection; } else { ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator; pGeom = pTopo.Boundary; pGeom.SpatialReference = pMapPoint.SpatialReference; m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize); ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup); } m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch { return; } }
/// <summary> /// 通过鼠标点击获取观察点与被观察点同时进行两点间通视分析 /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X"></param> /// <param name="Y"></param> public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_frm3DLineOfSight.m_Layer == null || m_frm3DLineOfSight.m_Surface == null) { MessageBox.Show("请设置有效的表面数据", "提示!"); return; } if (m_frm3DLineOfSight.txtObsOffset.Text == "" || m_frm3DLineOfSight.txtTarOffset.Text == "") { MessageBox.Show("观察点高度和被观察点高度不能为空", "提示!"); return; } m_frm3DLineOfSight.TopMost = true; ISceneGraph pSceneGraph = m_sceneHookHelper.SceneGraph; m_pNewLineFeedback = new NewLineFeedbackClass(); IPolyline pPolyline = m_pNewLineFeedback.Stop(); //用于判断是否已经获取两点 ISceneControl pSceneControl = m_sceneHookHelper.Hook as ISceneControl; Cls3DModulsefun pCls3DModulsefun = new Cls3DModulsefun(); //用于绘制通视分析结果的方法 object pOwner; object pObject; ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass(); pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pPoint, out pOwner, out pObject);//获取鼠标点击的位置并转化为地理坐标 if (pPoint == null) { return; } ESRI.ArcGIS.Geometry.IPoint pFlashPoint = new ESRI.ArcGIS.Geometry.PointClass(); IClone pClone = pPoint as IClone; pFlashPoint = pClone.Clone() as ESRI.ArcGIS.Geometry.IPoint; pFlashPoint.Z = pFlashPoint.Z / pSceneGraph.VerticalExaggeration; pFlashPoint.SpatialReference = pSceneGraph.Scene.SpatialReference; IDisplay3D pDisplay = pSceneGraph as IDisplay3D; pDisplay.FlashLocation(pFlashPoint);//闪烁显示被点击的位置 IGeometry pGeometry = null; if (m_pScenePoints == null) { m_pScenePoints = new PolylineClass(); pGeometry = m_pScenePoints as IGeometry; pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference; } object before = Type.Missing; object after = Type.Missing; m_pScenePoints.AddPoint(pPoint, ref before, ref after);//添加获取的点到点集合中 if (m_pScenePoints.PointCount == 2) { pClone = m_pScenePoints as IClone; pPolyline = pClone.Clone() as ESRI.ArcGIS.Geometry.IPolyline;//当点集合中点数达到两个时生成一条线用于判断观察点与被观察点是否确定 m_pScenePoints = null; } if (pPolyline != null) { m_pScenePoints = null; ISurface pSurface = m_SurFace; ESRI.ArcGIS.Geometry.IPoint fPoint = pPolyline.FromPoint; //获取观察点 fPoint.Z = pSurface.GetElevation(fPoint); //获取观察点的高程 ESRI.ArcGIS.Geometry.IPoint tPoint = pPolyline.ToPoint; tPoint.Z = pSurface.GetElevation(tPoint); if (pSurface.IsVoidZ(fPoint.Z) || pSurface.IsVoidZ(tPoint.Z)) { return; } fPoint.Z = fPoint.Z + Convert.ToDouble(m_frm3DLineOfSight.txtObsOffset.Text);//观察者的高度加上观察者所在的高程才是观察点实际的高程 tPoint.Z = tPoint.Z + Convert.ToDouble(m_frm3DLineOfSight.txtTarOffset.Text); ESRI.ArcGIS.Geometry.IPoint pObstruct; IPolyline pVisPolyline; IPolyline pInVisPolyline; bool bIsVis; object pRefractionFactor = Type.Missing; //进行两点间的通视分析 pSurface.GetLineOfSight(fPoint, tPoint, out pObstruct, out pVisPolyline, out pInVisPolyline, out bIsVis, m_frm3DLineOfSight.checkBoxCurv.Checked, m_frm3DLineOfSight.checkBoxCurv.Checked, ref pRefractionFactor); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; //绘制可视与不可视的沿地表线要素 if (pVisPolyline != null) { pSimpleLineSymbol.Color = Cls3DMarkDraw.getRGB(0, 255, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pVisPolyline as IGeometry, pSimpleLineSymbol as ISymbol); } if (pInVisPolyline != null) { pSimpleLineSymbol.Color = Cls3DMarkDraw.getRGB(255, 0, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pInVisPolyline as IGeometry, pSimpleLineSymbol as ISymbol); } IGeometryCollection pVisPatch = new MultiPatchClass();//用于存储可视域的要素 pGeometry = pVisPatch as IGeometry; pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference; double dTargetHeightForVis = 0; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); IGeometryCollection pInVisPatch = new MultiPatchClass();//存储不可视域的要素 pGeometry = pInVisPatch as IGeometry; pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference; IGeometryCollection pPathGeo = pInVisPolyline as IGeometryCollection; if (pPathGeo != null) { //下面的作用是将不可视域线每段path生成线要素进行绘制 张琪 20110623 for (int i = 0; i < pPathGeo.GeometryCount; i++) { IGeometryCollection pInPolyline = new PolylineClass(); IPath path = pPathGeo.get_Geometry(i) as IPath; pInPolyline.AddGeometry(path as IGeometry, ref before, ref after); pCls3DModulsefun.CreateVerticalLOSPatches(bIsVis, fPoint, tPoint, pVisPolyline, pInPolyline as IPolyline, pVisPatch, pInVisPatch, dTargetHeightForVis); } } else//当不可视域为空时,直接分析生成可视域与不可视域 { pCls3DModulsefun.CreateVerticalLOSPatches(bIsVis, fPoint, tPoint, pVisPolyline, pInVisPolyline, pVisPatch, pInVisPatch, dTargetHeightForVis); } // // 对可视域与不可视域要素在场景中绘制出来 if (pInVisPatch != null) { pSimpleFillSymbol.Color = Cls3DMarkDraw.getRGB(255, 0, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pInVisPatch as IGeometry, pSimpleFillSymbol as ISymbol); } if (pVisPatch != null) { pSimpleFillSymbol.Color = Cls3DMarkDraw.getRGB(0, 255, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pVisPatch as IGeometry, pSimpleFillSymbol as ISymbol); } } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolAddStone.OnMouseDown implementation if (pTinLayer != null) { ITin pTin = pTinLayer.Dataset; ISurface pSurface = ((ITinAdvanced)pTin).Surface; IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; //在mapctr操作 if (pMapCtr != null) { IPoint mapPoint = pMapCtr.ToMapPoint(X, Y); IZAware za = mapPoint as IZAware; za.ZAware = true; double zVal; zVal = pSurface.GetElevation(mapPoint); if (double.IsNaN(zVal)) { MessageBox.Show("获取模型的高度失败!"); return; } if (m_listModels.Count == 0) { MessageBox.Show("请先生成模型!"); return; } mapPoint.Z = zVal; IFeature pfeature = null; try { //IMultiPatch pMP = new MultiPatchClass(); IFeatureClass pFC = pFeatureLayer.FeatureClass; IFeature pF = pFC.CreateFeature(); IImport3DFile pI3D = new Import3DFileClass(); pI3D.CreateFromFile(m_listModels[m_listModels.Count - 1]); IMultiPatch pMP = pI3D.Geometry as IMultiPatch; ITransform3D pT3D = pMP as ITransform3D; pT3D.Move3D(mapPoint.X, mapPoint.Y, mapPoint.Z); pF.Shape = pMP as IGeometry; pfeature = pF as IFeature; pF.Store(); if (pMapCtr != null) { pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } catch (SystemException e) { if (e.Message == "The spatial index grid size is invalid.") { IFeatureClassLoad pFCL = pFeatureLayer.FeatureClass as IFeatureClassLoad; pFCL.LoadOnlyMode = true; pfeature.Store(); pFCL.LoadOnlyMode = false; } else { MessageBox.Show(e.Message); } } //IMultiPatch pMP = new MultiPatchClass(); //for (int i = 0; i < 5; i++) //{ // IFeature pF = pFC.CreateFeature(); // IImport3DFile pI3D = new Import3DFileClass(); // pI3D.CreateFromFile(@"C:\Users\Administrator\Desktop\sampleAnalysis\1002.3ds"); // IMultiPatch pMP = pI3D.Geometry as IMultiPatch; // // ITransform3D pT3D = pMP as ITransform3D; // pF.Shape = pMP as IGeometry; // ITransform3D pT3D = pF.Shape as ITransform3D; // pT3D.Move3D(5293 + 1600, -20427 , 800 + i*400); // // pF.Shape = pI3D.Geometry; } } if (pRasterLayer != null) { //ITin pTin = pTinLayer.Dataset; //ISurface pSurface = ((ITinAdvanced)pTin).Surface; IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; //在mapctr操作 if (pMapCtr != null) { IPoint mapPoint = pMapCtr.ToMapPoint(X, Y); //添加手工编辑窗口 FrmManualSetModelPara pManualSetPara = null; if (m_pModel == null) { Pt2d ptCurrent = new Pt2d(); ptCurrent.X = mapPoint.X; ptCurrent.Y = mapPoint.Y; pManualSetPara = new FrmManualSetModelPara(ptCurrent, "Rock"); } else { m_pModel.x = mapPoint.X; m_pModel.y = mapPoint.Y; pManualSetPara = new FrmManualSetModelPara(m_pModel); } if (pManualSetPara.ShowDialog() == DialogResult.OK) { if (m_pModel == null) { m_pModel = new Model(); } //bool bFlag = m_pModel.compareModelPara(pManualSetPara.m_pModel); //if (!bFlag)//模型参数已经被修改,需要重新生成新的模型文件 //{ // m_pModel.copyFromModel(pManualSetPara.m_pModel); // //获得当前文件路径下的石头模型文件,并随机获得石块模型 // String szAppPathName = GetParentPathofExe() + @"Resource\RockModel"; // String[] szFileList = Directory.GetFiles(szAppPathName); // if (szFileList.Length > 0) // { // Random r = new Random(TerrainGen.Chaos_GetRandomSeed()); // int nRandomPos = r.Next(szFileList.Length); // String szModelOutputFilename = szFileList[nRandomPos]; // m_listModels.Add(szModelOutputFilename); // } //} m_pModel.copyFromModel(pManualSetPara.m_pModel); //获得当前文件路径下的石头模型文件,并随机获得石块模型 String szAppPathName = ClsGlobal.GetParentPathofExe() + @"Resource\RockModel"; String[] szFileList = Directory.GetFiles(szAppPathName); if (szFileList.Length > 0) { Random r = new Random(TerrainGen.Chaos_GetRandomSeed()); int nRandomPos = r.Next(szFileList.Length); String szModelOutputFilename = szFileList[nRandomPos]; m_listModels.Add(szModelOutputFilename); } //保存当前添加的模型参数 Model pTmpModel = new Model(); pTmpModel.copyFromModel(pManualSetPara.m_pModel); m_manualAddModels.Add(pTmpModel); } else { return; } IZAware za = mapPoint as IZAware; za.ZAware = true; double zVal; IRaster2 pRaster2 = pRasterLayer.Raster as IRaster2; int col, row; pRaster2.MapToPixel(mapPoint.X, mapPoint.Y, out col, out row); zVal = Convert.ToDouble(pRaster2.GetPixelValue(0, col, row)); if (double.IsNaN(zVal)) { MessageBox.Show("获取模型的高度失败!"); return; } if (m_listModels.Count == 0) { MessageBox.Show("请先生成模型!"); return; } mapPoint.Z = zVal; try { //IMultiPatch pMP = new MultiPatchClass(); IFeatureClass pFC = pFeatureLayer.FeatureClass; IFeature pF = pFC.CreateFeature(); IImport3DFile pI3D = new Import3DFileClass(); pI3D.CreateFromFile(m_listModels[m_listModels.Count - 1]); IMultiPatch pMP = pI3D.Geometry as IMultiPatch; ITransform3D pT3D = pMP as ITransform3D; pT3D.Move3D(mapPoint.X, mapPoint.Y, mapPoint.Z); IRasterProps pRasterProps = pRasterLayer.Raster as IRasterProps; double xmax = pRasterProps.Extent.XMax; double xmin = pRasterProps.Extent.XMin; double ymax = pRasterProps.Extent.YMax; double ymin = pRasterProps.Extent.YMin; //生成地形的地理范围 double dbGeoRangeX = xmax - xmin; double dbGeoRangeY = ymax - ymin; double dbModelRangeX = pMP.Envelope.Width; double dbModelRangeY = pMP.Envelope.Height; double dbModelRangeZ = pMP.Envelope.ZMax - pMP.Envelope.ZMin; //根据地形大小改变石块大小 //double dbRandomSize = Math.Min(dbGeoRangeX, dbGeoRangeY) * (0.03 ); //[0.03 0.06] //double dbScale = dbRandomSize / Math.Max(dbModelRangeX, dbModelRangeY); double dbScale = m_pModel.dbSize / Math.Max(dbModelRangeX, Math.Max(dbModelRangeY, dbModelRangeZ)); pT3D.Scale3D(mapPoint, dbScale, dbScale, dbScale); pF.Shape = pMP as IGeometry; pF.Store(); if (pMapCtr != null) { pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } catch (SystemException e) { MessageBox.Show(e.Message); } } } }