al3cs

executing arc  hydro tool (flow direction)

Discussion created by al3cs on May 15, 2012
i have problems with executing arc hydro tools and how can i get gp environments in c#

here's my code:
            AHFlowDirection flowDirection = new AHFlowDirection();
            IArray parameters = new ArrayClass();
            IArray values = new ArrayClass();
            IGPUtilities util = new GPUtilitiesClass();
            GPEnvironmentManager gpEnv = new GPEnvironmentManagerClass();
            IGPMessages msg = new GPMessagesClass();
            IArray envs = gpEnv.GetLocalEnvironments();

            //1. in raster
            IGPParameterEdit inputParameter = new GPParameterClass();
            inputParameter.DataType = new GPLayerTypeClass();

            IGPValue val = util.MakeGPValueFromObject(layer);
            inputParameter.Value = val;
            inputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
            inputParameter.DisplayName = "Input Map";
            inputParameter.Name = "input_map";
            inputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
            parameters.Add(inputParameter);
            values.Add(val);

            //2. polygon
            inputParameter = new GPParameterClass();
            inputParameter.DataType = new GPPolygonTypeClass();
            //IPolygon poly = EsriHelper.GetPolygonFromList(CustomPanelControl.CurrentPolygon);
            //IGPValue gpPoly = util.MakeGPValueFromObject(poly);
            inputParameter.Value = null;
            inputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput;
            inputParameter.DisplayName = "Input Polygon";
            inputParameter.Name = "input_polygon";
            inputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeOptional;
            //parameters.Add(inputParameter);

            //3/out raster
            IGPParameterEdit outputParameter = new GPParameterClass();
            outputParameter = new GPParameterClass();
            outputParameter.DataType = new GPRasterLayerTypeClass();
            val = util.MakeGPValueFromObject(out_raster);
            outputParameter.Value = val;
            outputParameter.Direction = esriGPParameterDirection.esriGPParameterDirectionOutput;
            outputParameter.DisplayName = "Out Raster";
            outputParameter.Name = "out_raster";
            outputParameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired;
            parameters.Add(outputParameter);
            values.Add(val);
           
            //msg = flowDirection.Validate(parameters, true, gpEnv);
            ITrackCancel tc = new TrackCancelClass();
            msg = util.InternalValidate(parameters, values, true, true, gpEnv);
            flowDirection.Execute(parameters, tc, gpEnv, msg);
            flowDirection.UpdateParameters(values, gpEnv);
            flowDirection.UpdateMessages(parameters, gpEnv, msg);           

            for (int i = 0; i < msg.Count; i++)
                MessageBox.Show(msg.GetMessage(i).Description);

please help me. thanks.

Outcomes