/// <summary> /// 鼠标左键按下时发生的事件(建立缓冲区的主要方法) /// </summary> /// <param name="Flags"></param> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="pbHandled"></param> void TE_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { if (En == "DrawGeo") { } else if (En == "SelectModle") { // 2012-9-20 张航宇 // 若成功的完成了一次缓冲分析,则将状态释放,要求重新点击 IWorldPointInfo61 pIWorldPointInfo = this.SgWorld.Window.PixelToWorld(X, Y, WorldPointType.WPT_MODEL); if (pIWorldPointInfo.ObjectID != "" && pIWorldPointInfo.ObjectID != null) { try { ITerraExplorerObject61 pp = this.SgWorld.Creator.GetObject(pIWorldPointInfo.ObjectID); if (pp.ObjectType == ObjectTypeCode.OT_FEATURE) { IFeature61 pIF = pp as IFeature61; this.geo = pIF.GeometryZ.SpatialOperator.buffer((double)this.spinEdit1.Value); ITerrainPolygon61 polygon = this.SgWorld.Creator.CreatePolygon(this.geo, -16711936, -10197916, cbRelative.Checked?AltitudeTypeCode.ATC_TERRAIN_RELATIVE: AltitudeTypeCode.ATC_ON_TERRAIN, GroupID, "Buffer" + System.Guid.NewGuid().ToString().Substring(0, 6)); if (cbRelative.Checked) { polygon.Position.Altitude = (double)speHeight.Value; } this.En = null; this.Select.Checked = false; } else { ITerrainModel61 pITerrainModel = this.SgWorld.Creator.GetObject(pIWorldPointInfo.ObjectID) as ITerrainModel61; IBBox3D61 pBBox = pITerrainModel.Terrain.BBox; cVerticesArray = new double[] { pBBox.MaxX, pBBox.MinY, 0, pBBox.MaxX, pBBox.MaxY, 0, pBBox.MinX, pBBox.MaxY, 0, pBBox.MinX, pBBox.MinY, 0, }; ILinearRing cRing = this.SgWorld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray); IPolygon cPolygonGeometry = this.SgWorld.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null); //this.geo = cPolygonGeometry as IGeometry; ISpatialOperator _SpatialOperator = cPolygonGeometry.SpatialOperator; this.geo = _SpatialOperator.buffer((double)this.spinEdit1.Value); ITerrainPolygon61 polygon = this.SgWorld.Creator.CreatePolygon(this.geo, -16711936, -10197916, cbRelative.Checked ? AltitudeTypeCode.ATC_TERRAIN_RELATIVE : AltitudeTypeCode.ATC_ON_TERRAIN, GroupID, "Buffer" + System.Guid.NewGuid().ToString().Substring(0, 6)); if (cbRelative.Checked) { polygon.Position.Altitude = (double)speHeight.Value; } this.En = null; this.Select.Checked = false; } } catch { } } } }
/// <summary> /// 创建等高线*.shp文件的主方法 /// </summary> /// <param name="lux">左上投影x坐标</param> /// <param name="luy">左上投影y坐标</param> /// <param name="luz">左上投影z坐标</param> /// <param name="rlx">右下投影x坐标</param> /// <param name="rly">右下投影y坐标</param> /// <param name="rlz">右下投影z坐标</param> /// <param name="m_interval">采样间隔</param> /// <returns>等高线*.shp文件的文件名</returns> public string CreateContourShape(ISGWorld61 sgworld, double lux, double luy, double luz, double rlx, double rly, double rlz, double m_interval) { double width = sgworld.CoordServices.GetDistance(lux, luy, rlx, luy); double hight = sgworld.CoordServices.GetDistance(lux, luy, lux, rly); if (width < 5 || hight < 10) { MessageBox.Show("范围过小!", "SUNZ", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } if ((width / 1000) * (hight / 1000) > 40) { if (MessageBox.Show("范围超出40平分公里,系统计算时间比较长,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { } else { return(null); } } this.Interval = m_interval; this.Random = System.Guid.NewGuid().ToString().Substring(0, 6).ToLower(); CopyFolder(Application.StartupPath + "\\Convert\\TemPoints", Application.StartupPath + "\\Convert\\PointsResult\\" + this.Random); IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\Convert\\PointsResult\\" + this.Random, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(Application.StartupPath + "\\Convert\\PointsResult\\" + Random + "\\TemPointLayer.shp")); IFeatureClassWrite fr = (IFeatureClassWrite)pFeatureClass; IWorkspaceEdit w = (pFeatureClass as IDataset).Workspace as IWorkspaceEdit; IFeature f; w.StartEditing(true); w.StartEditOperation(); int EastPointCount = (int)(width / 5); int NothPointCount = (int)(hight / 5); for (int j = 0; j < NothPointCount; j++) { ESRI.ArcGIS.Geometry.IPoint p; p = new ESRI.ArcGIS.Geometry.PointClass(); ESRI.ArcGIS.Geometry.IZAware iz = p as ESRI.ArcGIS.Geometry.IZAware; iz.ZAware = true; p.X = lux; p.Y = luy; p.Z = luz; ESRI.ArcGIS.Geometry.IGeometry peo; peo = p; f = pFeatureClass.CreateFeature(); f.Shape = peo; f.set_Value(3, p.Z); f.Store(); fr.WriteFeature(f); for (int i = 0; i < EastPointCount; i++) { IPosition61 positionLU = null; ICoord2D pPoint = null; if ((j + 2) % 2 == 0) { pPoint = sgworld.CoordServices.MoveCoord(lux, luy, 5, 0); } else { pPoint = sgworld.CoordServices.MoveCoord(lux, luy, -5, 0); } IWorldPointInfo61 pW = sgworld.Terrain.GetGroundHeightInfo(pPoint.X, pPoint.Y, AccuracyLevel.ACCURACY_BEST_FROM_MEMORY, true); positionLU = pW.Position; luz = positionLU.Altitude; lux = positionLU.X; luy = positionLU.Y; p = new ESRI.ArcGIS.Geometry.PointClass(); iz = p as ESRI.ArcGIS.Geometry.IZAware; iz.ZAware = true; p.X = lux; p.Y = luy; p.Z = luz; peo = p; f = pFeatureClass.CreateFeature(); f.Shape = peo; f.set_Value(3, p.Z); f.Store(); fr.WriteFeature(f); } ICoord2D pPointL = sgworld.CoordServices.MoveCoord(lux, luy, 0, -5); IWorldPointInfo61 pWL = sgworld.Terrain.GetGroundHeightInfo(pPointL.X, pPointL.Y, AccuracyLevel.ACCURACY_FORCE_BEST_RENDERED, true); luz = pWL.Position.Altitude; lux = pWL.Position.X; luy = pWL.Position.Y; } w.StopEditOperation(); w.StopEditing(true); CreateTinFromFeature(pFeatureClass); return(this.Random); }
bool sgworld_OnLButtonDown(int Flags, int X, int Y) { if (pbhander == "modify") { LClickCount++; IWorldPointInfo61 pIWPInfo = this.SgWorld.Window.PixelToWorld(X, Y, WorldPointType.WPT_TERRAIN); IPosition61 pIPosition = this.SgWorld.Navigate.GetPosition(AltitudeTypeCode.ATC_TERRAIN_RELATIVE); if (pITerrainPolygon == null) { try { ILinearRing cRing = null; double[] cVerticesArray = null; cVerticesArray = new double[] { pIPosition.X, pIPosition.Y, 0, pIWPInfo.Position.X, pIWPInfo.Position.Y, 0, pIWPInfo.Position.X, pIWPInfo.Position.Y, 0, }; cRing = this.SgWorld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray); uint nLineColor = 0xFF00FF00; uint nFillColor = 0x7FFF0000; AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; pITerrainPolygon = this.SgWorld.Creator.CreatePolygon(cRing, nLineColor, nFillColor, eAltitudeTypeCode, 0, "Polygon"); IPolygon polygonGeometry = pITerrainPolygon.Geometry as IPolygon; polygonGeometry.StartEdit(); foreach (ILinearRing ring in polygonGeometry.Rings) { double dx = pIWPInfo.Position.X; double dy = pIWPInfo.Position.Y; double dh = pIWPInfo.Position.Distance; ring.Points.AddPoint(dx, dy, dh); ring.Points.DeletePoint(0); } IGeometry editedGeometry = polygonGeometry.EndEdit(); pITerrainPolygon.Geometry = editedGeometry; } catch (Exception) { } } else { try { IPolygon polygonGeometry = pITerrainPolygon.Geometry as IPolygon; polygonGeometry.StartEdit(); foreach (ILinearRing ring in polygonGeometry.Rings) { double dx = pIWPInfo.Position.X; double dy = pIWPInfo.Position.Y; double dh = pIWPInfo.Position.Distance; ring.Points.AddPoint(dx, dy, dh); } IGeometry editedGeometry = polygonGeometry.EndEdit(); pITerrainPolygon.Geometry = editedGeometry; } catch (Exception) { } } } return(false); }