Replace the following linegeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryAny;withgeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;Also have a look at the following linkhttp://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/GeometryType_Property/0025000003qs000000/
Thanks for the reply, I have seen the above mentioned links earlier also and tried to create a new feature class and add a feature into it but was facing issues, Hence I asked for some sample working code if anyone already had. Currently I am getting "No Current Record." Exception when I call CreateFeatureClass method on IFeatureWorkSpace and am unable to resolve the issue. This issue has previously been addressed in the forum which is left Unanswered .. http://forums.esri.com/Thread.asp?c=159&f=1707&t=225079 Anyways I am pasting my code, Kindly help on this. I am Stuck up and badly in need of help 😞 public void DrawPolygon(ESRI.ArcGIS.Carto.IActiveView activeView) { if (activeView == null) { return; } ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay; // Constant screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass(); rgbColor.Red = 255; ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass(); simpleFillSymbol.Color = color; ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass(); ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol); screenDisplay.SetSymbol(symbol); screenDisplay.DrawPolygon(geometry); screenDisplay.FinishDrawing(); IWorkspace pWorkSpace = CreateAccessWorkspace(@J:\GIS\DGN\); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)pWorkSpace; // createFeatureDataset(); IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)featureWorkspace; workspaceEdit.StartEditing(false); workspaceEdit.StartEditOperation(); IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; IField oidField = new FieldClass(); IFieldEdit oidFieldEdit = (IFieldEdit)oidField; oidFieldEdit.Name_2 = "OID"; oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; fieldsEdit.AddField(oidField); IGeometryDef geometryDef = new GeometryDefClass(); IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryAny; ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference spatialReference = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_17N); ISpatialReferenceResolution spatialReferenceResolution = (ISpatialReferenceResolution)spatialReference; spatialReferenceResolution.ConstructFromHorizon(); spatialReferenceResolution.SetDefaultXYResolution(); ISpatialReferenceTolerance spatialReferenceTolerance = (ISpatialReferenceTolerance)spatialReference; spatialReferenceTolerance.SetDefaultXYTolerance(); geometryDefEdit.SpatialReference_2 = spatialReference; IField geometryField = new FieldClass(); IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField; geometryFieldEdit.Name_2 = "Shape"; geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; geometryFieldEdit.GeometryDef_2 = geometryDef; fieldsEdit.AddField(geometryField); IField nameField = new FieldClass(); IFieldEdit nameFieldEdit = (IFieldEdit)nameField; nameFieldEdit.Name_2 = "Name"; nameFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; nameFieldEdit.Length_2 = 20; fieldsEdit.AddField(nameField); IFieldChecker fieldChecker = new FieldCheckerClass(); IEnumFieldError enumFieldError = null; IFields validatedFields = null; fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); // "NO CURRENT RECORD" EXCEPTION HERE IFeatureClass featureClass = featureWorkspace.CreateFeatureClass("FC007", validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); IFeatureClass pFeatureClass = featureClass; featureWorkspace.OpenFeatureClass(pFeatureClass.AliasName); IFeature feature = pFeatureClass.CreateFeature(); feature.Shape = geometry; int contractorFieldIndex = pFeatureClass.FindField("Name"); feature.set_Value(contractorFieldIndex, "Krishna"); feature.Store(); workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureClass; pFeatureLayer.Name = pFeatureClass.AliasName; axMapControl1.AddLayer(pFeatureLayer as ILayer); } Thanks and Regards, Pavan
Below are the samples to create feature class and feature http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0049000000pz000000http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000049v000000
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.