I have been programming in C# a small code for:1) create a polyline Featureclass in a GDB, 2)put that in the map view (ArcMap 10.2) and finally 3) edit that feature using a button or tool...Well I have tried to program it using AddInns controls, but I faced the trouble at the time to edit the feature; I switch to use "Extending ArcObjects" now I can create the feature in my local GDB easily, but at the momento to put the Feature into the map I can not do it; the code is as follows:
GLB.nombre = txtNombre.Text;//definig the name from a text box in a regular form....IWorkspaceFactory pWorkSpaceFactory = new FileGDBWorkspaceFactoryClass();IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)pWorkSpaceFactory.OpenFromFile(@"C:\INFO_2015\ANH_GDB.gdb", 0);IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset("Temp");IFeatureClass featureClass;UID CLSID = new UIDClass();UID CLSEXT = null;CLSID.Value = "esriGeoDatabase.Feature";IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();IGeometryDef pGeoDefL = new GeometryDefClass();var pGeoDefEditL = (IGeometryDefEdit)pGeoDefL;pGeoDefEditL.GeometryType_2 = esriGeometryType.esriGeometryPolyline;//here I define the fields of the DB.......IFields fields = new FieldsClass();fields = objectClassDescription.RequiredFields;IFieldsEdit fieldsEdit = (IFieldsEdit)fields; // Explicit CastfieldsEdit.FieldCount_2 = 3;// ID FieldIField oIdFieldL = new FieldClass();var oIdFieldEditL = (IFieldEdit)oIdFieldL; // Explicit CastoIdFieldEditL.Name_2 = "ObjectID";oIdFieldEditL.Type_2 = esriFieldType.esriFieldTypeOID;fieldsEdit.set_Field(0, oIdFieldL);//Entity typeIField shpFieldL = new FieldClass();var shpFieldEditL = (IFieldEdit)shpFieldL; // Explicit CastshpFieldEditL.Name_2 = "Shape";shpFieldEditL.Type_2 = esriFieldType.esriFieldTypeGeometry;shpFieldEditL.GeometryDef_2 = pGeoDefL;fieldsEdit.set_Field(1, shpFieldL);//line lenghtIField longFieldL = new FieldClass();var longFieldEditL = (IFieldEdit)longFieldL;longFieldEditL.Name_2 = "Longitud";longFieldEditL.Type_2 = esriFieldType.esriFieldTypeDouble;fieldsEdit.set_Field(2, longFieldL);// add field to field collectionfields = fieldsEdit; // Explicit CastIFieldChecker fieldChecker = new FieldCheckerClass();IEnumFieldError enumFieldError = null;IFields validatedFields = null;fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;fieldChecker.Validate(fields, out enumFieldError, out validatedFields);featureClass = featureDataset.CreateFeatureClass(GLB.nombre, validatedFields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, "Shape", "");IApplication application;//HERE IS THE ERROR!!!!!!!!IMxDocument mxDocument = ((IMxDocument)(application.Document)); // Explicit CastIActiveView activeView = mxDocument.ActiveView;IMap map = activeView.FocusMap;IFeatureLayer featureLayer = new FeatureLayerClass();featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(GLB.nombre);featureLayer.Name = GLB.nombre;map.AddLayer(featureLayer);mxDocument.UpdateContents();mxDocument.ActiveView.Refresh();I have been working on it more than three weeks without solution, could anybody give me a hand?
أكثر...
GLB.nombre = txtNombre.Text;//definig the name from a text box in a regular form....IWorkspaceFactory pWorkSpaceFactory = new FileGDBWorkspaceFactoryClass();IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)pWorkSpaceFactory.OpenFromFile(@"C:\INFO_2015\ANH_GDB.gdb", 0);IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset("Temp");IFeatureClass featureClass;UID CLSID = new UIDClass();UID CLSEXT = null;CLSID.Value = "esriGeoDatabase.Feature";IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();IGeometryDef pGeoDefL = new GeometryDefClass();var pGeoDefEditL = (IGeometryDefEdit)pGeoDefL;pGeoDefEditL.GeometryType_2 = esriGeometryType.esriGeometryPolyline;//here I define the fields of the DB.......IFields fields = new FieldsClass();fields = objectClassDescription.RequiredFields;IFieldsEdit fieldsEdit = (IFieldsEdit)fields; // Explicit CastfieldsEdit.FieldCount_2 = 3;// ID FieldIField oIdFieldL = new FieldClass();var oIdFieldEditL = (IFieldEdit)oIdFieldL; // Explicit CastoIdFieldEditL.Name_2 = "ObjectID";oIdFieldEditL.Type_2 = esriFieldType.esriFieldTypeOID;fieldsEdit.set_Field(0, oIdFieldL);//Entity typeIField shpFieldL = new FieldClass();var shpFieldEditL = (IFieldEdit)shpFieldL; // Explicit CastshpFieldEditL.Name_2 = "Shape";shpFieldEditL.Type_2 = esriFieldType.esriFieldTypeGeometry;shpFieldEditL.GeometryDef_2 = pGeoDefL;fieldsEdit.set_Field(1, shpFieldL);//line lenghtIField longFieldL = new FieldClass();var longFieldEditL = (IFieldEdit)longFieldL;longFieldEditL.Name_2 = "Longitud";longFieldEditL.Type_2 = esriFieldType.esriFieldTypeDouble;fieldsEdit.set_Field(2, longFieldL);// add field to field collectionfields = fieldsEdit; // Explicit CastIFieldChecker fieldChecker = new FieldCheckerClass();IEnumFieldError enumFieldError = null;IFields validatedFields = null;fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;fieldChecker.Validate(fields, out enumFieldError, out validatedFields);featureClass = featureDataset.CreateFeatureClass(GLB.nombre, validatedFields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, "Shape", "");IApplication application;//HERE IS THE ERROR!!!!!!!!IMxDocument mxDocument = ((IMxDocument)(application.Document)); // Explicit CastIActiveView activeView = mxDocument.ActiveView;IMap map = activeView.FocusMap;IFeatureLayer featureLayer = new FeatureLayerClass();featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(GLB.nombre);featureLayer.Name = GLB.nombre;map.AddLayer(featureLayer);mxDocument.UpdateContents();mxDocument.ActiveView.Refresh();I have been working on it more than three weeks without solution, could anybody give me a hand?
أكثر...