zoukankan      html  css  js  c++  java
  • 矢量数据转换成栅格数据

    项目需求:

    将一个多边形数据(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;            

      }        

    }

  • 相关阅读:
    鸡啄米vc++2010系列46(Ribbon界面开发:使用更多控件并为控件添加消息处理函数)
    鸡啄米vc++2010系列45(Ribbon界面开发:为Ribbon Bar添加控件)
    鸡啄米vc++2010系列44(Ribbon界面开发:创建Ribbon样式的应用程序框架)
    鸡啄米vc++2010系列43(MFC常用类:定时器Timer)
    鸡啄米vc++2010系列42(MFC常用类:CTime类和CTimeSpan类)
    鸡啄米vc++2010系列41(MFC常用类:CString类)
    pcl库的配置
    鸡啄米vc++2010系列40(文档、视图和框架:分割窗口)
    鸡啄米vc++2010系列39(文档、视图和框架:各对象之间的关系)
    c 函数传入数组。
  • 原文地址:https://www.cnblogs.com/suixinge/p/2565992.html
Copyright © 2011-2022 走看看