Hi all,I'm trying to automate a process that I constantly do manually in ArcCatalog. I export shapefiles from CAD and define their projection to NAD83 Zone 17 using ArcCatalog. I want to press a command button in ArcCatalog (in the toolbar) and have the selected shapefile be defined to NAD 83 Zone 17.Here's the code I have so far, but I can't seem to find away to cast the IGxObject to a feature layer to define it's projection..would I even have to cast it? Private Sub ProjectShapefile()
Try
Dim pGApp As IGxApplication = m_application
Dim pGxObj As IGxObject = pGApp.SelectedObject
Dim pGxDataset As IGxDataset
If (TypeOf (pGxObj) Is GxShapefileDataset) = False Then
'If pGxObj.Category <> "Shapefile" Then
MsgBox("Make a valid Selection")
Exit Sub
'End If
End If
Dim pSpatRefFact As ISpatialReferenceFactory
Dim pPCS As IProjectedCoordinateSystem
Dim pSpatialRef As ISpatialReference
pSpatRefFact = New SpatialReferenceEnvironment
pPCS = pSpatRefFact.CreateProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_NAD1983UTM_17N)
Dim gxShape As GxShapefileDataset = New GxShapefileDataset
gxShape = pGxObj
pGxDataset = pGxObj
Dim pGeoDataset As IGeoDataset = pGxDataset
Dim pGeoDatasetEdit As IGeoDatasetSchemaEdit = gxShape
If pGeoDatasetEdit.CanAlterSpatialReference = True Then
' Alter the target layer's spatial reference
pGeoDatasetEdit.AlterSpatialReference(pPCS)
Else
Exit Sub
End If
' Get the spatial reference information and export it to a prj file
pSpatialRef = pGeoDataset.SpatialReference
pGApp.Refresh(pGxObj.Parent.FullName)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub