예제 #1
0
        public static GSOFeature FindFeatureByUserID(GSOFeatureDataset featdataset, string fieldname, string value)
        {
            GSOFeatures feats = featdataset.GetAllFeatures();

            for (int i = 0; i < feats.Length; i++)
            {
                GSOFeature feat = feats[i];
                if (feat.GetFieldAsString(fieldname) == value)
                {
                    return(feat);
                }
            }
            return(null);
        }
예제 #2
0
        private string GetBubbleInfo(GSOFeature feature, string width, string height)
        {
            string str = "<!-- <BALLOON><CONTENT_CX>" + width + "</CONTENT_CX><CONTENT_CY>" + height + "</CONTENT_CY><CONTENT_TYPE>text</CONTENT_TYPE><SHOW_MODE>balloonex</SHOW_MODE>-->";

            str += "<html><body><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"width:100%;background:#FFFFFF none repeat scroll 0 0;border-collapse:collapse;font-family:\"Lucida Sans Unicode\",\"Lucida Grande\",Sans-Serif;font-size:10px;text-align:center;\" >";

            for (int j = 0; j < listFields.CheckedItems.Count; j++)
            {
                GSOFieldDefn field1 = (GSOFieldDefn)feature.GetFieldDefn(listFields.CheckedItems[j].ToString());

                string value1 = feature.GetFieldAsString(listFields.CheckedItems[(j)].ToString());

                str += "<tr><td style=\"font-size:10pt;border:1px solid #CCCCCC;color:#666699;padding:2px 2px; background-color:#E7F3FB\"><center>" +
                       field1.Name +
                       "</center></td><td style=\"font-size:10pt;border:1px solid #CCCCCC;color:#666699;padding:2px 2px;\"><center>" +
                       value1 + "</center></td></tr>";
            }

            str += "</table></body></html>";
            return(str);
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("kml文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("kml文件已存在!", "提示");
                    return;
                }

                GSOLayer sourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer layer = ctl.Globe.Layers.Add(txtModelLayer.Text);
                lgdFilePath = txtModelLayer.Text;
                if (layer != null)
                {
                    GSOFeatures features = sourceLayer.GetAllFeatures();
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double       radius = 0;
                        GSOFieldDefn field  = (GSOFieldDefn)(f.GetFieldDefn(cmbRadius.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp   = f.GetFieldAsString(cmbRadius.SelectedItem.ToString());
                            double outNum = 0;
                            bool   num    = double.TryParse(temp, out outNum);
                            if (num)
                            {
                                radius = outNum / 2000;
                            }
                        }
                        else if (field.Type == EnumFieldType.Double)
                        {
                            radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                        }
                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        if (radius == 0)
                        {
                            message += "ID为" + f.ID + "的管线的半径为0  \n  ";
                            continue;
                        }
                        style.Radius           = radius;
                        style.Slice            = int.Parse(txtSlice.Text);
                        style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text);

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            message += "ID为" + f.ID + "的对象不是线对象 \n";
                            continue;
                        }

                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

                        if (chkDeep.Checked)
                        {
                            deep1 = 0 - deep1;
                            deep2 = 0 - deep2;
                        }

                        if (cmbReference.SelectedIndex == 0) //管底
                        {
                            deep1 = deep1 + radius * 2;
                            deep2 = deep2 + radius * 2;
                        }
                        else if (cmbReference.SelectedIndex == 1) //管顶
                        {
                            deep1 = deep1 - radius * 2;
                            deep2 = deep2 - radius * 2;
                        }
                        for (int n = 0; n < line[0].Count; n++)
                        {
                            GSOPoint3d pt3d       = line[0][n];
                            int        pointcount = line[0].Count;
                            double     radio      = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                            pt3d.Z     = deep1 + (deep2 - deep1) * radio;
                            line[0][n] = pt3d;
                        }

                        newFeature.Geometry       = line; // f.Geometry;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;
                        layer.AddFeature(newFeature);
                    }
                    ctl.Refresh();
                    layer.Save();
                    ctl.Globe.Layers.Remove(layer);
                    string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + layer.GetAllFeatures().Length + "个对象!\n";
                    MessageBox.Show(strMessage + message, "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
예제 #4
0
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("管线模型文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("管线模型文件已存在!", "提示");
                    return;
                }

                GSOLayer ShpSourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer pipeModelLayer = ctl.Globe.Layers.Add(txtModelLayer.Text);

                string   pipeRectFile = Path.GetDirectoryName(txtModelLayer.Text) + "\\" + Path.GetFileNameWithoutExtension(txtModelLayer.Text) + "_Rect" + Path.GetExtension(txtModelLayer.Text);
                GSOLayer layer_Rect   = ctl.Globe.Layers.Add(pipeRectFile);
                lgdFilePath = txtModelLayer.Text;

                if (pipeModelLayer != null)
                {
                    GSOFeatures features = ShpSourceLayer.GetAllFeatures();
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double       radius        = 0;
                        GSOFieldDefn diameterfield = (GSOFieldDefn)f.GetFieldDefn(cmbRadius.SelectedItem.ToString());
                        if (diameterfield.Type == EnumFieldType.Text)
                        {
                            radius = Convert.ToDouble(f.GetFieldAsString(cmbRadius.SelectedItem.ToString())) / 2000;
                        }
                        else
                        {
                            radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                        }

                        string eventid    = f.GetFieldAsString(cmbID.SelectedItem.ToString());
                        int    num_width  = f.GetFieldAsInt32(cmbWidthNum.SelectedItem.ToString());
                        int    num_height = f.GetFieldAsInt32(cmbHeightNum.SelectedItem.ToString());
                        double interval   = radius * 2;                    //  f.GetFieldAsDouble(cmbInterval.SelectedItem.ToString());
                        double rectWidth  = radius * 2 * num_width + 0.08; // 两端空出0.04
                        double rectHeight = radius * 2 * num_height + 0.08;
                        if (radius == 0)
                        {
                            message += "ID为" + f.ID + "的管线的半径为0  \n  ";
                            continue;
                        }

                        style.Radius           = radius;
                        style.Slice            = int.Parse(txtSlice.Text);
                        style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text);

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            message += "ID为" + f.ID + "的管线不是线对象  \n  ";
                            continue;
                        }

                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

                        if (chkDeep.Checked)
                        {
                            deep1 = 0 - deep1;
                            deep2 = 0 - deep2;
                        }

                        if (cmbReference.SelectedIndex == 0)  //管底
                        {
                            deep1 = deep1 + radius * 2;
                            deep2 = deep2 + radius * 2;
                        }
                        else if (cmbReference.SelectedIndex == 1)  //管顶
                        {
                            deep1 = deep1 - radius * 2;
                            deep2 = deep2 - radius * 2;
                        }
                        for (int n = 0; n < line[0].Count; n++)
                        {
                            GSOPoint3d pt3d       = line[0][n];
                            int        pointcount = line[0].Count;
                            double     radio      = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                            pt3d.Z = deep1 + (deep2 - deep1) * radio;

                            if (double.IsInfinity(pt3d.Z))
                            {
                                pt3d.Z = deep2;
                            }
                            line[0][n] = pt3d;
                        }
                        if (num_height == 0 || num_width == 0)  // 直埋
                        {
                            newFeature.Geometry       = line;
                            newFeature.Geometry.Style = style;
                            newFeature.Name           = eventid;
                            pipeModelLayer.AddFeature(newFeature);
                        }
                        else
                        {
                            GSOFeature rectfeat = CreatePipeRect(f, line, rectWidth, rectHeight);
                            if (rectfeat != null)
                            {
                                layer_Rect.AddFeature(rectfeat);
                            }
                            one2Multi(line, num_width, num_height, interval, style, pipeModelLayer, eventid);
                        }
                    }
                    ctl.Refresh();

                    pipeModelLayer.Save();
                    layer_Rect.Save();
                    string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + (pipeModelLayer.GetAllFeatures().Length + layer_Rect.GetAllFeatures().Length) + "个对象!\n";
                    MessageBox.Show(strMessage + message, "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
예제 #5
0
        private void DrawCurveGraph(double a_x, double a_y)
        {
            // 遍历线,求距离
            table = new DataTable();
            //showTable.Columns.Clear();
            list.Clear();
            chart1.Series["管线"].Points.Clear();

            table.Columns.Add("编号", typeof(string));
            table.Columns.Add("管线类型", typeof(string));
            table.Columns.Add("管线编码", typeof(string));
            table.Columns.Add("管径_毫米", typeof(string));
            table.Columns.Add("材质", typeof(string));
            table.Columns.Add("管线埋深", typeof(string));

            object[,] sortIndex = new object[listPoint.Count, 2];
            for (int i = 0; i < listPoint.Count; i++)
            {
                GSOPoint3d geoPoint = (GSOPoint3d)listPoint[i];
                GSOFeature feature  = listFeat[i] as GSOFeature;
                //坐标投影
                int id = GeoScene.Data.GSOProjectManager.AddProject("+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=555484.8092 +y_0=-4114948.631 +ellps=krass +units=m +no_defs");

                GeoScene.Data.GSOPoint2d a_Point = GeoScene.Data.GSOProjectManager.Forward(new GSOPoint2d(a_x, a_y), id);//user画的线的起始点

                GeoScene.Data.GSOPoint2d pt2d   = new GeoScene.Data.GSOPoint2d(geoPoint.X, geoPoint.Y);
                GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Forward(pt2d, id);
                B_x = result.X;
                B_y = result.Y;

                double x   = System.Math.Abs(B_x - a_Point.X);
                double y   = System.Math.Abs(B_y - a_Point.Y);
                double Dis = Math.Round(Math.Sqrt(x * x + y * y), 2);
                list.Add(geoPoint.Z);
                sortIndex[i, 0] = Dis;
                sortIndex[i, 1] = i;

                chart1.Series["管线"].Points.AddXY(Dis, geoPoint.Z);//绑定数据

                string pipeType = "";
                if (feature.GetFieldAsInt32("管线编码") >= 6000 && feature.GetFieldAsInt32("管线编码") <= 6203)  // 6100是热力管线的编码
                {
                    pipeType = "热力管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 4000 && feature.GetFieldAsInt32("管线编码") <= 4306)//排水
                {
                    pipeType = "排水管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 3000 && feature.GetFieldAsInt32("管线编码") <= 3513)  // 3000是给力管线的编码
                {
                    pipeType = "给水管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 1000 && feature.GetFieldAsInt32("管线编码") <= 1808)  // 电力管线的编码
                {
                    pipeType = "电力管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 2000 && feature.GetFieldAsInt32("管线编码") <= 2300)  // 通信管线的编码
                {
                    pipeType = "通信管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 5000 && feature.GetFieldAsInt32("管线编码") <= 5200)  // 通信管线的编码
                {
                    pipeType = "燃气管线";
                }
                string number = Convert.ToString(i + 1);

                string material = feature.GetFieldAsString("材质");
                string diameter = feature.GetFieldAsString("管径_毫米");
                table.Rows.Add(new object[] { number, pipeType, feature.Name.ToString(), diameter, material, Convert.ToDecimal(list[i].ToString()).ToString("f2") });//list[i].ToString().Substring(0,list[i].ToString().IndexOf('.')+3) }

                //chart1.Series["管线"].Points[i].Label = number;//管线的标签
                chart1.Series["管线"].Points[i].LegendText = number;
                if (feature.Geometry.Style.GetType() == typeof(GSOPipeLineStyle3D))
                {
                    GSOPipeLineStyle3D style = (GSOPipeLineStyle3D)feature.Geometry.Style;
                    chart1.Series["管线"].Points[i].MarkerBorderColor = style.LineColor;     //点的填充色
                }
                else
                {
                    chart1.Series["管线"].Points[i].MarkerBorderColor = Color.Black;
                }

                chart1.Series["管线"].Points[i].MarkerBorderWidth = 3;                                                                                                                                //边框的宽度
                chart1.Series["管线"].Points[i].MarkerColor       = Color.Transparent;
                chart1.Series["管线"].Points[i].MarkerSize        = Convert.ToInt32(Math.Floor((feature.GetFieldAsDouble("管径_毫米") / 0.35 + chart1.Series["管线"].Points[i].MarkerBorderWidth) / 25.0)); //点的大小
            }

            string htmlCode = "<html><head><style>#hor-minimalist-b " +
                              "{-moz-background-clip:border;" +
                              "-moz-background-inline-policy:continuous;" +
                              "-moz-background-origin:padding;" +
                              "background:#FFFFFF none repeat scroll 0 0;" +
                              "border-collapse:collapse;" +
                              "font-family:'Lucida Sans Unicode','Lucida Grande',Sans-Serif;" +
                              " font-size:12px;" +
                              " margin:10px;" +
                              " text-align:left;" +
                              " width:80%;" +
                              " }" +
                              " #hor-minimalist-b th {" +
                              " border-bottom:2px solid #6678B1;" +
                              " color:#003399;" +
                              " font-size:12px;" +
                              "font-weight:normal;" +
                              "  padding:10px 8px;" +
                              " }" +
                              "  #hor-minimalist-b td {" +
                              " border-bottom:1px solid #CCCCCC;" +
                              " font-size:12px;" +
                              " color:#666699;" +
                              "padding:6px 8px;}" +
                              "#hor-minimalist-b tbody tr:hover td {" +
                              "color:#000099;}" +
                              "</style></head>" +
                              "<body style='border:none;' ><table align='center' summary='Employee Pay Sheet' id='hor-minimalist-b'><thead><tr><th scope='col'>管线类型</th><th scope='col'>管线编码</th><th scope='col'>管径_毫米</th>" +
                              "<th scope='col'>材质</th><th scope='col'>管线埋深</th></tr></thead>" +
                              "<tbody><tr><td>" +
                              "</td><td>" +
                              "</td><td>" +
                              "</td><td>" +
                              "</td><td>" +
                              "</td></tr></tbody></table></body><ml>";

            webBrowser1.DocumentText = htmlCode;
        }
예제 #6
0
        private void valiPipedata(GSOLayer layer)
        {
            txtMessage.Text = "";
            if (layer != null)
            {
                GSOFeatureDataset featDataSet        = layer.Dataset as GSOFeatureDataset;
                List <string>     lstField           = new List <string>();
                List <string>     listFieldType_Text = new List <string>();
                for (int i = 0; i < featDataSet.FieldCount; i++)
                {
                    string fieldName = featDataSet.GetField(i).Name;
                    lstField.Add(fieldName);
                    if (fields_types.ContainsKey(fieldName))
                    {
                        string fieldType = fields_types[fieldName].ToString().ToUpper();
                        switch (featDataSet.GetField(i).Type)
                        {
                        case EnumFieldType.Text:
                            if (fieldType != "string".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            listFieldType_Text.Add(fieldName);
                            break;

                        case EnumFieldType.INT32:
                            if (fieldType != "int".ToUpper() && fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.INT16:
                            if (fieldType != "int".ToUpper() && fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.Double:
                            if (fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.Date:
                            if (fieldType != "date".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;
                        }
                    }
                    else
                    {
                        txtMessage.Text += "警告:配置文件中不包含\"" + fieldName + "\"字段\r\n";
                    }
                }
                if (!lstField.Contains("Deep1"))
                {
                    txtMessage.Text += "Deep1字段不存在!\r\n";
                }
                else
                {
                    GSOFieldAttr fieldDeep1 = featDataSet.GetField("Deep1");
                    if (fieldDeep1.Type != EnumFieldType.Double && fieldDeep1.Type != EnumFieldType.Float && fieldDeep1.Type != EnumFieldType.INT16 && fieldDeep1.Type != EnumFieldType.INT32)
                    {
                        txtMessage.Text += "Deep1字段必须为数值类型\r\n";
                    }
                }
                if (!lstField.Contains("Deep2"))
                {
                    txtMessage.Text += "Deep2字段不存在!\r\n";
                }
                else
                {
                    GSOFieldAttr fieldDeep1 = featDataSet.GetField("Deep2");
                    if (fieldDeep1.Type != EnumFieldType.Double && fieldDeep1.Type != EnumFieldType.Float && fieldDeep1.Type != EnumFieldType.INT16 && fieldDeep1.Type != EnumFieldType.INT32)
                    {
                        txtMessage.Text += "Deep2字段必须为数值类型\r\n";
                    }
                }
                if (!lstField.Contains("Diameter"))
                {
                    txtMessage.Text += "Diameter字段不存在!\r\n";
                }
                else
                {
                    GSOFieldAttr fieldDeep1 = featDataSet.GetField("Diameter");
                    if (fieldDeep1.Type != EnumFieldType.Double && fieldDeep1.Type != EnumFieldType.Float && fieldDeep1.Type != EnumFieldType.INT16 && fieldDeep1.Type != EnumFieldType.INT32)
                    {
                        txtMessage.Text += "Diameter字段必须为数值类型\r\n";
                    }
                }
                if (!lstField.Contains("Handle"))
                {
                    txtMessage.Text += "Handle字段不存在!\r\n";
                }
                List <string> lstHandle = new List <string>();
                for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                {
                    GSOFeature f = layer.GetAt(i);
                    for (int j = 0; j < listFieldType_Text.Count; j++)
                    {
                        string fieldName = listFieldType_Text[j];
                        if (fields_types.ContainsKey(fieldName))
                        {
                            if (f.GetValue(fieldName).ToString().Trim().Length > 8000)
                            {
                                txtMessage.Text += "ID为" + f.ID + "的要素的字段" + fieldName + "的长度大于8000 !\r\n";
                            }
                        }
                    }
                    if (f.GetFieldAsFloat("Diameter") <= 0)
                    {
                        txtMessage.Text += "ID为" + f.ID + "\"Diameter\"字段中的值必须大于0 \r\n";
                    }
                    if (!lstHandle.Contains(f.GetFieldAsString("Handle")))
                    {
                        lstHandle.Add(f.GetFieldAsString("Handle"));
                    }
                    else
                    {
                        txtMessage.Text += "ID为" + f.ID + "的\"Handle\"字段中的值重复\r\n";
                    }
                }
            }
        }
예제 #7
0
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("管沟模型文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("管沟模型文件已存在!", "提示");
                    return;
                }

                GSOLayer sourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer layer = ctl.Globe.Layers.Add(txtModelLayer.Text);
                lgdFilePath = txtModelLayer.Text;
                if (layer != null)
                {
                    GSOFeatures features = sourceLayer.GetAllFeatures();

                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double radius  = f.GetFieldAsDouble(cmbRadius.SelectedIndex) / 1000; // 单位
                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        style.Radius           = radius;
                        style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text);


                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            return;
                        }



                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

                        if (chkDeep.Checked)
                        {
                            deep1 = 0 - deep1;
                            deep2 = 0 - deep2;
                        }

                        if (cmbReference.SelectedIndex == 0)  //管底
                        {
                            deep1 = deep1 + radius;
                            deep2 = deep2 + radius;
                        }
                        else if (cmbReference.SelectedIndex == 1)  //管顶
                        {
                            deep1 = deep1 - radius;
                            deep2 = deep2 - radius;
                        }
                        for (int n = 0; n < line[0].Count; n++)
                        {
                            GSOPoint3d pt3d       = line[0][n];
                            int        pointcount = line[0].Count;
                            double     radio      = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                            pt3d.Z     = deep1 + (deep2 - deep1) * radio;
                            line[0][n] = pt3d;
                        }

                        newFeature.Geometry       = line; // f.Geometry;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;
                        //newFeature.CustomID = f.ID;
                        layer.AddFeature(newFeature);
                    }
                }
                ctl.Refresh();

                layer.Save();

                ctl.Globe.Layers.Remove(layer);
                this.Close();
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
예제 #8
0
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个目标数据源!", "提示");
                return;
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

            if (ds == null)
            {
                MessageBox.Show("选择的目标数据源为空!", "提示");
                return;
            }
            try
            {
                if (string.IsNullOrEmpty(textBoxNewLayerName.Text))
                {
                    MessageBox.Show("管线图层名称无效!", "提示");
                    return;
                }
                if (valiPipeData())
                {
                    GSODataset        dataset = ds.GetDatasetByName(textBoxNewLayerName.Text.Trim());
                    GSOFeatureDataset newFeatureDataset;
                    if (dataset != null)
                    {
                        DialogResult result = MessageBox.Show("管线图层名称在数据库中已存在!是否向该表追加", "提示", MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            newFeatureDataset = dataset as GSOFeatureDataset;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        newFeatureDataset = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim());
                    }
                    if (newFeatureDataset == null)
                    {
                        MessageBox.Show("输入的图层名称不符合要求!", "提示");
                        return;
                    }
                    GSOLayer sourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());
                    if (sourceLayer == null)
                    {
                        MessageBox.Show("选择的shp图层为空!", "提示");
                        return;
                    }
                    newFeatureDataset.Open();
                    GSOFeatures features = sourceLayer.GetAllFeatures(true);
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature    = newFeatureDataset.CreateFeature();
                        string     maisheFangshi = f.GetFieldAsString(cmbMaiSheFangShi.SelectedItem.ToString());
                        string     eventid       = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            message += "ID为" + f.ID + "的管线不是一个线对象\r\n";
                            continue;
                        }

                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

                        if (chkDeep.Checked)
                        {
                            deep1 = 0 - deep1;
                            deep2 = 0 - deep2;
                        }

                        if (maisheFangshi == "直埋")
                        {
                            GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                            style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                            double       radius = 0;
                            GSOFieldDefn field  = (GSOFieldDefn)(f.GetFieldDefn(cmbRadius.SelectedItem.ToString()));
                            if (field.Type == EnumFieldType.Text)
                            {
                                string temp   = f.GetFieldAsString(cmbRadius.SelectedItem.ToString());
                                double outNum = 0;
                                bool   num    = double.TryParse(temp, out outNum);
                                if (num)
                                {
                                    radius = outNum / 2000;
                                }
                            }
                            else if (field.Type == EnumFieldType.Double)
                            {
                                radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                            }
                            if (radius == 0)
                            {
                                message += "ID为" + f.ID + "的管线半径为0\r\n";
                                continue;
                            }

                            style.Radius           = radius;
                            style.Slice            = int.Parse(txtSlice.Text);
                            style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text);


                            if (cmbReference.SelectedIndex == 0) //管底
                            {
                                deep1 = deep1 + radius * 2;
                                deep2 = deep2 + radius * 2;
                            }
                            else if (cmbReference.SelectedIndex == 1) //管顶
                            {
                                deep1 = deep1 - radius * 2;
                                deep2 = deep2 - radius * 2;
                            }
                            for (int n = 0; n < line[0].Count; n++)
                            {
                                GSOPoint3d pt3d       = line[0][n];
                                int        pointcount = line[0].Count;
                                double     fenmu      = Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                                if (fenmu == 0)
                                {
                                    pt3d.Z = deep1;
                                }
                                else
                                {
                                    double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / fenmu;
                                    pt3d.Z = deep1 + (deep2 - deep1) * radio;
                                }
                                line[0][n] = pt3d;
                            }

                            newFeature.Geometry       = line; // f.Geometry;
                            newFeature.Geometry.Style = style;
                        }
                        else if (maisheFangshi == "沟道")
                        {
                            GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D();
                            style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                            double       width = 0;
                            GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbWidth.SelectedItem.ToString()));
                            if (field.Type == EnumFieldType.Text)
                            {
                                string temp   = f.GetFieldAsString(cmbWidth.SelectedItem.ToString());
                                double outNum = 0;
                                bool   num    = double.TryParse(temp, out outNum);
                                if (num)
                                {
                                    width = outNum;
                                }
                            }
                            else if (field.Type == EnumFieldType.Double)
                            {
                                width = f.GetFieldAsDouble(cmbWidth.SelectedItem.ToString());
                            }


                            double height = 0;
                            field = (GSOFieldDefn)(f.GetFieldDefn(cmbHeight.SelectedItem.ToString()));
                            if (field.Type == EnumFieldType.Text)
                            {
                                string temp   = f.GetFieldAsString(cmbHeight.SelectedItem.ToString());
                                double outNum = 0;
                                bool   num    = double.TryParse(temp, out outNum);
                                if (num)
                                {
                                    height = outNum;
                                }
                            }
                            else if (field.Type == EnumFieldType.Double)
                            {
                                height = f.GetFieldAsDouble(cmbHeight.SelectedItem.ToString());
                            }


                            if (width == 0 || height == 0)
                            {
                                message += "ID为" + f.ID + "的沟道的宽度或高度为0\r\n";
                                continue;
                            }

                            GSOPoint3ds sectionpts = new GSOPoint3ds();
                            sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                            sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
                            sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
                            sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));

                            style.SetSectionPoints(sectionpts);
                            style.IsClosed = false;
                            style.SetAnchorByAlign(EnumAlign.BottomCenter);


                            for (int n = 0; n < line[0].Count; n++)
                            {
                                GSOPoint3d pt3d       = line[0][n];
                                int        pointcount = line[0].Count;
                                double     fenmu      = Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                                if (fenmu == 0)
                                {
                                    pt3d.Z = deep1;
                                }
                                else
                                {
                                    double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / fenmu;
                                    pt3d.Z = deep1 + (deep2 - deep1) * radio;
                                }
                                line[0][n] = pt3d;
                            }

                            newFeature.Geometry       = line; // f.Geometry;
                            newFeature.Geometry.Style = style;
                        }
                        else
                        {
                            message += "ID为" + f.ID + "的对象的埋设方式既不是直埋,也不是沟道\r\n";
                            continue;  // 即不是 直埋,又不是 沟道,那么忽略该记录
                        }

                        for (int i = 0; i < f.GetFieldCount(); i++)
                        {
                            GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i));
                            if (!en_cns.ContainsKey(fielddef.Name))
                            {
                                continue;
                            }

                            object fieldvalue = f.GetValue(fielddef.Name);// convertFieldValue(fielddef.Name, f.GetValue(fielddef.Name));
                            if (fieldvalue == null)
                            {
                                continue;
                            }
                            string fieldName = en_cns.ContainsKey(fielddef.Name) == true ? en_cns[fielddef.Name].ToString() : fielddef.Name;
                            newFeature.SetValue(fieldName, fieldvalue);
                        }

                        newFeature.Name = eventid;
                        newFeatureDataset.AddFeature(newFeature);
                    }
                    globeControl1.Refresh();

                    newFeatureDataset.Save();
                    newFeatureDataset.Close();
                    newFeatureDataset.Caption = newFeatureDataset.Name;
                    globeControl1.Globe.Layers.Add(newFeatureDataset);

                    string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + newFeatureDataset.GetAllFeatures().Length + "个对象!\r\n";
                    if (message == "")
                    {
                        MessageBox.Show(strMessage, "提示");
                    }
                    else
                    {
                        FrmMessageShow frm = new FrmMessageShow(strMessage + message);
                        frm.ShowDialog();
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个目标数据源!", "提示");
                return;
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

            if (ds == null)
            {
                MessageBox.Show("选择的目标数据源为空!", "提示");
                return;
            }
            if (comboBoxShpLayerList.SelectedIndex < 0)
            {
                return;
            }
            try
            {
                if (valiValvedata())
                {
                    GSOFeatureDataset featdataset = CreateDBFeatureDataset(textBoxNewLayerName.Text);
                    if (featdataset == null)
                    {
                        return;
                    }
                    featdataset.Open();
                    GSOLayer shpLayer = globeControl1.Globe.Layers[comboBoxShpLayerList.SelectedIndex];
                    if (shpLayer == null)
                    {
                        return;
                    }

                    GSOFeatures features = shpLayer.GetAllFeatures(true);
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature    f        = features[j];
                        GSOGeoPoint3D shpPoint = f.Geometry as GSOGeoPoint3D;
                        double        z        = f.GetFieldAsDouble(combZ.SelectedItem.ToString());
                        double        deep     = f.GetFieldAsDouble(combZ.SelectedItem.ToString());

                        GSOFeature  feature = featdataset.CreateFeature();
                        GSOGeoModel model   = new GSOGeoModel();
                        GSOPoint3d  pt      = new GSOPoint3d();
                        pt.X = shpPoint.X;
                        pt.Y = shpPoint.Y;
                        pt.Z = z;

                        model.Position     = pt;
                        model.AltitudeMode = EnumAltitudeMode.RelativeToGround;
                        string modelPath = f.GetFieldAsString(combPath.SelectedItem.ToString());
                        model.FilePath   = Application.StartupPath + "\\" + modelPath;
                        model.Name       = f.GetValue(combModelName.SelectedItem.ToString()).ToString();
                        feature.Name     = f.GetValue(combModelName.SelectedItem.ToString()).ToString();
                        feature.Geometry = model;

                        for (int i = 0; i < f.GetFieldCount(); i++)
                        {
                            GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i));
                            if (fielddef == null)
                            {
                                continue;
                            }
                            if (!fm_cns.ContainsKey(fielddef.Name))
                            {
                                continue;
                            }

                            object obu = f.GetValue(fielddef.Name);
                            if (obu != null)
                            {
                                string fieldName = fm_cns.ContainsKey(fielddef.Name) == true ? fm_cns[fielddef.Name].ToString() : fielddef.Name;
                                feature.SetValue(fieldName, obu);
                            }
                        }
                        featdataset.AddFeature(feature);
                    }
                    featdataset.Save();

                    string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + featdataset.GetAllFeatures().Length + "个对象!\r\n";
                    if (message == "")
                    {
                        MessageBox.Show(strMessage, "提示");
                    }
                    else
                    {
                        FrmMessageShow frm = new FrmMessageShow(strMessage + message);
                        frm.ShowDialog();
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个目标数据源!", "提示");
                return;
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

            if (ds == null)
            {
                MessageBox.Show("选择的目标数据源为空!", "提示");
                return;
            }
            if (string.IsNullOrEmpty(textBoxNewLayerName.Text))
            {
                MessageBox.Show("请选择一个Shp图层!", "提示");
                return;
            }
            if (ds.GetDatasetByName(textBoxNewLayerName.Text) != null)
            {
                MessageBox.Show("图层名称已存在!", "提示");
                return;
            }
            try
            {
                GSOLayer          ShpSourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());
                GSOFeatureDataset pipeline       = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim());
                if (pipeline == null)
                {
                    MessageBox.Show("输入的图层名称不符合要求!", "提示");
                    return;
                }
                pipeline.Open();
                GSOFeatureDataset pipelineRect = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim() + "_Rect");
                if (pipelineRect == null)
                {
                    return;
                }
                pipelineRect.Open();

                GSOFeatures features = ShpSourceLayer.GetAllFeatures();
                string      message  = "";
                for (int j = 0; j < features.Length; j++)
                {
                    GSOFeature f = features[j];

                    GSOFeature newFeature = pipeline.CreateFeature();

                    GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                    style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                    double radius = 0;
                    if (cmbRadius.SelectedItem == null)
                    {
                        cmbRadius.SelectedIndex = 0;
                    }
                    GSOFieldDefn diameterfield = (GSOFieldDefn)f.GetFieldDefn(cmbRadius.SelectedItem.ToString());
                    string       fieldText     = f.GetFieldAsString(cmbRadius.SelectedItem.ToString());
                    if (diameterfield.Type == EnumFieldType.Text)
                    {
                        if (double.TryParse(fieldText, out radius))
                        {
                            radius = radius / 2000;
                        }
                        else
                        {
                            message += "ID为" + f.ID + "的对象的管径字段值不符合要求!\r\n";
                            continue;
                        }
                    }
                    else
                    {
                        radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                    }

                    if (cmbID.SelectedItem == null)
                    {
                        cmbID.SelectedIndex = 0;
                    }
                    if (cmbWidthNum.SelectedItem == null)
                    {
                        cmbWidthNum.SelectedIndex = 0;
                    }
                    if (cmbHeightNum.SelectedItem == null)
                    {
                        cmbHeightNum.SelectedIndex = 0;
                    }
                    string eventid    = f.GetFieldAsString(cmbID.SelectedItem.ToString());
                    double interval   = radius * 2;
                    int    num_width  = 0;
                    int    num_height = 0;
                    if (!int.TryParse(f.GetFieldAsString(cmbWidthNum.SelectedItem.ToString()), out num_width))
                    {
                        message += "ID为" + f.ID + "的对象的宽度字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!int.TryParse(f.GetFieldAsString(cmbHeightNum.SelectedItem.ToString()), out num_height))
                    {
                        message += "ID为" + f.ID + "的对象的高度字段值不符合要求!\r\n";
                        continue;
                    }

                    double rectWidth  = radius * 2 * num_width + 0.08;// 两端空出0.04
                    double rectHeight = radius * 2 * num_height + 0.08;

                    if (radius == 0)
                    {
                        message += "ID为" + f.ID + "的对象的管径字段值为0!\r\n";
                        continue;
                    }

                    int    intSlice         = 0;
                    double cornerSliceAngle = 0;
                    if (!int.TryParse(txtSlice.Text.Trim(), out intSlice))
                    {
                        message += "ID为" + f.ID + "的对象的截面分段数字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!double.TryParse(textBoxCornerSliceAngle.Text.Trim(), out cornerSliceAngle))
                    {
                        message += "ID为" + f.ID + "的对象的拐弯平滑度字段值不符合要求!\r\n";
                        continue;
                    }
                    style.Radius           = radius;
                    style.Slice            = intSlice;
                    style.CornerSliceAngle = cornerSliceAngle;

                    f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                    GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                    if (line == null)
                    {
                        message += "ID为" + f.ID + "的对象不是一个线对象!\r\n";
                        continue;
                    }

                    if (cmbFrom.SelectedItem == null)
                    {
                        cmbFrom.SelectedIndex = 0;
                    }
                    if (cmbTo.SelectedItem == null)
                    {
                        cmbTo.SelectedIndex = 0;
                    }
                    double deep1 = 0;
                    double deep2 = 0;
                    if (!double.TryParse(f.GetFieldAsString(cmbFrom.Items[cmbTo.SelectedIndex].ToString().Trim()), out deep1))
                    {
                        message += "ID为" + f.ID + "的对象的起点埋深字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!double.TryParse(f.GetFieldAsString(cmbTo.Items[cmbTo.SelectedIndex].ToString().Trim()), out deep2))
                    {
                        message += "ID为" + f.ID + "的对象的终点埋深字段值不符合要求!\r\n";
                        continue;
                    }


                    if (chkDeep.Checked)
                    {
                        deep1 = 0 - deep1;
                        deep2 = 0 - deep2;
                    }

                    if (cmbReference.SelectedIndex == 0) //管底
                    {
                        deep1 = deep1 + radius * 2;
                        deep2 = deep2 + radius * 2;
                    }
                    else if (cmbReference.SelectedIndex == 1) //管顶
                    {
                        deep1 = deep1 - radius * 2;
                        deep2 = deep2 - radius * 2;
                    }
                    for (int n = 0; n < line[0].Count; n++)
                    {
                        GSOPoint3d pt3d       = line[0][n];
                        int        pointcount = line[0].Count;
                        double     radio      = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                        pt3d.Z = deep1 + (deep2 - deep1) * radio;

                        if (double.IsInfinity(pt3d.Z))
                        {
                            pt3d.Z = deep2;
                        }
                        line[0][n] = pt3d;
                    }
                    if (num_height == 0 || num_width == 0) // 直埋
                    {
                        newFeature.Geometry       = line;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;
                        SetFields(f, newFeature);

                        pipeline.AddFeature(newFeature);
                    }
                    else
                    {
                        GSOFeature rectfeat = pipelineRect.CreateFeature();
                        rectfeat.Geometry = CreatePipeRect(line, rectWidth, rectHeight);
                        if (rectfeat != null)
                        {
                            SetFields(f, rectfeat);
                            pipelineRect.AddFeature(rectfeat);
                        }
                        one2Multi(line, num_width, num_height, interval, style, pipeline, eventid, f);
                    }
                }
                globeControl1.Refresh();

                pipeline.Save();
                pipelineRect.Save();
                pipeline.Close();
                pipelineRect.Close();
                string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + pipeline.GetAllFeatures().Length + "个对象!\r\n";
                if (message == "")
                {
                    MessageBox.Show(strMessage, "提示");
                }
                else
                {
                    FrmMessageShow frm = new FrmMessageShow(strMessage + message);
                    frm.ShowDialog();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个目标数据源!", "提示");
                return;
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

            if (ds == null)
            {
                MessageBox.Show("选择的目标数据源为空!", "提示");
                return;
            }
            //判断是数字或者存在特殊字符串
            string SuiD = textBoxNewLayerName.Text.ToString().Trim();
            Regex  reg  = new Regex("^[0-9]+$");//判断是不是数据,要不是就表示没有选择。则从隐藏域里读出来
            Match  ma   = reg.Match(SuiD);

            if (ma.Success)
            {
                MessageBox.Show("管线图层名称不能全部为数字!", "警告");
                return;
            }

            try
            {
                // if (valiPipeData())
                {
                    if (string.IsNullOrEmpty(textBoxNewLayerName.Text))
                    {
                        MessageBox.Show("管线图层名称无效!", "提示");
                        return;
                    }

                    GSODataset dataset = ds.GetDatasetByName(textBoxNewLayerName.Text.Trim());

                    GSOFeatureDataset newFeatureDataset;
                    if (dataset != null)
                    {
                        DialogResult result = MessageBox.Show("管线图层名称在数据库中已存在!是否向该表追加", "提示", MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            newFeatureDataset = dataset as GSOFeatureDataset;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        newFeatureDataset = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim());
                    }
                    if (newFeatureDataset == null)
                    {
                        return;
                    }
                    GSOLayer sourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());
                    newFeatureDataset.Open();
                    GSOFeatures features = sourceLayer.GetAllFeatures(true);
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOGeoPolyline3D lineeee = f.Geometry as GSOGeoPolyline3D;
                        if (lineeee == null)
                        {
                            message += "ID为" + f.ID + "的对象不是一个线对象\n";
                            continue;
                        }
                        double length = lineeee.GetSpaceLength(true, 6378137);
                        if (length == 0)
                        {
                            message += "ID为" + f.ID + "的管线长度为0\n";
                            continue;
                        }

                        GSOFeature newFeature = newFeatureDataset.CreateFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double       radius = 0;
                        GSOFieldDefn field  = (GSOFieldDefn)(f.GetFieldDefn(cmbRadius.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp   = f.GetFieldAsString(cmbRadius.SelectedItem.ToString());
                            double outNum = 0;
                            bool   num    = double.TryParse(temp, out outNum);
                            if (num)
                            {
                                radius = outNum / 2000;
                            }
                        }
                        else if (field.Type == EnumFieldType.INT32 || field.Type == EnumFieldType.Double)
                        {
                            radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                        }
                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        if (radius == 0)
                        {
                            message += "ID为" + f.ID + "的管线半径为0\n";
                            continue;
                        }

                        style.Radius           = radius;
                        style.Slice            = int.Parse(txtSlice.Text);
                        style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text);

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            return;
                        }

                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

                        if (chkDeep.Checked)
                        {
                            deep1 = 0 - deep1;
                            deep2 = 0 - deep2;
                        }

                        if (cmbReference.SelectedIndex == 0) //管底
                        {
                            deep1 = deep1 + radius * 2;
                            deep2 = deep2 + radius * 2;
                        }
                        else if (cmbReference.SelectedIndex == 1) //管顶
                        {
                            deep1 = deep1 - radius * 2;
                            deep2 = deep2 - radius * 2;
                        }
                        for (int n = 0; n < line[0].Count; n++)
                        {
                            GSOPoint3d pt3d       = line[0][n];
                            int        pointcount = line[0].Count;
                            double     fenmu      = Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));

                            if (fenmu == 0)
                            {
                                pt3d.Z = deep1;
                            }
                            else
                            {
                                double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / fenmu;
                                pt3d.Z = deep1 + (deep2 - deep1) * radio;
                            }

                            if (double.IsInfinity(pt3d.Z))
                            {
                                pt3d.Z = deep2;
                            }
                            line[0][n] = pt3d;
                        }

                        newFeature.Geometry       = line; // f.Geometry;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;

                        for (int i = 0; i < f.GetFieldCount(); i++)
                        {
                            GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i));
                            if (fielddef == null)
                            {
                                continue;
                            }
                            if (!en_cns.Contains(fielddef.Name))
                            {
                                continue;
                            }
                            object fieldvalue = f.GetValue(fielddef.Name);// convertFieldValue(fielddef.Name, f.GetValue(fielddef.Name));
                            if (fieldvalue == null)
                            {
                                continue;
                            }
                            string fieldName = en_cns.ContainsKey(fielddef.Name) == true ? en_cns[fielddef.Name].ToString() : fielddef.Name;
                            newFeature.SetValue(fieldName, fieldvalue);
                        }

                        newFeatureDataset.AddFeature(newFeature);
                    }
                    newFeatureDataset.Save();
                    newFeatureDataset.Caption = newFeatureDataset.Name;
                    globeControl1.Globe.Layers.Add(newFeatureDataset);
                    globeControl1.Refresh();

                    string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + newFeatureDataset.GetAllFeatures().Length + "个对象!\n";
                    if (message == "")
                    {
                        MessageBox.Show(strMessage, "提示");
                    }
                    else
                    {
                        FrmMessageShow frm = new FrmMessageShow(strMessage + message);
                        frm.ShowDialog();
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
예제 #12
0
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("文件已存在!", "提示");
                    return;
                }

                GSOLayer sourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer layer = ctl.Globe.Layers.Add(txtModelLayer.Text);
                lgdFilePath = txtModelLayer.Text;
                if (layer != null)
                {
                    GSOFeatures features = sourceLayer.GetAllFeatures();

                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f          = features[j];
                        GSOFeature newFeature = new GSOFeature();

                        string text = "";
                        if (combLabel.SelectedItem != null)
                        {
                            text = f.GetFieldAsString(combLabel.SelectedItem.ToString());
                        }
                        if (listFields.CheckedItems.Count > 0)
                        {
                            newFeature.Description = GetBubbleInfo(f, numWidth.Value.ToString(), numHeight.Value.ToString());
                        }

                        if (f.Geometry is GSOGeoPoint3D)
                        {
                            GSOGeoMarker marker = new GSOGeoMarker();
                            marker.Position = f.Geometry.GeoCenterPoint;
                            marker.Text     = text;
                            GSOMarkerStyle3D style = new GSOMarkerStyle3D();
                            style.IconPath      = Application.StartupPath + "\\Resource\\ddd.png";
                            marker.Style        = style;
                            newFeature.Geometry = marker;
                        }
                        else if (f.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                        {
                            GSOGeoPolyline3D line  = (GSOGeoPolyline3D)f.Geometry.Clone();
                            GSOLabel         label = new GSOLabel();
                            label.Text = text;
                            GSOLabelStyle style = new GSOLabelStyle();
                            style.HasTracktionLine   = false;
                            style.OutlineColor       = Color.Transparent;
                            style.MaxVisibleDistance = 100000;
                            label.Style         = style;
                            line.Label          = label;
                            newFeature.Geometry = line;
                        }
                        else if (f.Geometry.Type == EnumGeometryType.GeoPolygon3D)
                        {
                            GSOGeoPolygon3D polygon = (GSOGeoPolygon3D)f.Geometry.Clone();
                            GSOLabel        label   = new GSOLabel();
                            label.Text = text;
                            GSOLabelStyle style = new GSOLabelStyle();
                            style.HasTracktionLine   = false;
                            style.OutlineColor       = Color.Transparent;
                            style.MaxVisibleDistance = 100000;
                            label.Style         = style;
                            polygon.Label       = label;
                            newFeature.Geometry = polygon;
                        }
                        newFeature.Name = text;
                        layer.AddFeature(newFeature);
                    }
                }
                ctl.Refresh();
                layer.Save();

                //ctl.Globe.Layers.Remove(layer);

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #13
0
        private string GetBubbleInfo(GSOFeature feature,string width,string height)
        {
            string str = "<!-- <BALLOON><CONTENT_CX>" + width + "</CONTENT_CX><CONTENT_CY>"+ height +"</CONTENT_CY><CONTENT_TYPE>text</CONTENT_TYPE><SHOW_MODE>balloonex</SHOW_MODE>-->";

            str += "<html><body><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"width:100%;background:#FFFFFF none repeat scroll 0 0;border-collapse:collapse;font-family:\"Lucida Sans Unicode\",\"Lucida Grande\",Sans-Serif;font-size:10px;text-align:center;\" >";

            for (int j = 0; j < listFields.CheckedItems.Count; j++)
            {
                GSOFieldDefn field1 = (GSOFieldDefn)feature.GetFieldDefn(listFields.CheckedItems[j].ToString());

                string value1 = feature.GetFieldAsString(listFields.CheckedItems[(j)].ToString());

                str += "<tr><td style=\"font-size:10pt;border:1px solid #CCCCCC;color:#666699;padding:2px 2px; background-color:#E7F3FB\"><center>" +
                    field1.Name +
                    "</center></td><td style=\"font-size:10pt;border:1px solid #CCCCCC;color:#666699;padding:2px 2px;\"><center>" +
                    value1 + "</center></td></tr>";
            }

            str += "</table></body></html>";
            return str;
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("管线模型文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("管线模型文件已存在!", "提示");
                    return;
                }

                GSOLayer sourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer layer = ctl.Globe.Layers.Add(txtModelLayer.Text);
                lgdFilePath = txtModelLayer.Text;
                if (layer != null)
                {
                    GSOFeatures features = sourceLayer.GetAllFeatures();
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double       width = 0;
                        GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbWidth.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp   = f.GetFieldAsString(cmbWidth.SelectedItem.ToString());
                            double outNum = 0;
                            bool   num    = double.TryParse(temp, out outNum);
                            if (num)
                            {
                                width = outNum;
                            }
                        }
                        else if (field.Type == EnumFieldType.Double)
                        {
                            width = f.GetFieldAsDouble(cmbWidth.SelectedItem.ToString());
                        }


                        double height = 0;
                        field = (GSOFieldDefn)(f.GetFieldDefn(cmbHeight.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp   = f.GetFieldAsString(cmbHeight.SelectedItem.ToString());
                            double outNum = 0;
                            bool   num    = double.TryParse(temp, out outNum);
                            if (num)
                            {
                                height = outNum;
                            }
                        }
                        else if (field.Type == EnumFieldType.Double)
                        {
                            height = f.GetFieldAsDouble(cmbHeight.SelectedItem.ToString());
                        }

                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        if (width == 0 || height == 0)
                        {
                            message += "ID为" + f.ID + "的对象的沟宽或者沟高字段的值为0 \n";
                            continue;
                        }
                        GSOPoint3ds sectionpts = new GSOPoint3ds();
                        sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                        sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));

                        style.SetSectionPoints(sectionpts);
                        style.IsClosed = false;
                        style.SetAnchorByAlign(EnumAlign.BottomCenter);

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            message += "ID为" + f.ID + "的对象不是线对象 \n";
                            continue;
                        }
                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

                        if (chkDeep.Checked)
                        {
                            deep1 = 0 - deep1;
                            deep2 = 0 - deep2;
                        }

                        for (int n = 0; n < line[0].Count; n++)
                        {
                            GSOPoint3d pt3d       = line[0][n];
                            int        pointcount = line[0].Count;
                            double     radio      = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                            pt3d.Z     = deep1 + (deep2 - deep1) * radio;
                            line[0][n] = pt3d;
                        }

                        newFeature.Geometry       = line; // f.Geometry;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;
                        layer.AddFeature(newFeature);
                    }
                    ctl.Refresh();
                    layer.Save();
                    ctl.Globe.Layers.Remove(layer);
                    string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + layer.GetAllFeatures().Length + "个对象!\n";
                    MessageBox.Show(strMessage + message, "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }