private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { int selectIndex = comboBox1.SelectedIndex; if (selectIndex >= 0) { layer = mGlobeControl.Globe.Layers.GetLayerByCaption(comboBox1.SelectedItem.ToString()); if (layer != null) { features = layer.GetAllFeatures(); if (features.Length > 0) { GSOFeature feature = features[0]; if (feature.GetFieldCount() > 0) { for (int i = 0; i < feature.GetFieldCount(); i++) { GSOFieldDefn defn = (GSOFieldDefn)feature.GetFieldDefn(i); listBox1.Items.Add(defn.Name); } } } } } }
private void FrmAtrributeMapping_Load(object sender, EventArgs e) { this.MaximizeBox = false; if (m_feature != null) { try { //ArrayList list = new ArrayList(); dt = new DataTable(m_feature.Name); DataColumn dcName = new DataColumn("Name", typeof(string)); DataColumn dcValue = new DataColumn("Value", typeof(string)); dt.Columns.Add(dcName); dt.Columns.Add(dcValue); dt.Columns["Name"].ReadOnly = true; for (int j = 0; j < m_feature.GetFieldCount(); j++) { DataRow dr = dt.NewRow(); GSOFieldDefn field = (GSOFieldDefn)m_feature.GetFieldDefn(j); if (field != null) { dr["Name"] = field.Name; object obj = m_feature.GetValue(j); if (obj != null) { dr["Value"] = obj.ToString(); DateTime date = DateTime.Now.Date; bool isDatetime = DateTime.TryParse(obj.ToString(), out date); if (isDatetime) { dr["Value"] = date.ToShortDateString(); list.Add(j); } } } dt.Rows.Add(dr); } dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "属性名"; dataGridView1.Columns[1].HeaderText = "属性值"; //for (int i = 0; i < list.Count; i++) //{ // int index = int.Parse(list[i].ToString()); // dataGridView1[1,index].ReadOnly = true; //} } catch (System.Exception exp) { Log.PublishTxt(exp); } } }
private void CtrlLineFieldsValuePage_Load(object sender, EventArgs e) { if (m_feature != null) { try { dt = new DataTable(m_feature.Name); DataColumn dcName = new DataColumn("属性名", typeof(string)); DataColumn dcValue = new DataColumn("属性值", typeof(string)); dt.Columns.Add(dcName); dt.Columns.Add(dcValue); dt.Columns["属性名"].ReadOnly = true; if (m_feature.GetFieldCount() > 0) { for (int j = 0; j < m_feature.GetFieldCount(); j++) { DataRow dr = dt.NewRow(); GSOFieldDefn field = (GSOFieldDefn)m_feature.GetFieldDefn(j); if (field != null) { dr["属性名"] = field.Name; object obj = m_feature.GetValue(j); if (obj != null) { dr["属性值"] = obj.ToString(); if (obj.GetType() == typeof(DateTime)) { DateTime date = DateTime.Parse(obj.ToString()); dr["属性值"] = date.ToShortDateString(); } } } dt.Rows.Add(dr); } } dataGridView1.DataSource = dt; dataGridView1.ReadOnly = !mlayer.Editable; dataGridView1.Columns[0].Width = 100; dataGridView1.Columns[1].Width = 200; } catch (System.Exception exp) { Log.PublishTxt(exp); } } }
//datagrid绑定数据 public void SetDataTable(GSOFeatures feats) { if (feats.Length == 0) { MessageBox.Show("查询结果为空!", "提示"); return; } GSOFeature feat = feats[0]; try { DataTable table = new DataTable(); for (int i = 0; i < feat.GetFieldCount(); i++) { GSOFieldDefn field = (GSOFieldDefn)feat.GetFieldDefn(i); table.Columns.Add(field.Name); } for (int i = 0; i < feats.Length; i++) { GSOFeature f = feats[i]; DataRow row = table.NewRow(); for (int j = 0; j < feat.GetFieldCount(); j++) { GSOFieldDefn field = (GSOFieldDefn)feat.GetFieldDefn(j); row[j] = f.GetValue(field.Name); } table.Rows.Add(row); } dataGridView1.DataSource = table; for (int i = 0; i < feats.Length; i++) { GSOFeature f = feats[i]; if (dataGridView1.Rows.Count > i) { dataGridView1.Rows[i].Tag = f; } } } catch (System.Exception exp) { Log.PublishTxt(exp); MessageBox.Show(exp.Message, "提示"); } }
private void SetFields(GSOFeature oldfeat, GSOFeature newFeature) { for (int i = 0; i < oldfeat.GetFieldCount(); i++) { GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(oldfeat.GetFieldDefn(i)); object fieldvalue = oldfeat.GetValue(fielddef.Name); if (fieldvalue == null) { continue; } newFeature.SetValue(fielddef.Name, fieldvalue); } }
private void buttonOk_Click(object sender, EventArgs e) { if (m_feature != null) { for (int j = 0; j < m_feature.GetFieldCount(); j++) { GSOFieldDefn field = (GSOFieldDefn)m_feature.GetFieldDefn(j); if (field != null) { m_feature.SetValue(CtrlLineFieldsValuePage.dt.Rows[j][0].ToString(), CtrlLineFieldsValuePage.dt.Rows[j][1].ToString()); } } } this.Close(); }
private void FrmDeleteFieldFromLayer_Load(object sender, EventArgs e) { if (layer != null) { textBoxLayerCaption.Text = layer.Caption.Trim(); if (layer.GetAllFeatures().Length > 0) { GSOFeature feature = layer.GetAt(0); if (feature != null) { for (int i = 0; i < feature.GetFieldCount(); i++) { GSOFieldDefn field = (GSOFieldDefn)feature.GetFieldDefn(i); if (field != null) { listViewFields.Items.Add(field.Name.Trim()); } } } } } }
private void FrmShowValveInformation_Load(object sender, EventArgs e) { labelValveInformation.Text = "共匹配了" + valveCount + "个阀门!";//localhost_casic_pipe_test if (features != null) { labelValveInformation.Text += "共有" + features.Length + "个阀门没有匹配!"; for (int i = 0; i < features.Length; i++) { GSOFeature f = features[i]; if (f != null) { for (int j = 0; j < f.GetFieldCount(); j++) { GSOFieldDefn fieldDefn = (GSOFieldDefn)f.GetFieldDefn(j); if (fieldDefn != null) { dataGridView1.Columns.Add(fieldDefn.Name, fieldDefn.Name); } } break; } } for (int i = 0; i < features.Length; i++) { GSOFeature f = features[i]; if (f != null) { int rowIndex = dataGridView1.Rows.Add(); for (int j = 0; j < f.GetFieldCount(); j++) { dataGridView1.Rows[rowIndex].Cells[j].Value = f.GetValue(j); } } } } }
public void SetTabControl() { if (m_Feature != null) { tabControlMain.TabPages.Clear(); textBoxName.Text = m_Feature.Name; checkBox1.Checked = m_Feature.Visible; if (m_Feature.Geometry != null) { // 属性信息页面 if (m_Feature.Geometry.Type != EnumGeometryType.GeoPolyline3D) { m_CtrlFeatureAttribute = new CtrlFeatureAttribute(m_Feature, m_GlobeControl); AddNewCtrlPage(m_CtrlFeatureAttribute, "tabAttribute", "属性信息"); } switch (m_Feature.Geometry.Type) { case EnumGeometryType.GeoParticle: { InsertNewCtrlPage(0, new CtrlParticleParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); } break; case EnumGeometryType.GeoMarker: case EnumGeometryType.GeoDynamicMarker: { InsertNewCtrlPage(0, new CtrlMarkerTextPage(m_Feature.Geometry, m_GlobeControl), "tabMarkerText", "标注内容"); } break; case EnumGeometryType.GeoModel: { m_CtrlModePathPage = new CtrlModelPathPage(m_Feature, m_GlobeControl); InsertNewCtrlPage(0, m_CtrlModePathPage, "tabModelPath", "模型路径"); } break; case EnumGeometryType.GeoFountain: { InsertNewCtrlPage(0, new CtrlFountainParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); } break; case EnumGeometryType.GeoWater: { InsertNewCtrlPage(0, new FrmWaterParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); } break; case EnumGeometryType.GeoSphereEntity: { InsertNewCtrlPage(0, new CtrlSphereEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); } break; case EnumGeometryType.GeoBoxEntity: { InsertNewCtrlPage(0, new CtrlBoxEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "长方体"; } break; case EnumGeometryType.GeoCylinderEntity: { InsertNewCtrlPage(0, new CtrlCylinderEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "柱"; } break; case EnumGeometryType.GeoFrustumEntity: { InsertNewCtrlPage(0, new CtrlFrustumEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "台"; } break; case EnumGeometryType.GeoEllipsoidEntity: { InsertNewCtrlPage(0, new CtrlEllipsoidEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "椭球"; } break; case EnumGeometryType.GeoEllipCylinderEntity: { InsertNewCtrlPage(0, new CtrlEllipCylinderEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "椭圆柱"; } break; case EnumGeometryType.GeoEllipFrustumEntity: { InsertNewCtrlPage(0, new CtrlEllipFrustumEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "椭圆台"; } break; case EnumGeometryType.GeoRangeEllipsoidEntity: { InsertNewCtrlPage(0, new CtrlRangeEllipsoidEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "缺口椭球"; } break; case EnumGeometryType.GeoRangeEllipCylinderEntity: { InsertNewCtrlPage(0, new CtrlRangeEllipCylinderEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "缺口椭圆柱"; } break; case EnumGeometryType.GeoRangeEllipFrustumEntity: { InsertNewCtrlPage(0, new CtrlRangeEllipFrustumEntityParamPage(m_Feature.Geometry, m_GlobeControl), "tabParam", "参数"); this.Text = "缺口椭圆台"; } break; } // 空间信息页面 if (m_Feature.Geometry.IsEntity) { CtrlEntitySpaceInfo curCtrlEntitySpaceInfo = new CtrlEntitySpaceInfo(m_Feature, m_GlobeControl); AddNewCtrlPage(curCtrlEntitySpaceInfo, "tabSpaceInfo", "空间信息"); if (m_CtrlModePathPage != null) { // 这里要设置关联一下,否则模型设置路径后里面的空间信息参数不能跟着更新 m_CtrlModePathPage.m_SpaceCtrl = curCtrlEntitySpaceInfo; } AddNewCtrlPage(new CtrlEntityStylePage(m_Feature, m_GlobeControl), "tabStyle", "风格"); } else { switch (m_Feature.Geometry.Type) { case EnumGeometryType.GeoPoint3D: case EnumGeometryType.GeoDynamicPoint3D: case EnumGeometryType.GeoMarker: case EnumGeometryType.GeoDynamicMarker: { AddNewCtrlPage(new CtrlPoint3DSpaceInfo(m_Feature.Geometry, m_GlobeControl), "tabSpaceInfo", "空间信息"); if (m_Feature.Geometry.Type == EnumGeometryType.GeoMarker || m_Feature.Geometry.Type == EnumGeometryType.GeoDynamicMarker) { AddNewCtrlPage(new CtrlMarkerStylePage(m_Feature.Geometry, m_GlobeControl), "tabStyle", "风格"); } } break; case EnumGeometryType.GeoPolyline3D: { AddNewCtrlPage(new CtrlPolylineSpaceInfo(m_Feature.Geometry, m_Feature, mlayer, m_GlobeControl), "tabSpaceInfo", "空间信息"); AddNewCtrlPage(new CtrlLineStylePage(m_Feature.Geometry, m_Feature, mlayer, m_GlobeControl), "tabStyle", "风格"); if (m_Feature.GetFieldCount() > 0) { AddNewCtrlPage(new CtrlLineFieldsValuePage(m_Feature, mlayer, m_GlobeControl), "tabFieldsValue", "字段值"); } } break; case EnumGeometryType.GeoPolygon3D: case EnumGeometryType.GeoWater: { AddNewCtrlPage(new CtrlPolylineSpaceInfo(m_Feature.Geometry, m_GlobeControl), "tabSpaceInfo", "空间信息"); AddNewCtrlPage(new CtrlPolygonStylePage(m_Feature, m_GlobeControl), "tabStyle", "风格"); AddNewCtrlPage(new CtrlExtrudePage(m_Feature.Geometry, m_GlobeControl), "tabExtrude", "拉伸"); } break; } } if (m_Feature.Geometry.Type != EnumGeometryType.GeoPolyline3D) { m_CtrlGeometryCameraState = new CtrlGeometryCameraState(m_Feature, m_GlobeControl); AddNewCtrlPage(m_CtrlGeometryCameraState, "tabCameraState", "定位参数"); } } } // 设置当前tab页面为第一个 tabControlMain.SelectedIndex = 0; }
private void radioButtonElevatePartFeature_CheckedChanged(object sender, EventArgs e) { if (radioButtonElevatePartFeature.Checked == true) { string layerCaption = cmbLayers.Text.Trim(); if (layerCaption == "") { radioButtonElevateAllFeature.Checked = true; MessageBox.Show("请先选择图层!", "提示"); return; } GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(layerCaption); if (layer == null) { radioButtonElevateAllFeature.Checked = true; MessageBox.Show("请先选择图层!", "提示"); return; } GSOFeatureLayer featureLayer = layer as GSOFeatureLayer; if (featureLayer == null) { radioButtonElevateAllFeature.Checked = true; MessageBox.Show("图层不是矢量图层!", "提示"); return; } if (featureLayer.GetAllFeatures().Length <= 0) { radioButtonElevateAllFeature.Checked = true; MessageBox.Show("图层中的要素个数为0个!", "提示"); return; } for (int i = 0; i < featureLayer.GetAllFeatures().Length; i++) { GSOFeature feature = featureLayer.GetAt(i); if (feature != null) { if (feature.GetFieldCount() <= 0) { radioButtonElevateAllFeature.Checked = true; MessageBox.Show("图层中的字段个数为0个!", "提示"); return; } for (int j = 0; j < feature.GetFieldCount(); j++) { GSOFieldDefn field = (GSOFieldDefn)feature.GetFieldDefn(j); if (field != null) { comboBoxFieldNames.Items.Add(field.Name); } } break; } } radioButtonElevateAllFeature.Checked = false; panel1.Enabled = true; } else { panel1.Enabled = false; radioButtonElevateAllFeature.Checked = true; } }
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 (txtFolder.Text == "") { return; } if (cmbLayer.SelectedIndex < 0) { return; } try { Regex regNum = new Regex("^[0-9]"); DirectoryInfo theFolder = new DirectoryInfo(txtFolder.Text); foreach (FileInfo nextFile in theFolder.GetFiles()) { if (nextFile.Name.ToLower().IndexOf("3ds") > -1 || nextFile.Name.ToLower().IndexOf("gcm") > -1) { files.Add(nextFile.Name); string temp = nextFile.Name.Substring(nextFile.Name.IndexOf("-") + 1, nextFile.Name.LastIndexOf(".") - nextFile.Name.IndexOf("-") - 1); string modeltype = nextFile.Name.Substring(0, nextFile.Name.IndexOf("-")); modeltypes.Add(modeltype); double Num; bool isNum = double.TryParse(temp, out Num); if (isNum) { deeps.Add(Convert.ToDouble(temp)); } } } GSOFeatureDataset featdataset = CreateDBFeatureDataset(txtLayerName.Text); featdataset.Open(); GSOLayer shpLayer = globeControl1.Globe.Layers[cmbLayer.SelectedIndex]; if (shpLayer == null) { return; } GSOFeatures features = shpLayer.GetAllFeatures(true); for (int j = 0; j < features.Length; j++) { GSOFeature f = features[j]; GSOGeoPoint3D shpPoint = f.Geometry as GSOGeoPoint3D; double x; double y; double rotateAngle = 0; rotateAngle = (double)f.GetValue(combAngle.SelectedItem.ToString()); string currentModelType = f.GetValue(combCode.SelectedItem.ToString()).ToString(); double z = Convert.ToDouble(txtUpGround.Text); double deep = f.GetFieldAsDouble(combDeep.SelectedItem.ToString()); int index = -1; double diff = double.MaxValue; for (int i = 0; i < deeps.Count; i++) { double tempdeep = Convert.ToDouble(deeps[i]); string modeltype = modeltypes[i].ToString(); if (modeltype != currentModelType) { continue; } if (tempdeep > deep) { double chazhi = tempdeep - deep; if (diff > chazhi) { diff = chazhi; index = i; } } } if (index < 0) { continue; } 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.Align = EnumEntityAlign.TopCenter; //接口已修复作用 model.AltitudeMode = EnumAltitudeMode.RelativeToGround; model.RotateZ = 0 - rotateAngle * 180 / Math.PI + 90; model.FilePath = txtFolder.Text + "\\" + files[index]; model.Name = f.GetValue(combModelName.SelectedItem.ToString()).ToString(); feature.Name = f.GetValue(combModelName.SelectedItem.ToString()).ToString(); feature.Geometry = model; for (int i = 0; i < feature.GetFieldCount(); i++) { GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i)); //if (!en_cns.ContainsKey(fielddef.Name)) // continue; // object fieldvalue = convertFieldValue(fielddef.Name, f.GetValue(fielddef.Name)); if (fielddef == null) { continue; } feature.SetValue(fielddef.Name, f.GetValue(fielddef.Name)); } featdataset.AddFeature(feature); } featdataset.Save(); this.Close(); } catch (Exception 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); } }
public void SetDataTable() { this.Shown += new EventHandler(Frm_TableAttribute_Shown); GSOFeatureLayer pFeatureLayer = geoLayer as GSOFeatureLayer; GSOFeatureDataset pFeatureDataset = pFeatureLayer.Dataset as GSOFeatureDataset; if (pFeatureLayer == null || pFeatureDataset == null) { MessageBox.Show("该数据不是属性数据,属性表为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error); isShow = false; return; } else { GSOFeatures feats = m_features;// pFeatureLayer.GetAllFeatures(); GSOFeature feat = feats[0]; countLog = 0; GetReallyFeature(feats); try { dataGridView1.Columns.Clear(); dataGridView1.Rows.Clear(); for (int j = 0; j < pFeatureDataset.FieldCount; j++) { GSOFieldAttr field = pFeatureDataset.GetField(j); dataGridView1.Columns.Add(field.Name, field.Name); } for (int i = 0; i < feats.Length; i++) { feat = feats[i]; if (feat == null) { continue; } int rowIndex = dataGridView1.Rows.Add(); dataGridView1.Rows[rowIndex].Tag = feat; for (int j = 0; j < feat.GetFieldCount(); j++) { GSOFieldDefn field = (GSOFieldDefn)feat.GetFieldDefn(j); object fieldValue = feat.GetValue(j); if (fieldValue != null) { dataGridView1.Rows[rowIndex].Cells[j].Value = fieldValue.ToString(); } } } dataGridView1.ReadOnly = !pFeatureLayer.Editable; this.编辑ToolStripMenuItem.BackColor = geoLayer.Editable == true ? Color.Orange : Color.Transparent; if (statusStrip1.Items.Count > 0) { if (dataGridView1.Rows.Count >= countLog) { statusStrip1.Items[0].Text = " 共有 " + dataGridView1.Rows.Count + " 条记录"; } else { statusStrip1.Items[0].Text = " 共有 " + countLog + " 条记录"; } } } catch (System.Exception exp) { Log.PublishTxt(exp); if (statusStrip1.Items.Count > 0) { statusStrip1.Items[0].Text = " 共有 " + 0 + " 条记录"; } } } }
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 (textBoxModelFolder.Text == "") { return; } if (comboBoxShpLayerList.SelectedIndex < 0) { return; } try { Regex regNum = new Regex("^[0-9]"); DirectoryInfo theFolder = new DirectoryInfo(textBoxModelFolder.Text); foreach (FileInfo nextFile in theFolder.GetFiles()) { if (nextFile.Name.ToLower().IndexOf("3ds") > -1 || nextFile.Name.ToLower().IndexOf("gcm") > -1) { files.Add(nextFile.Name); string temp = nextFile.Name.Substring(nextFile.Name.IndexOf("-") + 1, nextFile.Name.LastIndexOf(".") - nextFile.Name.IndexOf("-") - 1); string modeltype = nextFile.Name.Substring(0, nextFile.Name.IndexOf("-")); modeltypes.Add(modeltype); double Num; bool isNum = double.TryParse(temp, out Num); if (isNum) { deeps.Add(Convert.ToDouble(temp)); } } } GSODataset dataset = ds.GetDatasetByName(textBoxNewLayerName.Text.Trim()); GSOFeatureDataset featdataset; if (dataset != null) { DialogResult result = MessageBox.Show("工井图层名称在数据库中已存在!是否向该表追加", "提示", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } else if (result == DialogResult.Yes) { featdataset = dataset as GSOFeatureDataset; } else { return; } } else { featdataset = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim()); } if (featdataset == null) { return; } featdataset.Open(); GSOLayer shpLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim()); 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 x; double y; double rotateAngle = 0; string currentModelType = f.GetValue(combCode.SelectedItem.ToString()).ToString(); double z = Convert.ToDouble(txtUpGround.Text); double deep = f.GetFieldAsDouble(combDeep.SelectedItem.ToString()); int index = -1; double diff = double.MaxValue; for (int i = 0; i < deeps.Count; i++) { double tempdeep = Convert.ToDouble(deeps[i]); string modeltype = modeltypes[i].ToString(); if (modeltype != currentModelType) { continue; } if (tempdeep > deep) { double chazhi = tempdeep - deep; if (diff > chazhi) { diff = chazhi; index = i; } } } if (index < 0) { message += "ID为" + f.ID + "的对象没有找到符合井深的工井模型\r\n"; continue; } 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.Align = EnumEntityAlign.TopCenter; //接口已修复作用 model.AltitudeMode = EnumAltitudeMode.RelativeToGround; model.RotateZ = 0 - rotateAngle * 180 / Math.PI + 90; model.FilePath = textBoxModelFolder.Text + "\\" + files[index]; 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 (!gj_cns.ContainsKey(fielddef.Name)) { continue; } object obu = f.GetValue(fielddef.Name); if (obu != null) { string fieldName = gj_cns.ContainsKey(fielddef.Name) == true ? gj_cns[fielddef.Name].ToString() : fielddef.Name; feature.SetValue(fieldName, obu); } } featdataset.AddFeature(feature); } featdataset.Save(); featdataset.Close(); 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 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 SetFields(GSOFeature oldfeat, GSOFeature newFeature) { for (int i = 0; i < oldfeat.GetFieldCount(); i++) { GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(oldfeat.GetFieldDefn(i)); object fieldvalue = oldfeat.GetValue(fielddef.Name); if (fieldvalue == null) continue; newFeature.SetValue(fielddef.Name, fieldvalue); } }