private void TOC_LabelLayer(ILayer pLayer) { if (pLayer == null) { return; } if (!(pLayer is IFeatureLayer)) { return; } IGeoFeatureLayer pGeoFeaturelayer = (IGeoFeatureLayer)pLayer; bool boolKG = pGeoFeaturelayer.DisplayAnnotation; m_pMainForm.m_TM_LableLayer.Checked = !boolKG; if (m_pMainForm.m_TM_LableLayer.Checked == true) { //Select Field Name from Current Layers FrmSelectField frm = new FrmSelectField((IFeatureLayer)pLayer, "name"); string sFieldName = "NAME"; if (frm.ShowDialog() == DialogResult.Cancel) { return; } sFieldName = frm.strDefFieldName; GeoBaseLib.InitLabel(pGeoFeaturelayer, sFieldName); pGeoFeaturelayer.DisplayAnnotation = true; } else { pGeoFeaturelayer.DisplayAnnotation = false; } m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, m_pMapControl.Extent); }
public bool Create(string sLayerName, esriGeometryType nGeometryType, baseFieldList pNewFields, bool bAddIntoMapContol = false) { if (m_axMapControl == null) { return(false); } m_nGeometryType = nGeometryType; m_sMapPath = Global.GetWorkspacePath(); m_sLayerName = sLayerName; bool bFileExisted = System.IO.File.Exists(m_sMapPath + "\\" + m_sLayerName + ".shp"); if (bFileExisted && MessageBox.Show("The file is already existed, and do you want to create new one?", "Select one", MessageBoxButtons.YesNo) == DialogResult.Yes) { System.IO.File.Delete(m_sMapPath + "\\" + m_sLayerName + ".shp"); System.IO.File.Delete(m_sMapPath + "\\" + m_sLayerName + ".dbf"); System.IO.File.Delete(m_sMapPath + "\\" + m_sLayerName + ".shx"); GeoBaseLib.RemoveLayer(m_axMapControl, m_sLayerName); } IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFWS = pWorkspaceFactory.OpenFromFile(m_sMapPath, 0) as IFeatureWorkspace; m_pFeatureLayer = new FeatureLayerClass(); //If file existed, directly load if (System.IO.File.Exists(m_sMapPath + "\\" + m_sLayerName + ".shp")) { m_pFeatureLayer.FeatureClass = pFWS.OpenFeatureClass(m_sLayerName); m_pFeatureLayer.Name = m_pFeatureLayer.FeatureClass.AliasName; if (bAddIntoMapContol && !GeoBaseLib.IsLayerExisted(m_axMapControl, m_sLayerName)) { m_axMapControl.AddLayer(m_pFeatureLayer); m_axMapControl.Refresh(); } return(true); } try { IFields pFields = CreateFields(pNewFields); //Create feature class m_pFeatureLayer.FeatureClass = pFWS.CreateFeatureClass(m_sLayerName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); m_pFeatureLayer.Name = m_sLayerName; if (bAddIntoMapContol) { m_axMapControl.AddShapeFile(m_sMapPath, m_sLayerName + ".shp"); m_axMapControl.Refresh(); } } catch (Exception exception) { MessageBox.Show("Create \"" + m_sLayerName + "\" shapefile error:" + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } return(true); }
public void copy_Value(IFeature pFromFeature) { if (pFromFeature == null || m_pCurFeature == null) { return; } for (int i = 0; i < pFromFeature.Fields.FieldCount; i++) { IField pFromField = pFromFeature.Fields.get_Field(i); if (GeoBaseLib.IsSysField(pFromField.Name)) { continue; } int index = m_pFeatureLayer.FeatureClass.Fields.FindField(pFromField.Name); if (index != -1) { object value = pFromFeature.get_Value(i); m_pCurFeature.set_Value(index, value); } } }
public static baseFieldList get_Fields(IFeature pFeature) { baseFieldList pFields = new baseFieldList(); if (pFeature == null) { return(null); } for (int i = 0; i < pFeature.Fields.FieldCount; i++) { IField pField = pFeature.Fields.get_Field(i); if (GeoBaseLib.IsSysField(pField.Name)) { continue; } baseField smField = new baseField(); smField.strFieldName = pField.Name; smField.strFieldAliasName = pField.Name; smField.ftFieldType = pField.Type; smField.nFieldLen = pField.Length; pFields.Add(smField); } return(pFields); }