4 votos

Problema al crear un punto IFeatureClass

Estoy tratando de crear un punto IFeatureClass, pero mi código no funciona.

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

3voto

pointernil Puntos 136

Como dijo Goldorak84, te falta una referencia espacial.

Podría sugerir hacer un método de utilidad, que es como esto. Lo siento usando C# aquí.

static public ISpatialReference GetSpatialReference()
{

ISpatialReference spatialReference;

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

return spatialReference;

}

Obviamente, también querrás establecer tu resolución y tolerancia allí.

3voto

Goldorak84 Puntos 893

La documentación dice que tienes que añadir una referencia espacial válida a tu objeto geometryDefEdit.

Añade estas líneas después de la creación de tu objeto geometryDef (tomado de 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

0voto

mattlandis Puntos 132

Error tipográfico menor, sustituya esriSRGeoCSType.esriSRGeoCS_WGS1984 por esriRSGeoCSType.esriSRGeoCS_WSG1984

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X