矢量裁剪栅格(过滤)(c#)

本文介绍了一种使用ClipFilter类从矢量形状文件中读取几何对象,并将其应用于栅格数据的方法。通过遍历要素类获取每个要素的几何形状,然后将这些几何形状添加到ClipFilter实例中。此外,还介绍了如何设置输出属性,包括当输出为非地理数据库格式时调整像素深度和定义NoData值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

IClipFilter clipRaster = new ClipFilterClass();

      //Add the polygons from the shapefile to the clip filer
      IGeometry clipGeometry;
      IFeature feature;
      for (int i = 0; i <= featureClass.FeatureCount(null) - 1; i++)
      {
        feature = featureClass.GetFeature(i);
        clipGeometry = (IGeometry)feature.Shape;
        clipRaster.Add(clipGeometry);
      }

      //Set the filter to the raster
      IPixelOperation pixelOp = (IPixelOperation)raster;
      pixelOp.PixelFilter = (IPixelFilter)clipRaster;

      //Now we need to specify properties for the output. The output can
      //be a file format or a geodatabase. This sample supports output
      //to File geodatabase and Personal Geodatabase.
      //If the output is a file format and input raster does not contain NoData and the max value
      //of the pixel depth is being used. (For example 255 is used for
      //8 bit unsigned case), output pixel depth needs to be promoted and NoData
      //value need to set up properly.

      IWorkspace workSpace = openWorkspace(outputFolder);
      IRasterProps rasterProps = (IRasterProps)raster;

      if (workSpace.PathName.Contains(".gdb") == false)
      {
        rasterProps.NoDataValue = 256;
        rasterProps.PixelType = rstPixelType.PT_USHORT;
      }

      //Save the result out
      ISaveAs saveas = (ISaveAs)raster;
      saveas.SaveAs(outputFile, workSpace, Format);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值