• Creating a Feature Set via C#


    http://anothergisblog.blogspot.com/2009/07/creating-feature-set-via-c.html

    Creating a Feature Set via C#

    A very powerful model builder feature is the create variable option. This will allow users to create almost any type of user input desire. The feature set variable is a very helpful variable when a user needs to interact with the map or recordset. The feature set allows users to draw points, polylines, or polygons on the fly. To do this in C#, you need to use the IGPRecordSetLayerClass(), but the process of making the interactive part work isn't that straight forward.
    To get the interactive part of the Feature set to work, you must define the Schema with either a layer file or feature class in model builder. When you take a look at the ArcObject description of a parameter, you notice a pointer called Schema, but this isn't where you define the template data for a GPFeatureRecordSet, you define it in Value().

    inputParameter.DataType = new GPFeatureRecordSetLayerTypeClass();
    //
    // create the GP Feature Recordset Layer Object
    // from template data
    //
    IFeatureClass FC = (IFeatureClass)m_GPUtilities.OpenDatasetFromLocation( @"" );
    IRecordSetInit recordset = new RecordSetClass();
    recordset.SetSourceTable( (ITable)FC, null );
    IGPRecordSet gpRS = new GPRecordSetClass();
    gpRS.RecordSet = (IRecordSet)recordset;
    IGPRecordSet gpR = new GPFeatureRecordSetLayerClass();
    gpR.RecordSet = new RecordSetClass();
    gpR.RecordSet = (IRecordSet)recordset;
    IGPFeatureRecordSetLayer gpFRSL = (IGPFeatureRecordSetLayer)gpR;
    //
    // Make template Data the default value
    //
    inputParameter.Value = (IGPValue)gpFRSL;
    //
    // Set schema to Geometry Type and
    // add it to schema parameter value
    //
    IGPFeatureSchema fgs = new GPFeatureSchemaClass();
    fgs.GeometryType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline;
    IGPSchema GPschema = (IGPSchema)fgs;
    inputParameter.Schema = GPschema;
    //
    // set the geometery type domain
    //
    IGPFeatureClassDomain geomTypeDomain = new GPFeatureClassDomainClass();
    geomTypeDomain.AddType( esriGeometryType.esriGeometryPolyline );
    inputParameter.Domain = (IGPDomain)geomTypeDomain;
    //
    // Enable the value
    //
    inputParameter.Enabled = true;
    //
    // Set input direction
    //
    inputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
    //
    // Set the name and Dispaly Name
    //
    inputParameter.DisplayName = "Barriers";
    inputParameter.Name = "LineBarrier";
    //
    // Set required, optional, or derivived data
    //
    inputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
    // add parameter
    parameters.Add( inputParameter );

    The result should be an interactive dataset that you can use for interactive Geoprocessing.
    Enjoy

  • 相关阅读:
    [原创]Windows 7 下成功添加网络共享HP打印机
    [原创]PDFCreator自动保存及文件名带空格、后缀名丢失的解决方法(Windows 7通过)
    [原创]U872客户端“system.net.sockets.socketexception”的解决方法
    [转载]Windows 7默认共享无法访问
    [转载]使Excel不显示0值的三招
    [原创]使用空密码远程桌面连接
    分布式架构理论
    ffmpeg重要函数和结构体整理
    es~存储部分字段
    es~text与keyword的选择
  • 原文地址:https://www.cnblogs.com/adodo1/p/4328148.html
Copyright © 2020-2023  润新知