AppManger And ToolManager Requirements

Oct 18, 2011 at 1:54 PM

Using the latest download, I am getting the following message when adding the AppManager or ToolManager to a form:

Error 5 Reference required to assembly 'System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' containing the implemented interface 'System.ComponentModel.Composition.IPartImportsSatisfiedNotification'. Add one to your project.

When I add a reference to 'System.ComponentModel.Composition' the error disappears.

Is this reference a requirement for AppManager and ToolManager?

Terry

Developer
Oct 19, 2011 at 2:14 AM

I believe it is.

Oct 19, 2011 at 1:19 PM

OK, thanks.

Oct 20, 2011 at 2:33 PM

Thanks mudnug, this helped fix the errors I was getting as well. I just upgraded to the latest version in hopes that I could get the ToolManager to show the tools. However, I still cannot get the tools to display in the ToolManager control. I have followed a few of the forum searches suggestions and the recommendations under the documentation but with no luck. I can't figure out what I am doing wrong. I am almost positive I have followed every guide perfectly.

 

On a related note, How can I call up the function for using IDW (Inverse Distance Weighting)? Since I can't get the tools to display, I was going to try and call up that function manually since it is the only one I am concerned with. Here is some sample code in vbnet that I am using.

 

Dim IDW As New DotSpatial.Tools.InverseDistanceWeighting
Dim M_E As DotSpatial.Modeling.Forms.ModelElement
Dim frm As New DotSpatial.Modeling.Forms.ToolDialog(IDW, M_E)
frm.Show()

I am unsure of what a modelElement is and am stuck there. Any help is greatly appreciated!

Developer
Oct 20, 2011 at 4:37 PM

I'm not entirely sure what you mean by "call up that function manually" but if you mean execute the tool programatically, this example might help.

 

Dim Idw As New DotSpatial.Tools.InverseDistanceWeighting
Idw.Execute(...)

Oct 20, 2011 at 5:00 PM

I just want to bring up the IDW dialog window that you would normally get by clicking on the tool "IDW". Since I can't get the tools to display in my form after many hours of frustration, I decided to try and call up the dialog box manually.

Developer
Oct 20, 2011 at 7:34 PM

I noticed the ToolManager uses the other overload of the ToolDialog 

   public ToolDialog(ITool tool, List<DataSetArray> dataSets, Extent mapExtent)

If you want to follow the DemoMap example and load all of the tools, don't forget to include this code in your form constructor:

            appManager.LoadExtensions();
            appManager.CompositionContainer.ComposeParts(toolManager1);
Oct 21, 2011 at 4:20 PM
Edited Oct 21, 2011 at 4:22 PM

mudnug, I had the previous release from October 14th, 2011 and the last line of code (

appManager.CompositionContainer.ComposeParts(toolManager1);) had no definition in the dll for that function.

I just downloaded and compiled the latest source code (changeset 54e8cae97358) and there is now a definition for CompositionContainer but still nothing for "ComposeParts". There is a compose command and when i try to use that function with the toolmanager, i get the following error: " Value of type 'DotSpatial.Controls.ToolManager' cannot be converted to 'System.ComponentModel.Composition.Hosting.CompositionBatch'.    "

 

 

Edit: I have no idea why the text came out green! Sorry if that makes it more confusing to read


Developer
Oct 21, 2011 at 5:36 PM

You'll want to add a using statement (or Imports in VB.NET) so that the ComposeParts extension Method is availalble.

using System.ComponentModel.Composition;
Oct 21, 2011 at 6:43 PM

Thanks Mudnug! that actually got the tools into the toolmanager!

Mar 2, 2012 at 1:50 AM
Edited Mar 2, 2012 at 1:52 AM

Hello..I am a newbie at Spatial Programming using DotSpatial Library. In DotSpatial library I find means of Inverse Distance Weighting (IDW), but I'm get the same problem. Until now I have not been able to apply IDW in the application that I created. I'm using VB.NET.

Is it possible I build a standalone application about Inverse Distance Weighting (IDW) with the DotSpatial library???

I try to apply source code like that :

 

Imports DotSpatial.Data
Imports DotSpatial.Tools
Imports DotSpatial.Tools.InverseDistanceWeighting

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Idw As New DotSpatial.Tools.InverseDistanceWeighting
        Dim IFeatureSet As IFeatureSet = FeatureSet.OpenFile("D:\IDW\Point.shp")
        Dim ZField As String = "Z"
        Dim CellSize As Double = 1
        Dim Power As Double = 2
        Dim PointCount As Integer = 12
        Dim Distance As Double = 2
        Dim IRaster As IRaster = New Raster
        Idw.Execute(IFeatureSet, ZField, CellSize, Power, NeighborhoodType.FixedDistance, PointCount, Distance, IRaster, Nothing)
        IRaster.SaveAs("D:\IDW\Dem.bgd")
    End Sub
End Class

 

I think the source code that I wrote this much wrong. So I am asking your help to justify it.


If anyone can, please give an example of project or writing code about that using VB.NET. I'm tired to try, try, try and try but nothing I get. Please help me. This concerns the education I am in the Faculty of Geography.

 

==================================================================
Thanks

Rendy Putra Maretika

Student at Faculty of Geography, Gadjah Mada University, Bulaksumur, Yogyakarta 55281 - INDONESIA

my_rendyputra@yahoo.com

