Sub extractionofraster ()
Dim app as iapplication
Set APP = Application
Dim pmxdocument as imxdocument
Set pmxdocument = application. Document
Dim pmap as IMAP
Set pmap = pmxdocument. focusmap
Dim pfeaturelayer as ifeaturelayer
Set pfeaturelayer = pmap. layer (0)
Dim prasterlayer as irasterlayer
Set prasterlayer = pmap. layer (1)
Dim pfeatureclass as ifeatureclass
Set pfeatureclass = pfeaturelayer. featureclass
Dim ppolygon as ipolympus gon
Set ppolygon = pfeatureclass. getfeature (0). Shape
Dim pextractionop as iextractionop
Set pextractionop = new rasterextractionop
Dim pinputdataset as igeodataset
Set pinputdataset = prasterlayer. Raster
Dim poutputdataset as igeodataset
Set poutputdataset = pextractionop. polygon (pinputdataset, ppolygon, false) 'false' indicates that parts other than shapefile are retained, and ture indicates that parts within shapefile are retained.
Dim PWS as iworkspace
Dim pwsf as iworkspacefactory
Set pwsf = new rasterworkspacefactory
Set PWS = pwsf. openfromfile ("C: \ Temp", 0) 'output directory of the result data
Dim prws as irasterworkspace2 'is used to create rasterdataset
Set prws = PWS
Dim psaveas as isaveas
Set psaveas = poutputdataset
Dim outdataset as idataset
Set outdataset = psaveas. saveas ("new2.tif", prws, "tiff ")
Msgbox "Good! "
End sub