ArcObjects Library Reference  (GeoDatabase)    

IGeoDatasetSchemaEdit Example

[Visual Basic 6.0]
' This code sample takes a layer and resets its SpatialReference 
' to the OSGB1936 Geographic Coordinate System.
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pLayer As IFeatureLayer
Set pLayer = pMap.Layer(0)
Dim pFeatureClass As IFeatureClass
Set pFeatureClass = pLayer.FeatureClass
'QI for the geodataset for the layers featureclass
Dim pGeoDataset As IGeoDataset
Set pGeoDataset = pFeatureClass
'QI for the GeoDatasetSchemaEdit from the geodataset
Dim pGeoDatasetEdit As IGeoDatasetSchemaEdit
Set pGeoDatasetEdit = pGeoDataset
'Test if you can alter the spatialreference, if you can, then you
'create a factory and use it to create a geographic coordinate system.
If (pGeoDatasetEdit.CanAlterSpatialReference = True) Then
   Dim pSpatRefFact As ISpatialReferenceFactory2
   Set pSpatRefFact = New SpatialReferenceEnvironment
   Dim pGeoCoordSys As IGeographicCoordinateSystem
   Set pGeoCoordSys = _
      pSpatRefFact.CreateGeographicCoordinateSystem(esriSRGeoCS_OSGB1936)
   'Now alter the layers SR
   pGeoDatasetEdit.AlterSpatialReference pGeoCoorSys
End If
'and force a refresh
pMxDoc.ActiveView.Refresh

[C#]

    //IGeoDatasetSchemaEdit Example

    public void IGeoDatasetSchemaEdit_Example(IFeatureClass featureClass)
    {
        //This function takes a feature class and resets its spatial reference to the
        //OSGB1936 Geographic Coordinate System.
        //cast for the geoDataset
        IGeoDataset geoDataset = (IGeoDataset)featureClass;
        IGeoDatasetSchemaEdit geoDatasetSchemaEdit = (IGeoDatasetSchemaEdit)geoDataset;
        //test if you can alter the spatial reference, if you can, then create
        // a factory and use it to create a geographic coordinate system.
        if (geoDatasetSchemaEdit.CanAlterSpatialReference == true)
        {
            ESRI.ArcGIS.Geometry.ISpatialReferenceFactory2 srFactory = new
                ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
            int gcsType = (int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_OSGB1936;
            ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem geoCoordSystem =
                 srFactory.CreateGeographicCoordinateSystem(gcsType);
            //now alter the spatial reference of the feature class
            geoDatasetSchemaEdit.AlterSpatialReference((ESRI.ArcGIS.Geometry.ISpatialReference)geoCoordSystem);
        }
    }


[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.