WHY no result was returned when using project raster geoprocessor in ArcEngine?

1196
2
01-18-2011 04:51 AM
lzm
by
New Contributor
Hi there,

I can use Project Raster in arctoolbox to project a raster data correctly and one result raster image file was returned. The related parameters are showed in the following picture.



BUT, I program C# in VS2008 using the same parameters as the above. And, try to run it. There is no error information and  no result returned! I am puzzled! The details is as followed
       private void button1_Click(object sender, EventArgs e)
        { 

            //output projected CS
            ISpatialReferenceFactory2 pSpatRefFact = new SpatialReferenceEnvironmentClass();
            int proCS_Type = (int)esriSRProjCSType.esriSRProjCS_World_Mercator;
            IProjectedCoordinateSystem pOutProCS = pSpatRefFact.CreateProjectedCoordinateSystem(proCS_Type);
            ISpatialReference pOutSRprj = pOutProCS as ISpatialReference;

            Geoprocessor igp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            ProjectRaster proR = new ProjectRaster();

            //construct processor            
            proR.out_coor_system = pOutSRprj;// "World_Mercator";
            proR.in_raster = @"E:\TestData\gisrs\projection\gcs_long_dem.img";
            proR.out_raster = @"E:\TestData\gisrs\projection\out2.img";
            proR.cell_size = 16.6;
            proR.resampling_type = "NEAREST";

            //execute the tool
            RunTool(igp, proR, null);            

        }
        // Function for returning the tool messages.
        private void ReturnMessages(Geoprocessor gp)
        {
            string ms = "";
            if (gp.MessageCount > 0)
            {
                for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
                {
                    ms += gp.GetMessage(Count);
                }
                MessageBox.Show(ms);
            }
        }
        private void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)
        {
            // Set the overwrite output option to true
            geoprocessor.OverwriteOutput = true;
            geoprocessor.AddOutputsToMap = true;
            try
            {
                //  geoprocessor.Execute(
                geoprocessor.Execute(process, null);
                ReturnMessages(geoprocessor);
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                ReturnMessages(geoprocessor);
            }

        }


My operation system is WIN7, and the version of arcengine is 9.3. Any reply will be appreciated! Thank you so much!
0 Kudos
2 Replies
JohnHauck
Occasional Contributor II
The code looks fine, and executes without error when tested against 9.3.1. I don't have a 9.3 system readily avalible anymore. The messages returned indicate that the tool executed sucessfully? Could you post the messages returned? With the random test data I chose I also needed to specify a geographic transformation. I can't see your image and don't know what datum you are coming from so I'm not sure if this is the case for you. Have you tried with other rasters? You may also try adding the GP tool to a model then export to Python or VB Script to see if you may be able to get an idea of what's going wrong.
0 Kudos
lzm
by
New Contributor
The code looks fine, and executes without error when tested against 9.3.1. I don't have a 9.3 system readily avalible anymore. The messages returned indicate that the tool executed sucessfully? Could you post the messages returned? With the random test data I chose I also needed to specify a geographic transformation. I can't see your image and don't know what datum you are coming from so I'm not sure if this is the case for you. Have you tried with other rasters? You may also try adding the GP tool to a model then export to Python or VB Script to see if you may be able to get an idea of what's going wrong.


Thank you so much, John.  Finally, I find the problem in my codes.

out_coor_system parameter needs to be set with the detail projection parameters.

This method can implement the conversion between to coordinate system using the same datum. Sometimes, the two coordinate systems used in the conversioin have different datums.  But, the geographic transformations pre-defined in AreGIS are not enough. Sometimes, we need to create a geographic transformation to be used in our applications. So, could you please let me know how to define one customized geographic transformation? Thanks.
0 Kudos