// 高度线性内插 private double GetInterectPointHeight(ICoord2D startPt, double startPtH, ICoord2D endPt, double endPtH, ICoord2D interPt) { if (startPt == null || endPt == null || interPt == null) { return(0.0); } if (Math.Abs(startPtH - endPtH) < 0.00000001) { return(startPtH); } double l1 = (startPt.X - endPt.X) * (startPt.X - endPt.X) + (startPt.Y - endPt.Y) * (startPt.Y - endPt.Y); double l2 = (startPt.X - interPt.X) * (startPt.X - interPt.X) + (startPt.Y - interPt.Y) * (startPt.Y - interPt.Y); double ratio = Math.Sqrt(l2 / l1); return(startPtH + (endPtH - startPtH) * ratio); }
/// <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); }
private void HorizontalSectionAnalysis() { ILineString line = this._drawTool.GetGeo2D() as ILineString; if (line.Length > _maxLength) { XtraMessageBox.Show(string.Format("断面长度不超过{0}米!", _maxLength), "提示"); return; } ICoord2D startCoord = null; if (line.Points.Count == 2) { IPoint startPt = line.StartPoint; startCoord = RenderControlServices.Instance().CovertCoord(startPt.X, startPt.Y); } else { return; } WaitForm.Start("正在进行横断面分析...", "请稍后", false); List <InterPointInfo> listInter = new List <InterPointInfo>(); foreach (Layer l in WorkSpaceServices.Instance().PipeLineLayers) { if (!l.Show && l.ShpLayer == null) { continue; } l.ShowShp = true; Field fDiameter = WorkSpaceServices.Instance().GetFieldBySysField(l, SystemField.PIPELINE_DIAMETER[1]); Field fClassify = WorkSpaceServices.Instance().GetFieldBySysField(l, SystemField.CLASSIFY[1]); Field fMaterial = WorkSpaceServices.Instance().GetFieldBySysField(l, SystemField.MATERIAL[1]); Field fHlb = WorkSpaceServices.Instance().GetFieldBySysField(l, SystemField.HLB[1]); if (fDiameter == null || fMaterial == null || fHlb == null) { continue; } IFeatures65 fs = l.ShpLayer.ExecuteSpatialQuery(line, IntersectionType.IT_INTERSECT); for (int i = 0; i < fs.Count; i++) { IFeature65 f = fs[i] as IFeature65; IGeometry geo = f.Geometry; IGeometry inter = line.SpatialOperator.Intersection(geo);// 平面相交 if (inter.GeometryType == SGGeometryTypeId.SG_POINT) { IPoint pt = inter as IPoint; ICoord2D coordInter = RenderControlServices.Instance().CovertCoord(pt.X, pt.Y); double height = 0.0; if (geo.GeometryType == SGGeometryTypeId.SG_LINESTRING) { ILineString geoLine = geo as ILineString; if (geoLine.Points.Count == 2) { double startPtH = geoLine.StartPoint.Z; double endPtH = geoLine.EndPoint.Z; ICoord2D sc = RenderControlServices.Instance().CovertCoord(geoLine.StartPoint.X, geoLine.StartPoint.Y); ICoord2D ec = RenderControlServices.Instance().CovertCoord(geoLine.EndPoint.X, geoLine.EndPoint.Y); height = GetInterectPointHeight(sc, startPtH, ec, endPtH, coordInter); } else { continue; } } IWorldPointInfo65 wpi = RenderControlServices.Instance().SGWorld.Terrain.GetGroundHeightInfo(pt.X, pt.Y, AccuracyLevel.ACCURACY_NORMAL, false); InterPointInfo interPtInfo = new InterPointInfo(); interPtInfo.pt = pt; interPtInfo.terrainHeight = wpi.Position.Altitude; interPtInfo.height = height; interPtInfo.coordInter = coordInter; interPtInfo.distance = Math.Sqrt((coordInter.X - startCoord.X) * (coordInter.X - startCoord.X) + (coordInter.Y - startCoord.Y) * (coordInter.Y - startCoord.Y)); interPtInfo.color.abgrColor = Convert.ToUInt32(l.ShpLayer.FeatureGroups.Polyline.GetProperty("Line Color").ToString()); interPtInfo.layerName = l.Name; interPtInfo.diameter = f.FeatureAttributes.GetFeatureAttribute(fDiameter.Name).Value; interPtInfo.classify = f.FeatureAttributes.GetFeatureAttribute(fClassify.Name).Value; interPtInfo.material = f.FeatureAttributes.GetFeatureAttribute(fMaterial.Name).Value; interPtInfo.hlb = f.FeatureAttributes.GetFeatureAttribute(fHlb.Name).Value; listInter.Add(interPtInfo); } } l.ShowShp = false; } WaitForm.Stop(); if (listInter.Count > 0) { listInter.Sort(new ComparerInterPointInfo()); for (int i = 0; i < listInter.Count; i++) { InterPointInfo info = listInter[i]; info.no = (i + 1); if (info.no > 1) { info.interHDist = info.distance - listInter[i - 1].distance; } IPosition65 pos = RenderControlServices.Instance().SGWorld.Creator.CreatePosition(info.pt.X, info.pt.Y); ILabelStyle65 lStyle = RenderControlServices.Instance().SGWorld.Creator.CreateLabelStyle(); lStyle.TextColor = info.color; lStyle.FontSize = 10; lStyle.MaxViewingHeight = 1000; ITerrainLabel65 label = RenderControlServices.Instance().SGWorld.Creator.CreateTextLabel(pos, info.no.ToString(), lStyle); label.Visibility.MaxVisibilityDistance = 1000; this._listLabel.Add(label); } DrawHorizontalSection(listInter); } }
private double L2Distance(ICoord2D a, ICoord2D b) { var dx = a.X - b.X; var dy = a.Y - b.Y; return(Math.Sqrt(dx * dx + dy * dy)); }