zoukankan      html  css  js  c++  java
  • How to load a raster dataset to the raster field in a feature class

    A feature class or table can have a raster attribute field to store any raster related to the feature. You can edit raster values in the raster field using the Editor tool. If you have many raster datasets to add to the raster field, you need to write a custom application to simplify the workflow.

    Loading a raster dataset to the raster field in a feature class

    To load a raster dataset to the raster field, follow these steps:
    1. Get a workspace for editing.
    2. Find the raster field index.
    3. Create a raster value object with an input raster dataset.
    4. Set the raster value to the raster field.
    5. Stop editing and save.
    The following code sample shows how to load a raster dataset into a feature in a feature class given the ObjectID (OID) of the feature. Only geodatabase feature classes can have a raster attribute field.

    [C#]

    static void LoadToRasterAttribute(IFeatureClass featureClass, IRasterDataset
        rasterDataset, int OID)
    {
        /*Parameters:
        featureClass—The feature class with raster attribute.
        rasterDataset—The raster dataset to be loaded to the raster attribute.
        OID—The ObjectID of the feature to be edited.
         */
    
        //Get workspace for editing.
        IDataset dataset = (IDataset)featureClass;
        IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)dataset.Workspace;
        workspaceEdit.StartEditing(false);
        workspaceEdit.StartEditOperation();
        IFeature feature = featureClass.GetFeature(OID);
    
        //Find raster field index.
        int iRasterField = 0;
        for (int i = 0; i < feature.Fields.FieldCount; i++)
        {
            if (feature.Fields.get_Field(i).Type == esriFieldType.esriFieldTypeRaster)
            {
                iRasterField = i;
                i = 1000;
            }
        }
    
        //Create raster value with input raster dataset.
        IRasterValue rasterValue = new RasterValueClass();
        rasterValue.RasterDataset = rasterDataset;
    
        //Set raster value to the raster field.
        feature.set_Value(iRasterField, rasterValue);
        feature.Store();
    
        //Stop editing and save edits.
        workspaceEdit.StopEditOperation();
        workspaceEdit.StopEditing(true);
    }

    [VB.NET]

    Public Sub LoadToRasterAttribute(ByVal featureClass As IFeatureClass, ByVal rasterDataset As IRasterDataset, ByVal OID As Integer) ' Parameters:
        ' featureClass—The feature class with raster attribute.
        ' rasterDataset—The raster dataset to be loaded to the raster attribute.
        ' OID—The ObjectID of the feature to be edited.
        
        'Get workspace for editing.
        Dim dataset As IDataset = CType(featureClass, IDataset)
        Dim workspaceEdit As IWorkspaceEdit = CType(dataset.Workspace, IWorkspaceEdit)
        workspaceEdit.StartEditing(False)
        workspaceEdit.StartEditOperation()
        
        Dim feature As IFeature = featureClass.GetFeature(OID)
        'Find raster field index.
        Dim iRasterField As Integer = 0
        Dim i As Integer
        For i = 0 To feature.Fields.FieldCount - 1 Step i + 1
            If feature.Fields.get_Field(i).Type = esriFieldType.esriFieldTypeRaster Then
                iRasterField = i
                i = 1000
            End If
        Next
        
        'Create raster value with input raster dataset.
        Dim rasterValue As IRasterValue = New RasterValueClass()
        rasterValue.RasterDataset = rasterDataset
        
        'Set raster value to the raster field.
        feature.set_Value(iRasterField, rasterValue)
        feature.Store()
        
        'Stop editing and save edits.
        workspaceEdit.StopEditOperation()
        workspaceEdit.StopEditing(True)
    End Sub







    To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):


    Development licensingDeployment licensing
    ArcGIS for Desktop Basic ArcGIS for Desktop Basic
    ArcGIS for Desktop Standard ArcGIS for Desktop Standard
    ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
    Engine Developer Kit Engine


  • 相关阅读:
    Spring基于注解整合Redis实现内容缓存
    配置Mybatis二级缓存为Redis来实现内容缓存
    Spring整合Redis
    Java连接redis
    机器学习之 KNN近邻算法(一)入门
    matplotlib 之 快速入门
    Pandas 之入门
    Hadoop 之 环形缓冲区原理
    numpy 之 rollaxis的理解
    python 之 遇到SyntaxError: Non-UTF-8 code starting with 'xb8' in file
  • 原文地址:https://www.cnblogs.com/gisoracle/p/5209735.html
Copyright © 2011-2022 走看看