Hi.
I want to alter the spatial reference of some layers of different types, the code executes but when it reaches the cast operation it gives an error message saying could not cast from system._comobject to IGeoDatasetSchemaEdit. here's my code :
the two messageboxes are there to check if the casting operation form ilayer to igeodataset works, and i does.
Any help would be greatly appreciated.
I want to alter the spatial reference of some layers of different types, the code executes but when it reaches the cast operation it gives an error message saying could not cast from system._comobject to IGeoDatasetSchemaEdit. here's my code :
Code:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
try
{
SpatialReferenceDialog pSRDialog = new SpatialReferenceDialog();
ISpatialReference pSReference = pSRDialog.DoModalCreate(true, false, false, 0);
ILayer pLayer = Utilities.GetLayerByName(pMap, (sender as DataGridView).Rows[e.RowIndex].Cells[0].Value as String);
IGeoDataset pGDataset = (IGeoDataset)pLayer;
MessageBox.Show(pLayer.Name);
MessageBox.Show(pGDataset.SpatialReference.Name);
IGeoDatasetSchemaEdit pGDSEdit = (IGeoDatasetSchemaEdit)pGDataset;
if (pGDSEdit == null)
{
MessageBox.Show("Error. pGDSEdit is null");
return;
}
else if (pGDSEdit.CanAlterSpatialReference)
{
pGDSEdit.AlterSpatialReference(pSReference);
}
(sender as DataGridView).Rows[e.RowIndex].Cells[1].Value = (pLayer as IGeoDataset).SpatialReference.Name;
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
MessageBox.Show(ex.Message);
}Any help would be greatly appreciated.