mapaction/mapaction-toolbox

Exported .KML file is added to the map document after export completes

Closed this issue · 9 comments

When an export is run the .KML from the resulting files is added to the map document, which is not desirable behaviour. See email from Matt to dev group 2016-04-18.

Almost certainly occurs because KML is exported via GP call:
gp.Execute("MapToKML_conversion", parameters, null);
and default behaviour is to add geoprocessing outputs to the map. So this should be turned off.

More comments from Harry:
My guess, and it is only a guess, is that you need to set gp.AddOutputsToMap = False in exportMapFrameKmlAsRaster.
See http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/AddOutputsToMap_Property/002n000000tt000000/
(wrong version, but you get the idea).

If this guess is correct, then the issue is probably only arising when the map frame is in WGS84. There is this comment in the code:
//This function needs to be updated to incorporate projected map frames, it currently only works if the frame is wgs84
So if they set a projection then maybe it won't happen (but they won't get kml generated either).

I've tried fixing this but there is a more egregious issue.
A KeyNotFoundException is generated in the exportMapFrameKmlAsRaster method at this line: parameters.Add(dict["kmlresolutiondpi"]);

Because that key isn't present in that dictionary, and never will be.

I'm not sure how this has got through because the net result is that the tool is always broken - this issue will be hit every time.

@harry-gibson, @clairebyrne I've spent a bit of time looking at this and cannot currently reproduce it.

I've tried these three versions (manually driving ArcMap, not using automated tests):
v3.1.5415.30845 (which is what it currently on the laptops). => KML is exported and not added to the map
v3.1.5954.15939 (a build I created last night on my machine) => KML is exported and not added to the map
v3.1.5941.100 (the version attached to this card https://www.pivotaltracker.com/story/show/109039658) => crashes badly

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at MapAction.MapExport.exportMapFrameKmlAsRaster(IMxDocument pMxDoc, String dataFrame, String filePathName, String scale) in c:\Program Files (x86)\Jenkins\jobs\Export Tool (test)\workspace\arcgis10_mapping_tools\MapAction\MapAction\MapExport.cs:line 214
   at MapActionToolbars.frmExportMain.btnCreateZip_Click(Object sender, EventArgs e) in c:\Program Files (x86)\Jenkins\jobs\Export Tool (test)\workspace\arcgis10_mapping_tools\MapActionToolbars\frmExportMain.cs:line 246
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

(The missing key is relates to this line parameters.Add(dict["kmlresolutiondpi"]); I've got a separate fix for that which I'll push shortly, but I'm not sure that's relevant to this problem.)

In fact even if I tried adding the line gp.AddOutputsToMap = True I still couldn't reproduce the problem. I've also checked all of the relevant settings in ArcMap (eg Geoprocessing Menu -> Geoprocessing Options...).

I wonder if there could be another factor? Perhaps specific types of map content? My map is very simple (just the polygon outline of Nepal).

@andrewphilipsmith , @clairebyrne Yes - that KeyNotFoundException is what I mentioned in the previous comment and my email. It's relevant only in that I need to work around it (hard code in a value) to be able to get as far as reproducing the KML adding to map issue!

Having hardcoded a kml resolution, to work around the dictionary key issue, I have reproduced the adding-to-map issue, using the polygon Nepal outline map in the projects test files.

As you would expect:

  • The outputs are added to the map if "Add results of geoprocessing operations to the display" is checked under Geoprocessing Options
  • They are not added if it is not checked, so this should be a successful workaround.
  • Adding "gp.AddOutputsToMap = false" causes the outputs not to be added to the map regardless of the UI setting, and therefore seems to fix the issue.

I'm not sure why you couldn't reproduce, Andy. The only thing I can guess is that ArcMap was using a different copy of the compiled add-in. I made sure to delete the addin, close ArcMap, clean, and rebuild the solution, before reloading the add-in from the build directory.

@andrewphilipsmith Another thought - is the copy of Arcmap you're testing with able to read the kml if you add it manually? If I remember correctly it depends on the Data Interop extension so if this isn't available it may be that ArcMap "tries" to add it but cannot, hence your lack of reproduction.

Have now committed an apparent fix.

@harry-gibson you are a genius!. Yes enabling the Data Interop Extension, meant that I could reproduce this bug.

BTW: the third and fourth part of the version number is generated automatically at compile time, so it it possible to check from within ArcMap which specific build is currently in use.

Excellent stuff!
Do we have a new addin to send to the FT then ?

We probably could do if we're happy to send out with the KML resolution
hardcoded @ 300dpi which it currently is.

Best not from me though, as I only have ArcGIS 10.3 to compile against.

On 20 April 2016 at 20:44, clairebyrne notifications@github.com wrote:

Excellent stuff!
Do we have a new addin to send to the FT then ?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#124 (comment)

Harry Gibson - 07967 730049