Alberto

Create feature class in File Geodatabase: XY domain error

Discussion created by Alberto on Mar 28, 2011
Hi,
I built a routine to create a point feature class and populate it with data from an Oracle view. The user can choose the output format: shapefile or file geodatabase. If shapefile is selected the procedure runs without any error and the shapefile was correctly created and populated, but if I select File Geodatabase as output format the error "The XY domain on the spatial reference is not set or invalid".
I don't know why it happens: the spatial reference is set. I really appreciate any help. Thanks

Private Sub CreaOutputFeatureClass()

    'On Error Resume Next     

    Set pDoc = ThisDocument         
    Set pMap = pDoc.FocusMap

    ' Open the folder to contain the data as a workspace         
    Dim pFWS As IFeatureWorkspace
    Dim pWorkspaceFactory As IWorkspaceFactory

    If cbo_Format.ListIndex = 0 Then     
            Set pWorkspaceFactory = New FileGDBWorkspaceFactory
    ElseIf cbo_Format.ListIndex = 1 Then
            Set pWorkspaceFactory = New ShapefileWorkspaceFactory
    End If
    Set pFWS = pWorkspaceFactory.OpenFromFile(sOutDir, 0)

    Dim pFields As IFields     
    Dim pFieldsEdit As IFieldsEdit
    Set pFields = New Fields
    Set pFieldsEdit = pFields

    Dim pField As IField     
    Dim pFieldEdit As IFieldEdit

    ' Make the shape field     
    ' it will need a geometry definition, with a spatial reference
    Set pField = New Field
    Set pFieldEdit = pField
    pFieldEdit.Name = "Shape"
    pFieldEdit.Type = esriFieldTypeGeometry

    Dim pGeoCoordSys As IProjectedCoordinateSystem 
    Dim pSpatRefFact As ISpatialReferenceFactory2
    Dim pGeomDef As IGeometryDef
    Dim pGeomDefEdit As IGeometryDefEdit
    Set pGeomDef = New GeometryDef
    Set pGeomDefEdit = pGeomDef
    With pGeomDefEdit
            .GeometryType = esriGeometryPoint
            Set pSpatRefFact = New SpatialReferenceEnvironment
            Set pGeoCoordSys = pSpatRefFact.CreateProjectedCoordinateSystem(32633)       'WGS84 UTM 33 N
            Set .SpatialReference = pGeoCoordSys
    End With
    Set pFieldEdit.GeometryDef = pGeomDef
    pFieldsEdit.AddField pField

    ' add fields     
    Set pField = New Field
    Set pFieldEdit = pField
    With pFieldEdit
            .Name = "STAT_ID"
            .Type = esriFieldTypeInteger
    End With
    pFieldsEdit.AddField pField
    ' other fields...

    Set pFWS = pWorkspaceFactory.OpenFromFile(sOutDir, 0)     
    Dim pFeatClass As IFeatureClass
    Dim pDataset As IDataset
    Dim pFW As IFeatureWorkspace
    Set pFW = pFWS

    'delete it if it already exists     
    If pGxDialog.ReplacingObject = True Then
            Set pFeatClass = pFW.OpenFeatureClass(sOutputName)
            Set pDataset = pFeatClass
            pDataset.Delete
    End If

    ' Create thefeatureclass (****** ERROR IF IT IS STANDALONE FILE GEODATABASE FEATURE CLASS) 
    Set pFeatClass = pFWS.CreateFeatureClass(sOutputName, pFields, Nothing, Nothing, esriFTSimple, "Shape", "")

    'add layer to the map     
    Set pFLayer = New FeatureLayer
    If cbo_Format.ListIndex = 0 Then
            Set pFLayer.FeatureClass = pFWS.OpenFeatureClass(sOutputName)
    ElseIf cbo_Format.ListIndex = 1 Then
            Set pFLayer.FeatureClass = pFWS.OpenFeatureClass(sOutputName & ".shp")
    End If
    pFLayer.Name = pFLayer.FeatureClass.AliasName
    pMap.AddLayer pFLayer
    pFLayer.Visible = True

    pDoc.UpdateContents     

End Sub             


Private Sub cmb_SelOutDir_Click()  

    On Error Resume Next 

    sOutputName = "STAT_" & Replace(cbo_Subcomp.Text, " ", "_")       

    Dim pDataFilter As IGxObjectFilter         
    Dim pFilterCol As IGxObjectFilterCollection

    If cbo_Format.ListIndex = 0 Then     
            Set pDataFilter = New GxFilterFGDBFeatureClasses
    ElseIf cbo_Format.ListIndex = 1 Then
            Set pDataFilter = New GxFilterShapefiles
    End If

    Set pLyrFilter = New GxFilterLayers     
    Set pGxDialog = New GxDialog
    Set pFilterCol = pGxDialog

    If sOutputName <> "" Then     
            pGxDialog.Name = sOutputName
    End If

    pFilterCol.AddFilter pDataFilter, False     
    pGxDialog.Title = "Save Station as..."

    If Not pGxDialog.DoModalSave(0) Then     
            Exit Sub        'Exit if user press Cancel
    End If

    txb_OutDir.Text = pGxDialog.FinalLocation.FullName & "\" & pGxDialog.Name     
    sOutDir = pGxDialog.FinalLocation.FullName

End Sub

Outcomes