zoukankan      html  css  js  c++  java
  • 从FeatureClass创建Grid

     1 /// <summary>
     2 /// Create a raster GeoDataset grid from a FeatureClass.
     3 /// </summary>
     4 /// <param name="feaureClass">An IFeatureClass interface that will have a raster (grid) created from it.</param>
     5 /// <param name="string_RasterWorkspace">A System.String that is the workspace location for the grid coverage. Example: "C:workspace"</param>
     6 /// <param name="int32_NumberOfCells">A System.Int32 that is the number of cells in the X direction that you want the raster to have. This defines the resolution of the raster. Example: 10000.X方向上单元格数量,这决定栅格数据的分辨率</param>
     7 /// <returns>A GeoDataset that is a raster of the input FeatureClass</returns>
     8 /// <remarks></remarks>
     9 public ESRI.ArcGIS.Geodatabase.IGeoDataset CreateGridFromFeatureClass(ESRI.ArcGIS.Geodatabase.IFeatureClass feaureClass, System.String string_RasterWorkspace, System.Int32 int32_NumberOfCells)
    10 {
    11   //显示转换,把IFeatureClass转为IGeoDataset
    12     ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)feaureClass; // Explicit Cast
    13    //获取空间参考
    14     ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = geoDataset.SpatialReference;
    15     //创建栅格转换操作
    16     // Create a RasterMaker operator
    17     ESRI.ArcGIS.GeoAnalyst.IConversionOp conversionOp = new ESRI.ArcGIS.GeoAnalyst.RasterConversionOpClass();
    18     //从目标文件夹创建栅格工作空间
    19     ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass();
    20     // set output workspace
    21     ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile(string_RasterWorkspace, 0);
    22     //显示转换,创建栅格分析环境,设置输出工作空间为上面设置的栅格工作空间
    23     // Create analysis environment
    24     ESRI.ArcGIS.GeoAnalyst.IRasterAnalysisEnvironment rasterAnalysisEnvironment = (ESRI.ArcGIS.GeoAnalyst.IRasterAnalysisEnvironment)conversionOp; // Explicit Cast
    25     rasterAnalysisEnvironment.OutWorkspace = workspace;
    26     //获取输入的范围Extent
    27     ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
    28     envelope = geoDataset.Extent;
    29    //根据图形边界,X轴方向单元格数量设置单元格尺寸大小
    30     // Set cell size
    31     System.Double double_xMin = envelope.XMin;
    32     System.Double double_xMax = envelope.XMax;
    33     System.Double double_difference = double_xMax - double_xMin;
    34     System.Double double_cellSize = double_difference / int32_NumberOfCells;
    35     object object_cellSize = (System.Object)double_cellSize;
    36     rasterAnalysisEnvironment.SetCellSize(ESRI.ArcGIS.GeoAnalyst.esriRasterEnvSettingEnum.esriRasterEnvValue, ref object_cellSize);
    37     
    38     //设置输出范围
    39     // Set output extent
    40     object object_Envelope = (System.Object)envelope; // Explict Cast
    41     object object_Missing = System.Type.Missing;
    42     rasterAnalysisEnvironment.SetExtent(ESRI.ArcGIS.GeoAnalyst.esriRasterEnvSettingEnum.esriRasterEnvValue, ref object_Envelope, ref object_Missing);
    43     //设置输出空间参考与输入一致
    44     // Set output spatial reference
    45     rasterAnalysisEnvironment.OutSpatialReference = spatialReference;
    46     //以下是执行空间操作
    47     // Perform spatial operation
    48     ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset = new ESRI.ArcGIS.DataSourcesRaster.RasterDatasetClass();
    49    //创建输出栅格文件的名称,用下划线替代空格
    50     // Create the new raster name that meets the coverage naming convention
    51     System.String string_RasterName = feaureClass.AliasName;
    52     if (string_RasterName.Length > 13)
    53     {
    54         string_RasterName = string_RasterName.Substring(0, 13);
    55     }
    56     string_RasterName = string_RasterName.Replace(" ", "_");
    57 
    58     rasterDataset = conversionOp.ToRasterDataset(geoDataset, "GRID", workspace, string_RasterName);
    59 
    60     ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_output = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset;
    61 
    62     return geoDataset_output;
    63 }


    源:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//00490000000z000000
  • 相关阅读:
    ZOJ2402 Lenny's Lucky Lotto List 简单DP
    HDU1024 最大M子段和问题 (单调队列优化)
    HDU2048 HDU2049 组合数系列 错排
    HDU1081 最大字段和 压缩数组(单调队列优化)
    HDU1166 数状数组
    HDU1085 多重背包
    HDU3062
    递归 递推 规律
    【机器学习PAI实战】—— 玩转人工智能之美食推荐
    阿里开源自用 OpenJDK 版本,Java 社区迎来中国力量
  • 原文地址:https://www.cnblogs.com/xuchen/p/5844409.html
Copyright © 2011-2022 走看看