Use shapefile to cut rasterdataset

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.