How do I add rasters to a raster mosaic?

510
2
05-31-2019 03:32 PM
DrewDowling
Occasional Contributor III

I'm trying to programmatically add .tif files to a raster mosaic. The code below gives a GPResult object of error type but no error messages are given so I don't know what I'm doing wrong. I can't get any other error messages or warning to trigger.

string inpath = Project.Current.DefaultGeodatabasePath;

string in_mosaicdataset_name = "Mosaic_name";

parameters = Geoprocessing.MakeValueArray(inpath + "\\" + in_mosaicdataset_name, "Raster Dataset", @"D:\Temp\image_982-1376.tif");
                    try
                    {
                        IGPResult gPResult = await Geoprocessing.ExecuteToolAsync(tool_path, parameters, null, _cts.Token, (event_name, o) =>  // implement delegate and handle events, o is message object.
                        {
                            switch (event_name)
                            {
                                case "OnValidate": // stop execute if any warnings
                                    MessageBox.Show(o.ToString());
                                    if ((o as IGPMessage[]).Any(it => it.Type == GPMessageType.Warning))
                                        System.Windows.MessageBox.Show(o.ToString());
                                    //_cts.Cancel();

                                    break;
                                case "OnProgressMessage":
                                    string msg = string.Format("{0}: {1}", new object[] { event_name, (string)o });
                                    System.Windows.MessageBox.Show(msg);
                                    //_cts.Cancel();
                                    break;
                                case "OnProgressPos":
                                    string msg2 = string.Format("{0}: {1} %", new object[] { event_name, (int)o });
                                    System.Windows.MessageBox.Show(msg2);
                                    //_cts.Cancel();
                                    break;
                            }
                        });
                        Geoprocessing.ShowMessageBox(gPResult.Messages, "GP Messages", gPResult.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);

0 Kudos
2 Replies
Prashant_MukeshMangtani
Esri Contributor

Drew,

Can you try adding the same image through ArcGIS Pro GP? If that works a good way to validate your code is to run the Add Rasters tool with the same data/parameters and use the History tab on the Catalog pane to Copy python command to get a valid call to the tool and compare the string with your call.

-Prashant

0 Kudos
DrewDowling
Occasional Contributor III

Sorry for the late reply, I only saw this now.

I was able to add the rasters using the Pro GUI without any problems. The problem turned out to be an issue with the token I supplied, _cts.Token. I changed it deceleration location and the prepossessing tool worked. I'm not entirely sure what the issue was but I think I had declared _cts on a different thread and this was causing the tool to fail.

Thanks for your help.

0 Kudos