//加载shp文件并显示管线 private void btn_LoadLayer_Click(object sender, EventArgs e) { if (_layerAdded) { return; } _shpLayer = _glbControl.Globe.Layers.Add(_testShpPath); _shpLayer.Editable = true; //设置样式 GSOPipeLineStyle3D style = new GSOPipeLineStyle3D(); style.LineColor = Color.Green; //管线半径 style.Radius = _radius; //获得默认图层的要素 var features = _shpLayer.GetAllFeatures(); //遍历要素 for (int i = 0; i < features.Length; i++) { GSOGeoPolyline3D geometry = features[i].Geometry as GSOGeoPolyline3D; geometry.Style = style; //将高度抬高到管径高度 geometry.MoveZ(style.Radius); //重要,要将高度模式设置成相对地表,如果为依附地面则无渲染效果 geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround; } _glbControl.Refresh(); FlyToLayer(_shpLayer); }
private void one2Multi(GSOGeoPolyline3D line, int num_width, int num_height, double interval, GSOPipeLineStyle3D style, GSOFeatureDataset layer, string name, GSOFeature oldfeat) { line = LatLon2Coord_Line(line); double width_all = interval * (num_width - 1); double height_all = interval * (num_height - 1); line.Clone(); GSOGeoPolyline3D line_1 = line.Clone() as GSOGeoPolyline3D; GSOPoint3d p1 = line[0][0]; GSOPoint3d p2 = line[0][1]; double daltaX = p2.X - p1.X; double daltaY = p2.Y - p1.Y; double agree = Math.Atan(daltaY / daltaX); line.MoveXY((-0.5 * width_all - interval) * Math.Sin(agree), (0.5 * width_all + interval) * Math.Cos(agree)); line.MoveZ(height_all / -2); for (int i = 0; i < num_width; i++) { for (int j = 0; j < num_height; j++) { GSOGeoPolyline3D templine = line.Clone() as GSOGeoPolyline3D; templine.MoveXY((i + 1) * interval * Math.Sin(agree), -1 * (i + 1) * interval * Math.Cos(agree)); templine = Coord2LatLon_Line(templine); templine.MoveZ(interval * j); GSOFeature feat = layer.CreateFeature(); feat.Geometry = templine; feat.Geometry.Style = style; feat.Name = name; SetFields(oldfeat, feat); layer.AddFeature(feat); } } }
private void one2Multi(GSOGeoPolyline3D line, int num_width, int num_height, double interval, GSOPipeLineStyle3D style, GSOLayer layer,string name) { line = LatLon2Coord_Line(line); double width_all = interval * (num_width-1); double height_all = interval * (num_height-1); line.Clone(); GSOGeoPolyline3D line_1 = line.Clone() as GSOGeoPolyline3D; GSOPoint3d p1 = line[0][0]; GSOPoint3d p2 = line[0][1]; double daltaX = p2.X-p1.X; double daltaY = p2.Y-p1.Y; double agree = Math.Atan(daltaY/daltaX); line.MoveXY((-0.5*width_all-interval)*Math.Sin(agree),(0.5*width_all+interval)*Math.Cos(agree)); line.MoveZ(height_all / -2); for (int i = 0; i < num_width; i++) { for (int j = 0; j < num_height; j++) { GSOGeoPolyline3D templine = line.Clone() as GSOGeoPolyline3D; templine.MoveXY((i + 1) * interval * Math.Sin(agree), -1 * (i + 1) * interval * Math.Cos(agree)); templine = Coord2LatLon_Line(templine); templine.MoveZ(interval*j); GSOFeature feat = new GSOFeature(); feat.Geometry = templine; feat.Geometry.Style = style; feat.Name = name; layer.AddFeature(feat); } } }
private void btnApply_Click(object sender, EventArgs e) { GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(cmbLayers.Text.Trim()); if (layer == null) { MessageBox.Show("请选择图层", "提示"); return; } if (layer.Type != EnumLayerType.FeatureLayer) { MessageBox.Show("当前选中的图层不是模型图层!", "提示"); return; } GSOFeatureLayer flayer = layer as GSOFeatureLayer; GSOFeatures features = new GSOFeatures(); if (radioButtonElevateAllFeature.Checked == true) { features = flayer.GetAllFeatures(); } else if (radioButtonElevatePartFeature.Checked == true) { string fieldName = comboBoxFieldNames.Text.Trim(); if (fieldName == "") { MessageBox.Show("请选择字段名称!", "提示"); return; } if (listViewFieldValues.SelectedItems.Count <= 0) { MessageBox.Show("请选中一个字段值!", "提示"); return; } string fieldValue = listViewFieldValues.SelectedItems[0].Text.Trim(); features = flayer.GetFeatureByFieldValue(fieldName, fieldValue, true); } string elevateHeight = txtHeight.Text.Trim(); double height = 0; if (txtHeight.Text == "" || double.TryParse(elevateHeight, out height) == false) { MessageBox.Show("请输入正确的调整高度", "提示"); return; } for (int i = 0; i < features.Length; i++) { GSOFeature feature = features[i]; if (feature is GSOFeatureFolder) { MoveEachFeature(feature as GSOFeatureFolder, height); } else if (feature.Geometry is GSOGeoModel) { GSOGeoModel model = feature.Geometry as GSOGeoModel; if (model != null) { GSOPoint3d pt = model.Position; pt.Z += height; model.Position = pt; } } else if (feature.Geometry is GSOGeoPolyline3D) { GSOGeoPolyline3D templine = feature.Geometry as GSOGeoPolyline3D; if (templine != null) { templine.MoveZ(height); feature.Geometry = templine; } } } ctl.Refresh(); MessageBox.Show("抬升成功", "提示"); }
//创建管线要素 public void CreatePipeLine() { //创建线要素 GSOGeoPolyline3D line1 = new GSOGeoPolyline3D(); GSOPoint3ds points1 = new GSOPoint3ds(); GSOPoint3d point1 = new GSOPoint3d(120.27191, 31.9864637, 5); GSOPoint3d point2 = new GSOPoint3d(120.271, 31.9864637, 5); points1.Add(point1); points1.Add(point2); line1.AddPart(points1); //设置线高度模式为相对地表 line1.AltitudeMode = EnumAltitudeMode.RelativeToGround; //设置样式 GSOPipeLineStyle3D style = new GSOPipeLineStyle3D(); //管线颜色 style.LineColor = Color.Brown; //管线半径, 单位:米 style.Radius = 1; line1.Style = style; //相对地表抬高半径的距离 line1.MoveZ(style.Radius); //创建要素 _pipeFeature1 = new GSOFeature(); _pipeFeature1.Geometry = line1; //将要素添加到globe中并显示 _glbControl.Globe.MemoryLayer.AddFeature(_pipeFeature1); _pipeFeature2 = new GSOFeature(); GSOGeoPolyline3D line2 = new GSOGeoPolyline3D(); line2.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOPoint3ds points2 = new GSOPoint3ds(); GSOPoint3d point3 = new GSOPoint3d(120.27191, 31.986, 0); GSOPoint3d point4 = new GSOPoint3d(120.271, 31.986, 0); points2.Add(point3); points2.Add(point4); line2.AddPart(points2); line2.Style = style; line2.MoveZ(style.Radius); _pipeFeature2.Geometry = line2; _glbControl.Globe.MemoryLayer.AddFeature(_pipeFeature1); _glbControl.Globe.MemoryLayer.AddFeature(_pipeFeature2); _glbControl.Globe.FlyToFeature(_pipeFeature1); //添加辅助线 GSOSimpleLineStyle3D lineStyle = new GSOSimpleLineStyle3D() { LineColor = Color.Yellow, LineType = EnumLineType.Dot }; //水平线 GSOPoint3d pointtemp = new GSOPoint3d(point4.X, point4.Y, point2.Z + _radius); GSOGeoPolyline3D lineHor = new GSOGeoPolyline3D(); GSOPoint3ds pointsHor = new GSOPoint3ds(); pointsHor.Add(pointtemp); pointsHor.Add(new GSOPoint3d(point2.X, point2.Y, point2.Z + _radius)); lineHor.AddPart(pointsHor); lineHor.Style = lineStyle; lineHor.AltitudeMode = EnumAltitudeMode.RelativeToGround; double horLength = Math.Round(lineHor.GetSpaceLength(true, 6378137), 3); GSOFeature featureHorLine = new GSOFeature() { Geometry = lineHor }; featureHorLine.Label = CreateLabel(horLength.ToString()); this._glbControl.Globe.MemoryLayer.AddFeature(featureHorLine); //垂直线 GSOGeoPolyline3D lineVer = new GSOGeoPolyline3D(); GSOPoint3ds pointsVer = new GSOPoint3ds(); pointsVer.Add(pointtemp); pointsVer.Add(new GSOPoint3d(point4.X, point4.Y, point4.Z + _radius)); lineVer.AddPart(pointsVer); lineVer.Style = lineStyle; lineVer.AltitudeMode = EnumAltitudeMode.RelativeToGround; double verLength = Math.Round(Math.Abs(point2.Z - point4.Z)); GSOFeature featureVerLine = new GSOFeature() { Geometry = lineVer }; featureVerLine.Label = CreateLabel(verLength.ToString()); this._glbControl.Globe.MemoryLayer.AddFeature(featureVerLine); }