做项目遇到需要将矢量数据转换成栅格数据的问题,走了很多弯路,后来发现使用 GP 工具很轻松就解决了,记录一下。
ArcGIS 软件中 ArcToolbox 中的工具几乎都可以使用 GP 工具来完成。矢量转栅格的工具主要在 ArcToolbox --> Conversion Tools --> To Raster 下,包括 Feature to Raster、Point to Raster、Polygon to Raster 和 Polyline to Raster。其中 Feature to Raster 与其他三种效果相同。
The input feature dataset to be converted to a raster dataset.
Feature Layer
field
The field used to assign values to the output raster. It can be any field of the input feature dataset’s attribute table. If the Shape field of a point or multipoint dataset contains z or m values, then either of these can be used.
Field
out_raster
The output raster dataset to be created. When not saving to a geodatabase, specify .tif for a TIFF file format, .img for an ERDAS IMAGINE file format, or no extension for an Esri Grid raster format.
Raster Dataset
cell_size (Optional)
The cell size for the output raster dataset. The default cell size is the shortest of the width or height of the extent of the input feature dataset, in the output spatial reference, divided by 250.
using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geoprocessing; using ESRI.ArcGIS.AnalysisTools; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ESRI.ArcGIS.Geoprocessor; using ESRI.ArcGIS.DataSourcesRaster;
privatevoidtoRaster_Click(object sender, EventArgs e) { Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true;
int pLayerId = -1; ILayer pLayer = null; for (int i = 0; i < axMapControl1.LayerCount; i++) { pLayer = axMapControl1.get_Layer(i); //if (pLayer is IFeatureLayer && pLayer.Name == "质点") if (pLayer is IFeatureLayer) { pLayerId = i; } } if (pLayerId == -1) { MessageBox.Show("找不到点图层,请重新加载", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
try { ESRI.ArcGIS.ConversionTools.FeatureToRaster ptr = new ESRI.ArcGIS.ConversionTools.FeatureToRaster();