IActiveView.Output times out

1196
14
10-14-2010 03:23 AM
BjørnarSundsbø
Occasional Contributor
I use IMapDocument and its ActiveView.Output to export a bitmap from an MXD documen to a bitmap. This works just fine with an MXD with local data. However, when exporting from an MXD connected to an ArcGIS Server Map Service, the output method seems to time out, and nothing is exported to the bitmap.

Looking at the jobs folder on the arcgisserver, I can see new cache images are crated for the extent I exported. If I zoom out one level, and back in, I get the map image. So in other words I have to export to every extent twice to get an exported map.

What is the reason for this? Is there a timeout setting I have yet to find? The code for exporting is pretty much what you see on different threads here. I do not believe it is the actual code used to export which is the problem.

I use ArcObjects 9.3. I've seen in version 10 there is an ITrackCancel2 interface which has a Timeout property, which might be something I'm looking for. But I hope there is a different way of allowing the Output to wait a bit longer for result from the MapServer service.
0 Kudos
14 Replies
OttarViken_Valvåg
New Contributor III
Hi Bjørnar, it would be easier to comment if you did show us your code, even if it's copied from a sample.
0 Kudos
BjørnarSundsbø
Occasional Contributor
If I call the following method twice, it works, but exporting the same image twice every time i need an image is not an option. Most of the time i will be using an MXD pointing to local data, and doubling the already long export time is not exactly ideal.

private Bitmap GetImageFromJpegExporter(tagRECT rect, CancelTracker trackCancel)
        {
            string filename = Guid.NewGuid().ToString();
            try
            {
                tagRECT exportRECT = _mapDocument.ActiveView.ExportFrame;

                //Create a new envelope object and populate it with the values from exportRECT.
                // We need to do this because the exporter object requires an envelope object
                // instead of a tagRECT structure.
                IEnvelope pPixelBoundsEnv = new EnvelopeClass();
                pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);

                IExport export = new ExportJPEGClass
                {
                    Resolution = 96,
                    ExportFileName = filename,
                    PixelBounds = pPixelBoundsEnv
                };

                Stopwatch watch = new Stopwatch();
                watch.Start();
                int hwnd = export.StartExporting();
                _mapDocument.ActiveView.Output(hwnd, 96, ref rect, _mapDocument.ActiveView.Extent, trackCancel);
                export.FinishExporting();
                export.Cleanup();
                watch.Stop();
                Trace.WriteLine("Export took " + watch.ElapsedMilliseconds + " ms");
                Bitmap fromFileBitmap = new Bitmap(filename);
                // Copy fromFileBitmap because it keeps a lock on the file 
                Bitmap returnBitmap = new Bitmap(fromFileBitmap);
                fromFileBitmap.Dispose();
                return returnBitmap;
            }
            finally
            {
                if(File.Exists(filename))
                {
                    try
                    {
                        File.Delete(filename);
                    }
                    catch (Exception)
                    {
                        
                    }
                }
            }

        }
0 Kudos
OttarViken_Valvåg
New Contributor III
Is your mxd using an internet connection or a local connection to the AGS map service? You could test whether or not this makes a difference.

If exporting twice is what it takes to make things work, a workaround might be to cancel the first export operation after one second and then redoing the export.
0 Kudos
BjørnarSundsbø
Occasional Contributor
I use a local connection to the mapservice. Canceling the operation after a little while is just as bad as exporting twice in my book. The second call will never be necessary if the data is local (fgdb), as the map image will be available in the first export.

I've been looking through the interfaces used by MapDocument to see if I can find a way to set any settings in case a mapservice/wms layer is in use, but no luck so far. There has to be some way to tell the map that we want to change settings on how it interacts with a remote source?
0 Kudos
OttarViken_Valvåg
New Contributor III
You can just loop through your layers and see which interfaces they implement. ArcGIS Server Map Services should be contained in IMapServerSublayer interfaces, and WMS layers should be IWMSLayer interfaces.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IMapServerSublayer_Inter...

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IWMSMapLayer_Interface/0...
0 Kudos
BjørnarSundsbø
Occasional Contributor
Checking for those interfaces to determine if I should export the map once or twice does work. However, I feel this is a hack in the programming-by-coincidence category. Who's to say this is not an issue on a different ArcGIS server installation, or that on the next, I need to export three times because of some other delay?

Any further information on how to fix what is going wrong here would be highly appreciated.

Bjørnar
0 Kudos
OttarViken_Valvåg
New Contributor III
Did you try to change your connection to ArcGIS Server to an internet connection?
0 Kudos
BjørnarSundsbø
Occasional Contributor
No. Our server is not exposed to the internet, and the GIS guy left for the weekend and I have no ArcMap on a machine available to me
0 Kudos
BjørnarSundsbø
Occasional Contributor
I changed the Output type of the service to MIME only instead of MIME + URL, and that did the trick. I get the image on the first attempt. What kind of consequences will this have on performance? From what I can see, the images generated to the argcisoutput directory has a very limited time of life, so the will not really serve as a proper cache.
0 Kudos