private void buttonGetFieldValue_Click(object sender, EventArgs e) { string fieldName = comboBoxFieldNames.Text.Trim(); if (fieldName == "") { MessageBox.Show("请选择字段名称!", "提示"); return; } GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(cmbLayers.Text.Trim()); if (layer == null) { MessageBox.Show("请选择图层", "提示"); return; } if (layer.Type != EnumLayerType.FeatureLayer) { MessageBox.Show("当前选中的图层不是模型图层!", "提示"); return; } GSOFeatureLayer featureLayer = layer as GSOFeatureLayer; List <string> listValues = new List <string>(); for (int i = 0; i < featureLayer.GetAllFeatures().Length; i++) { GSOFeature feature = featureLayer.GetAt(i); if (feature != null) { object value = feature.GetValue(fieldName); if (value == null || value.ToString() == "") { continue; } if (listValues.Contains(value.ToString()) == false) { listValues.Add(value.ToString()); } } } listViewFieldValues.Items.Clear(); if (listValues.Count <= 0) { MessageBox.Show("没有找到不为空的字段值!", "提示"); return; } for (int i = 0; i < listValues.Count; i++) { listViewFieldValues.Items.Add(listValues[i]); } }
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; } }