矢量數據轉換成柵格數據


項目需求:

將一個多邊形數據(Polygon)根據指定字段生成柵格數據,和。

不消說,先查閱ArcGIS的幫助文檔。

首先進入我視線的是 IConversionOp接口的ToRasterDataset方法:

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

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

Part Description
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)

Parameter Explanation Datatype
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;            

  }        

}

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM