Select to view content in your preferred language

IObjectClassDescription: How to define the shape geometry

676
2
04-07-2010 04:10 AM
Marianne_BilstedWiese
Emerging Contributor
Hi new Forum

I am writing a Class Extension in C# for a Line Feature Class with z-values.

I have constructed the following piece of code from various VB-examples.
It will make a featureclass, but it seems that the geometry definitions in my code will not override the settings in the New Feature Class dialog box in Arc Catalog.

Can I somehow make sure that this feature class will always be a line class?

Another question:
This featureclass will normally reside in a dataset with defined spatial reference.
I have to define a spatial reference anyway, in order to make a Geometry Definition, if I understand it right?

Thanks in advance for any input.


IFields IObjectClassDescription.RequiredFields
{
     get 
        {
            // Get the feature class required fields.
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription ocDescription = (IObjectClassDescription)fcDescription;
            IFields requiredFields = ocDescription.RequiredFields;
            IFieldsEdit requiredFieldsEdit = (IFieldsEdit)requiredFields;

            try
            {
                 //Add objectID Field
                 IField oidField = new FieldClass();
                 IFieldEdit oidFieldEdit = (IFieldEdit)oidField;
                 oidFieldEdit.Name_2 = "OBJECTID";
                 oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                   requiredFieldsEdit.set_Field(0, oidField);

                // Get a spatial reference
                SpatialReferenceEnvironment spatialReferenceEnvironment = new SpatialReferenceEnvironmentClass();
                ISpatialReferenceFactory spatialReferenceFactory = (ISpatialReferenceFactory)spatialReferenceEnvironment;
                ISpatialReference pSR = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile
                        ("Path to Projection File......");

                // Get a Geometry definition
                IGeometryDef pGeomDef = new GeometryDefClass();
                IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;                              
                pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                pGeomDefEdit.AvgNumPoints_2 = 2;
                pGeomDefEdit.HasZ_2 = true;                              
                pGeomDefEdit.SpatialReference_2 = pSR;
                    
                // Add the shape field
                IField shapeField = new FieldClass();
                IFieldEdit shapeFieldEdit = (IFieldEdit)shapeField;
                shapeFieldEdit.Name_2 = "MYSHAPE";
                shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                shapeFieldEdit.GeometryDef_2 = pGeomDef;
                shapeFieldEdit.IsNullable_2 = true;
                shapeFieldEdit.Required_2 = true;
                requiredFieldsEdit.set_Field(1, shapeField);


                // Add a symbol field, required for subtypes
                IField symbolField = new FieldClass();
                IFieldEdit symbolFieldEdit = (IFieldEdit)symbolField;
                symbolFieldEdit.Name_2 = "GM_SYMBOL";
                symbolFieldEdit.Required_2 = true;
                symbolFieldEdit.IsNullable_2 = false;
                symbolFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                requiredFieldsEdit.AddField(symbolField);

            }
            catch (Exception e)
            {
                    MessageBox.Show(e.Message);
            }

            return requiredFields;
       }
}

0 Kudos
2 Replies
SandhyaYamarthi
Emerging Contributor
Hi,
I'm also in the same process of creating class extension using C#.
I followed TimeStamper example provided in ArcGIS 10 samples.
But the one I'm not able to figure it out is how the 'ObjectClassDescription' class is created and implemented in that example.
Can you please let me know how to create objectclassdescription class?

Thanks in advance!
0 Kudos
YvoWeidmann
Deactivated User
Dear all

This is exactly the question I am also looking at. Implementing  IFeatureClassDescription allows you to set the FeatureType. But does someone knows how to define the GeometryType (e.g. Point)?

Looking forward to any hint,
Yvo
0 Kudos