2

I am writing a fairly simple application to build simple polylines.

I got most of the application working for the most part, but this part is just baffling me to no end and there is nothing I can find about this problem, so maybe I am alone on this.

This is the code:

        IFeatureClassDescription fcDescrip = new FeatureClassDescription() as IFeatureClassDescription;
        IObjectClassDescription objDescrip = (IObjectClassDescription)fcDescrip;

        IFieldsEdit fields = (IFieldsEdit)objDescrip.RequiredFields;

        IFieldEdit geoField = (IFieldEdit)fields.get_Field(fields.FindField(fcDescrip.ShapeFieldName));

        IGeometryDefEdit geoDefField = (IGeometryDefEdit)geoField.GeometryDef;

        geoDefField.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
        geoDefField.SpatialReference_2 = spatialReference;
        geoDefField.HasM_2 = true;
        geoDefField.GridCount_2 = 1;
        geoDefField.set_GridSize(0, 0);

        for (int i = 0; i < fields.FieldCount; i++)
        {
            Console.WriteLine(fields.get_Field(i).Name);
            if (fields.get_Field(i).Name == "SHAPE")
            {
                Console.WriteLine(fields.get_Field(i).GeometryDef.GeometryType);
            }
        }

        UID uidCL = new UID();
        uidCL.Generate();
        UID uidEXT = new UID();
        uidEXT.Generate();

        IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(m_name, (IFields)fields, uidCL, uidEXT, esriFeatureType.esriFTSimple, string.Empty, string.Empty);
        IFeature feature = featureClass.CreateFeature();

It tells me that it doesn't contain a geometry field... even though it clearly does because it tells me what shape it has in there.

I tried using add_Field, but it does the same thing (oddly) if I do. It clearly updates 'fields' since I had it output the type before and after and it changes from polygon to polyline.

I looked at this thread and I tried defining everything, but it still gives the error.

Any ideas?

  • Why are you using the the FeatureClassDescription? It is intended to be used when implementing class extensions. – Petr Krebs Dec 9 '13 at 21:54
1

You need to define ShapeFieldName parameter when you call CreateFeatureClass function. In your case, you'll have to set it to "SHAPE".

Change this:

IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(m_name, (IFields)fields, uidCL, uidEXT, esriFeatureType.esriFTSimple, string.Empty, string.Empty);

to this:

IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(m_name, (IFields)fields, uidCL, uidEXT, esriFeatureType.esriFTSimple, "SHAPE", string.Empty);

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.