4

I have to create a new featureClass in my existing personal GeoDatabase. And save some polylines into this featureClass.

How can i do it?

I need c# code to do this.

Edit: I have a problem during Geometry type featureClass creation. Here the code i'm using:

IFields fields = objectClassDescription.RequiredFields;
ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast
ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.Field();
ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field;
fieldEdit.Name_2 = "Shape";
fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry;
fieldEdit.IsNullable_2 = true;
fieldEdit.AliasName_2 = "SampleShap";
fieldEdit.DefaultValue_2 = "test";
fieldsEdit.AddField(field);
fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit;
ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldChecker();
ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
IFeatureClass featureClass = featureWorkspace.CreateFeatureClass("Test01", validatedFields, null, null, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, "");

I get this error:

The module of database management can't find the table or the input query 'GDB_DataChanges'

How can i solve it?

1

Here is a simple function I wrote to create a shape file with only one attribute "Title".If you change shapefile workspace factory intto personal geodatabase workspace factory it may work for you.

        IWorkspaceFactory ipShapeWF = null;
        IFields2 ipFileds = null;
        IField2 ipField = null;
        IGeometryDef ipGDef = null;

        #region Create shape file if you already have your workspace object skip this block and go to creating fields block
        ipShapeWF = new ShapefileWorkspaceFactoryClass();
        int idx = filePath.LastIndexOf(@"\");
        string strFileName = filePath.Substring(idx + 1);
        string strfilepath = filePath.Replace(strFileName, "");
        ipShapeWS = ipShapeWF.OpenFromFile(strfilepath, 0);
        IFeatureWorkspace ipShapeFW = ipShapeWS as IFeatureWorkspace;
        strFileName = strFileName.ToUpper().Replace(".SHP", "");

        #region Create fields object for shape file
        ipFileds = new FieldsClass();
        IFieldsEdit ipFieldsEdit = ipFileds as IFieldsEdit;

        ipField = new FieldClass();
        IFieldEdit2 ipFieldEdit = ipField as IFieldEdit2;
        ipFieldEdit.Name_2 = "Shape";
        ipFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

        ipGDef = new GeometryDefClass();
        IGeometryDefEdit ipGDefEdit = ipGDef as IGeometryDefEdit;
        if (geomType == esriGeometryType.esriGeometryPoint)
            ipGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
        else
            ipGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;

        ipGDefEdit.SpatialReference_2 = ipSR;
        ipFieldEdit.GeometryDef_2 = ipGDef;
        ipFieldsEdit.AddField(ipField);

        ipField = new FieldClass();
        ipFieldEdit = ipField as IFieldEdit2;
        ipFieldEdit.Name_2 = "Title";
        ipFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
        ipFieldEdit.Length_2 = 254;
        ipFieldsEdit.AddField(ipField);
        #endregion

        try
        {
            IWorkspaceEdit ipShapeWE = (IWorkspaceEdit)ipShapeFW;
            ipShapeWE.StartEditing(true);
            ipShapeWE.StartEditOperation();

            if (geomType == esriGeometryType.esriGeometryPoint)
                ipShapeFC = ipShapeFW.CreateFeatureClass(strFileName, ipFileds, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            else
                ipShapeFC = ipShapeFW.CreateFeatureClass(strFileName, ipFileds, null, null, esriFeatureType.esriFTComplexEdge, "Shape", "");

            ipShapeWE.StopEditOperation();
            ipShapeWE.StopEditing(true);
        }
        catch (COMException cexp2)
        {
    //if any error 
        }
        catch (Exception exp2)
        {
    //if any error 
        }
        #endregion

        #region Clear COM objects from memory
        if (ipShapeWF != null)
            Marshal.ReleaseComObject(ipShapeWF);
        if (ipFileds != null)
            Marshal.ReleaseComObject(ipFileds);
        if (ipField != null)
            Marshal.ReleaseComObject(ipField);
        if (ipGDef != null)
            Marshal.ReleaseComObject(ipGDef);
        #endregion
0

You may use the IFeatureDataConverter.ConvertFeatureClass method. Here is a code snippet:

Converting simple data

  • I have to create a featureclass in my personal gdb, and then load the plylines to this featureclass. How can i do it? – AndryDev Jul 2 '14 at 16:25
  • You will have to write the geometry using an insert cursor, this link talks about it and gives some examples, help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/… – artwork21 Jul 2 '14 at 17:04
  • Thanks, but i have another problem during the creation of featureClass. I edited the main post. If u can check it please. – AndryDev Jul 3 '14 at 10:38
  • Have you defined the source and destination workspace? – artwork21 Jul 3 '14 at 12:06
  • Yes, I'm doing it. If i don't declase any geometry type in the fieldedit it work, but i can't insert my polyline into that featureclass. – AndryDev Jul 3 '14 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.