• 矢量数据转换成栅格数据


    项目需求:

    将一个多边形数据(Polygon)根据指定字段生成栅格数据,和。

    不消说,先查阅ArcGIS的帮助文档。

    首先进入我视线的是 IConversionOp接口的ToRasterDataset方法:

    Set variable = object.ToRasterDataset (dataset, rasterFormat, pWorkspace, name )

    The ToRasterDataset method syntax has the following object qualifier and arguments:

    PartDescription
    object An object expression that evaluates to an object in the Applies To list.
    variable A reference to an object that implements IRasterDataset.
    dataset Required. An IGeoDataset object.
    rasterFormat Required. A string expression that represents the rasterFormat.
    pWorkspace Required. An IWorkspace object.
    name Required. A string expression that represents the name.

     

     

     

     

    因为参数中不能指定字段名,不符合需求,继续寻找另外的方法。

    其实,需求的功能就是ArcToolbox的Conversion下的Polygon To Raster功能,如下图所示:

     

      

    原来有现成的工具啊,这可就容易了。工具的说明如下图所示:

    PolygonToRaster_conversion(in_features, value_field, out_raster_dataset, cell_assignment, priority_field, cellsize)

    ParameterExplanationDatatype
    Input features (Required)

    The polygon input feature dataset to be converted to a raster.

    Feature Layer
    Value field (Required)

    The field used to assign values to the output raster. It can be any field of the input feature dataset's attribute table.

    Field
    Output raster name (Required)

    The output raster dataset to be created.

    When you're not saving to a geodatabase, specify .tif for a TIFF file format, .img for an ERDAS IMAGINE file format, or no extension for a GRID file format.

    Raster Dataset
    Cell assignment type (Optional)

    The method to determine how the cell will be assigned a value when more than one feature falls within a cell.

    • CELL_CENTER—The polygon in which the center of the cell yields the attribute to assign to the cell.
    • MAXIMUM_AREA—The single feature with the largest area within the cell yields the attribute to assign to the cell.
    • MAXIMUM_COMBINED_AREA—Features with common attributes are combined to produce a single area within the cell in question for consideration when determining the largest area.
    String
    Priority field (Optional)

    This field is used when a feature should take preference over another feature with the same attribute.

    Field
    Output cell size (Optional)

    The cell size from which the output raster dataset will be created.

    Analysis cell size

    我们直接用IGeoProcessor的Execute方法进行掉用该工具就OK了。

    代码如下图所示:

    public static bool ToRaster(IFeatureClass feaureClass, string fieldName, String rasterWorkspace, String rasterName, int cellSize)        

    {            

      string fullPath;            

      IGeoProcessor pGP;            

      IGeoProcessorResult pGPR;

      IVariantArray pParameterArray;

      try            

      {                

        fullPath = System.IO.Path.Combine(rasterWorkspace, rasterName);                

        if (System.IO.File.Exists(fullPath))                

        {                    

          //删除已经存在的文件                    

          System.IO.File.Delete(fullPath);                

        }

        pGP = new GeoProcessorClass();

               pParameterArray = new VarArrayClass();                

        pParameterArray.Add(feaureClass);                

        pParameterArray.Add(fieldName);                

        pParameterArray.Add(rasterWorkspace + @"\" + rasterName);                

        pParameterArray.Add("MAXIMUM_AREA");                

        pParameterArray.Add(null);                

        pParameterArray.Add(cellSize);

        //Convertion Tools(PolygonToRaster_conversion)                

        pGPR = pGP.Execute("PolygonToRaster_conversion", pParameterArray, null);

        return true;            

      }            

      catch (Exception ex)            

      {                

         throw ex;            

      }        

    }

  • 相关阅读:
    vuex mapstate_学习 vuex 源码整体架构,打造属于自己的状态管理库
    正则表达式
    对 Kubernetes 部署进行故障排除的视觉指南
    Uber Go 语言编码规范
    云原生训练营结课总结
    谈谈 Kubernetes Operator
    npm run serve报错
    BATIS PLUS实体类中字段映射MYSQL中的JSON格式
    PHPCMS V9静态化HTML生成设置及URL规则优化
    phpcmsV9 文章页时间问题
  • 原文地址:https://www.cnblogs.com/suixinge/p/2565992.html
Copyright © 2020-2023  润新知