Mar 4, 2012 at 1:46 PM
Edited Mar 4, 2012 at 1:47 PM

 

Hi, All..I've tried IDW using GeostatisticalTool and IT WORKS VERY NICE.. Thanks.. Go GeostatisticalTool! Go! Go! Go! ;)

http://geostatisticaltool.codeplex.com/



Great Thanks,
Rendy Putra Maretika
Student at Faculty of Geography, Gadjah Mada University, Bulaksumur, Yogyakarta 55281 - INDONESIA
my_rendyputra@yahoo.com

Sep 12, 2014 at 8:16 PM
Here is the method to run a tool without loading tools in tool manager.
just use as this
 Tools.BufferTool tool = new Tools.BufferTool();

            exTool(tool);
       public void exTool(ITool tool)
        {
            toolToExecute = tool;
        Extent ex = new Extent(-180, -90, 180, 90);
            List<DataSetArray> dataSets = new List<DataSetArray>();
            if (legend1 != null)
            {
                for (int i = 0; i < legend1.RootNodes.Count; i++)
                {
                    dataSets.AddRange(populateDataSets(legend1.RootNodes[i] as IGroup));
                }
            }
            
          //  DotSpatial.Tools.InverseDistanceWeighting IDW = new DotSpatial.Tools.InverseDistanceWeighting();
            // it wasn't a category?
            if (legend1 != null)
            {
                IMapFrame mf = legend1.RootNodes[0] as IMapFrame;
                if (mf != null) ex = mf.ViewExtents;
            }
            ToolDialog td;
            toolToExecute.Initialize();
            td = new ToolDialog(toolToExecute, dataSets, ex);
            //Modeling.Forms.ToolDialog td = new Modeling.Forms.ToolDialog(IDW, dataSets, ex);
            DialogResult tdResult = td.ShowDialog(this);

            while (tdResult == DialogResult.OK && td.ToolStatus != ToolStatus.Ok)
            {
                MessageBox.Show("MessageStrings.ToolSetupIncorectly");
                tdResult = td.ShowDialog(this);
            }
            if (tdResult == DialogResult.OK && td.ToolStatus == ToolStatus.Ok)
            {
                //This fires when the user clicks the "OK" button on a tool dialog
                //First we create the progress form
                ToolProgress progForm = new ToolProgress(1);

                //We create a background worker thread to execute the tool
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += BwDoWork;
                bw.RunWorkerCompleted += executionComplete;

                object[] threadParameter = new object[2];
                threadParameter[0] = toolToExecute;
                threadParameter[1] = progForm;

                // Show the progress dialog and kick off the Async thread
                progForm.Show(this);
                bw.RunWorkerAsync(threadParameter);
            }
}

        private IEnumerable<DataSetArray> populateDataSets(IGroup root)
        {
            List<DataSetArray> dataSets = new List<DataSetArray>();
            if (root != null)
            {
                foreach (ILayer ml in root)
                {
                    if (ml.DataSet != null)
                    {
                        dataSets.Add(new DataSetArray(ml.LegendText, ml.DataSet));


                        IFeatureLayer fl = ml as IFeatureLayer;
                        if (fl != null)
                        {
                            if (fl.Selection.Count > 0)
                            {
                                dataSets.Add(new DataSetArray(fl.LegendText + " - Current Selection", fl.Selection.ToFeatureSet()));
                            }
                        }
                    }
                    if (ml.GetType().Equals(Type.GetType("DotSpatial.Controls.MapGroup")))
                    {
                        dataSets.AddRange(populateDataSets(ml as IGroup));
                    }
                }
            }
            return dataSets;
        }

        private static void BwDoWork(object sender, DoWorkEventArgs e)
        {
            object[] threadParameter = e.Argument as object[];
            if (threadParameter == null) return;
            ITool toolToExecute = threadParameter[0] as ITool;
            ToolProgress progForm = threadParameter[1] as ToolProgress;

            if (progForm == null) return;
            if (toolToExecute == null) return;
            progForm.Progress(String.Empty, 0, "==================");
            progForm.Progress(String.Empty, 0, String.Format("Executing Tool: {0}", toolToExecute.Name));
            progForm.Progress(String.Empty, 0, "==================");
            bool result = false;
            try
            {
                result = toolToExecute.Execute(progForm);
            }
            catch (Exception ex)
            {
                progForm.Progress(String.Empty, 100, "Error: " + ex);
            }
            e.Result = result;
            progForm.ExecutionComplete();
            progForm.Progress(String.Empty, 100, "==================");
            progForm.Progress(String.Empty, 100, String.Format("Done Executing Tool: {0}", toolToExecute.Name));
            progForm.Progress(String.Empty, 100, "==================");
        }
       
        private void executionComplete(object sender, RunWorkerCompletedEventArgs e)
        {
            if (toolToExecute.OutputParameters != null && (bool)e.Result)
            {
                foreach (var p in toolToExecute.OutputParameters)
                {
                    try
                    {
                        var featureset = p.Value as IFeatureSet;
                        if (featureset != null)
                        {
                            appManager1.Map.AddLayer(featureset.Filename);
                        }
                        else
                        {
                            var rasterset = p.Value as IRaster;
                            if (rasterset != null)
                            {
                                appManager1.Map.AddLayer(rasterset.Filename);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to add layer. Reason: " + ex.Message);
                    }
                }
            }
        }