4

I'm trying to create a point IFeatureClass, but my code doesn't work.

Public Function CreatePointFeatureClass(ByVal featureClassName As String, _
                                         ByVal featureWorkspace As IFeatureWorkspace) As IFeatureClass

    ' Instantiate a feature class description to get the required fields.
    Dim fcDescription As IFeatureClassDescription = New FeatureClassDescriptionClass()
    Dim ocDescription As IObjectClassDescription = CType(fcDescription, IObjectClassDescription)

    Dim fields As IFields = New FieldsClass
    Dim fieldsEdit As IFieldsEdit = CType(fields, IFieldsEdit)
    Dim fieldUserDefined As IField = New FieldClass
    Dim fieldEdit As IFieldEdit = CType(fieldUserDefined, IFieldEdit)

    ' Set up geometry definition for the Shape field.
    ' You do not have to set the spatial reference, as it is inherited from the feature dataset.
    Dim geometryDef As IGeometryDef = New GeometryDefClass
    Dim geometryDefEdit As IGeometryDefEdit = CType(geometryDef, IGeometryDefEdit)

    ' By setting the grid size to 0, you are allowing ArcGIS to determine the appropriate grid sizes for the feature class. 
    ' If in a personal geodatabase, the grid size is 1,000. If in a file or ArcSDE geodatabase, the grid size
    ' is based on the initial loading or inserting of features.
    geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint

    ' Set standard field properties.
    fieldEdit.Name_2 = "SHAPE"
    fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry
    fieldEdit.GeometryDef_2 = geometryDefEdit
    fieldEdit.IsNullable_2 = True
    fieldEdit.Required_2 = True
    fieldsEdit.AddField(fieldUserDefined)


    ' Add a X Double field to the required fields.
    Dim field1 As IField = New FieldClass()
    Dim fieldEdit1 As IFieldEdit = CType(field1, IFieldEdit)
    fieldEdit1.Name_2 = "X"
    fieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble
    fieldsEdit.AddField(field1)

    ' Add a Y Double field to the required fields.
    Dim field2 As IField = New FieldClass()
    Dim fieldEdit2 As IFieldEdit = CType(field2, IFieldEdit)
    fieldEdit2.Name_2 = "Y"
    fieldEdit2.Type_2 = esriFieldType.esriFieldTypeDouble
    fieldsEdit.AddField(field2)

    ' Add a Elevation Double field to the required fields.
    Dim field3 As IField = New FieldClass()
    Dim fieldEdit3 As IFieldEdit = CType(field3, IFieldEdit)
    fieldEdit3.Name_2 = "Elevation"
    fieldEdit3.Type_2 = esriFieldType.esriFieldTypeDouble
    fieldsEdit.AddField(field3)




    ' Use IFieldChecker to create a validated fields collection.
    Dim fieldChecker As IFieldChecker = New FieldCheckerClass()
    Dim enumFieldError As IEnumFieldError = Nothing
    Dim validatedFields As IFields = Nothing
    fieldChecker.ValidateWorkspace = CType(featureWorkspace, IWorkspace)
    fieldChecker.Validate(fields, enumFieldError, validatedFields)

    ' The enumFieldError enumerator can be inspected at this point to determine
    ' which fields were modified during validation.
    ' Create the feature class.
    Dim featureClass As IFeatureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, _
                                    ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, _
                                    "SHAPE", "")

    Return featureClass

End Function
2
  • 1
    Try not to scare away the n00bs! It's definitely down-vote worthy, but he joined today. I suggest commenting first and give him a shot to redeem the question before chucking down-votes at the question (maybe a few hours after the next 'last seen' time) . Otherwise he may flee to the Esri forums and never look back! Commented Jul 18, 2011 at 23:40
  • if you have some sources that can helps me , please write down here.
    – hvaezi
    Commented Jul 19, 2011 at 9:04

3 Answers 3

3

The documentation says you have to add a valid spatial reference to your geometryDefEdit object.

Add these lines after the creation of your geometryDef object (taken from http://resources.esri.com/help/9.3/ArcGISengine/ArcObjects/esriGeodatabase/IFeatureWorkspace.CreateFeatureClass_Example.htm)

        Dim spatialReferenceFactory As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 = New     ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass()
        Dim spatialReference As ESRI.ArcGIS.Geometry.ISpatialReference = spatialReferenceFactory.CreateProjectedCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_NAD1983UTM_20N)
        Dim spatialReferenceResolution As ESRI.ArcGIS.Geometry.ISpatialReferenceResolution = CType(spatialReference, ESRI.ArcGIS.Geometry.ISpatialReferenceResolution)
        spatialReferenceResolution.ConstructFromHorizon()
        Dim spatialReferenceTolerance As ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance = CType(spatialReference, ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance)
        spatialReferenceTolerance.SetDefaultXYTolerance()
        geometryDefEdit.SpatialReference_2 = spatialReference
3

Like Goldorak84 said, you're missing a spatial reference.

Might I suggest making a utility method, that's like this. Sorry using C# here.

static public ISpatialReference GetSpatialReference()
{

ISpatialReference spatialReference;

ISpatialReferenceFactory3 spatialReferenceFactory = 
new SpatialReferenceEnvironmentClass();
spatialReference = spatialReferenceFactory.CreateSpatialReference((int)esriRSGeoCSType.esriSRGeoCS_WSG1984);

return spatialReference;

}

Obviously you'll want to set your resolution and tolerance in there as well.

1
0

Minor Typo ,Replace esriSRGeoCSType.esriSRGeoCS_WGS1984 with esriRSGeoCSType.esriSRGeoCS_WSG1984

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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