This project is read-only.

How to get separate Centroid with my Map control using Existing FeatureSet

Apr 12, 2014 at 4:58 PM
I'm very new to dotspatial. I want to get the function of GenerateCentroid only in Plugin Tools of dot spatial. But I don't know what I have to pass in parameter.

I want to use this function in my own Window, I have created Map Control with Legend. And then one button of loading layer with the function map1.AddLayer();
public bool Execute(IFeatureSet input1, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
But I don't know how to get featuredset of my loading shp file in Map Control. How I can Access that? and I try to use like this function
GenerateCentroid generate = new GenerateCentroid();
            FeatureSet fs = new FeatureSet();
            //FeatureSet source = map1.GetFeatureLayers()[0]; // this line I don't know
            //generate.Execute(map1.GetAllLayers()[0], fs, null);//  this line also I don't know what to pass in third parameter
How I can Access that? I want to just use the GenerateCentroid with my own button so it can be generated directly to my map control?
Apr 15, 2014 at 2:14 AM
Need help..
Apr 17, 2014 at 9:51 AM
They should be something like


in this way you get the centroids of the layer you selected in your map legend

and null should be fine for the third parameter in the execute command. Otherwise you can see this ISSUE how Mogikanin suggested me to make a cancelprogresshandler

Apr 20, 2014 at 2:12 PM
It doesn't work I have using this code..
private void button3_Click(object sender, EventArgs e)
            GenerateCentroid generate = new GenerateCentroid();
            FeatureSet fs = new FeatureSet(FeatureType.Polygon);

            generate.Execute(map1.Layers.SelectedLayer as FeatureSet, fs, null);
            //FeatureSet source = map1.GetFeatureLayers()[0];
            //generate.Execute(map1.GetAllLayers()[0], fs, null);
It throws an error with invalid cast of SelectedLayer to IFeatureSet. I don't know the object / class that inherit IFeatureSet. Can you give me a complete code to make my code working with my map legend?? Image
Apr 23, 2014 at 1:30 PM
You cannot cast selectedlayer directly into a featureset. Try this out:
            IMapFeatureLayer layer = Map1.Layers.SelectedLayer;
            IFeatureSet fset= layer.DataSet;
            generate.Execute(fset, fs, null);
Marked as answer by jany_ on 9/9/2014 at 1:34 AM