Problem about SelectShapes

Jul 27, 2011 at 4:39 AM

hello everybody,

I am a MapWinGIS novice, I don't know how to select  features in shapelayer and highlight the selected graphics, while I hope the corresponding attribute table records have also been selected and highlighted. That means the realization of selected features linked with the attribute table.

 Greatly appreciate your help.

Coordinator
Jul 28, 2011 at 8:34 AM

What you can do is look at how the table attribute editor is doing that.
That might bring you up to speed:
http://svn.mapwindow.org/svnroot/MapWindow4Dev/TableEditor/

--
Paul

Jul 29, 2011 at 9:24 AM

hello Paul,

Thanks for you answer.I have another question.Is there a TableEditor plugin in MapWinGIS?Where can I download it?

regards

Jean Guan

Jul 31, 2011 at 7:35 PM

hello Paul,

I have another problem.When I select futures on the shapfile,it is not valid. How to select features on the shapefile the mouse?

regards

Jean Guan

Aug 2, 2011 at 1:18 AM
Edited Aug 2, 2011 at 1:19 AM
gqh227 wrote:

hello Paul,

Thanks for you answer.I have another question.Is there a TableEditor plugin in MapWinGIS?Where can I download it?

regards

Jean Guan

The TableEditor plugin comes with MapWindow, so if you install MapWindow you can use the plugin by right clicking on a feature and selecting 'Attribute Table Editor'.  If your just using the MapWinGIS ocx, you'd have to write your own.  I usually find that writing a plugin for MapWindow is usually the way to go for all but the simplest applications.

Developer
Aug 8, 2011 at 2:09 AM

Some notes on shapefile selection are available here: http://www.mapwindow.org/phorum/read.php?2,22646,22646#msg-22646

Aug 10, 2011 at 9:28 AM
Edited Aug 10, 2011 at 11:12 AM

Hello Samsinite and sleschinski

Thanks for you answers. I just using the MapWinGIS.ocx. I still do not make it work. I am trying to select  a polygon by clicking it  from the shapefile.

Here is my code in c#: 

private void MapMain_MouseUpEvent(object sender, AxMapWinGIS._DMapEvents_MouseUpEvent e)
        {
            
            MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
            MapWinGIS.Extents extents = new MapWinGIS.Extents();
            sf = (MapWinGIS.Shapefile)MapMain.get_GetObject(handle);

            double xProjected = 0, yProjected = 0;
            object ShapeIDS = new object(); 
            bool Result;
            if (MapMain.CursorMode == MapWinGIS.tkCursorMode.cmSelection)
            {

                MapMain.PixelToProj(e.x, e.y, ref xProjected, ref yProjected);
                
                extents = (MapWinGIS.Extents)MapMain.Extents;

                extents.SetBounds(xProjected, yProjected, 0, xProjected, yProjected, 0);
                
                Result = sf.SelectShapes(extents, 0.0, MapWinGIS.SelectMode.INTERSECTION, ref ShapeIDS);
                MessageBox.Show(sf.NumSelected.ToString());
                if (Result)
                {
                    MapMain.set_ShapeLayerFillColor(handle, System.Convert.ToUInt32(MapMain.get_ShapeLayerFillColor(handle)));
                    MapMain.set_ShapeLayerLineColor(handle, System.Convert.ToUInt32(MapMain.get_ShapeLayerLineColor(handle)));
                    int[] ShapeID = (int[])ShapeIDS;

                    for (int i = 0; i < ShapeID.Length; i++)
                    {
                        MapMain.set_ShapeFillColor(handle, ShapeID[i], System.Convert.ToUInt32(System.Drawing.Color.Yellow));
                        MapMain.set_ShapeLineColor(handle, ShapeID[i], System.Convert.ToUInt32(System.Drawing.Color.Red));
                    }
                }
            }
        }

No polygon was selected!The "success"is true,but the"sf.NumSelected"is zero.What's the problem?Please help me.

Developer
Aug 12, 2011 at 12:17 AM

The results of selection is in ShapeIds parameter. It should be treated like this:

int[] arr = ShapeIDS as int[];
for (int i =0; i < arr.Count; i++) {
   sf.ShapeSelected(arr[i], true);
}
To set color of selection use:
Shapefile.SelectionColor and Shapefile.SelectionTransparency.
Aug 12, 2011 at 3:08 AM
Edited Aug 12, 2011 at 8:23 AM
sleschinski wrote:

The results of selection is in ShapeIds parameter. It should be treated like this:

int[] arr = ShapeIDS as int[];
for (int i =0; i < arr.Count; i++) {
   sf.ShapeSelected(arr[i], true);
}
To set color of selection use:
Shapefile.SelectionColor and Shapefile.SelectionTransparency.

hello sleschinski,

Running VS2008 - MapWinGIS.ocx(MapWinGIS-only-v4.8RC2)

Thanks for your answer,My problem is about the SelectShapes( ) function.The function returned true,but the sf.NumberSelected is 0.That means no polygon was selected.Why the SelectShapes( ) function didn't work? Any problems of the parameters?

I only add activeX control "MapWinGIS.ocx"to my application,So the shapefile doesn't have    Shapefile.shapeSelected(),Shapefile.SelectionColor and Shapefile.SelectionTransparency metheds.How do I make my shapefile with these methods? What components do I need to reference?

Greatly appreciate your help.

Jean Guan

Developer
Aug 14, 2011 at 9:39 AM

Try to download either Second Release Candidate for v4.8: http://mapwingis.codeplex.com/releases/view/68791

or the one of the latest binaries: http://mapwingis.codeplex.com/releases/view/56060 (need to register with regsvr32)

In the previous versions one need just to set colors of selected shapes, like you tried to do initially. But array with shapes indices should be used all the same.

BTW, ShapeSelected was introduced quite long time ago (set prefix should be used - set_ShapeSelected in C#). 

Aug 14, 2011 at 5:08 PM
Edited Aug 14, 2011 at 5:22 PM

hello sleschinski,

Thanks for  your help again. I think you misunderstood my problem.My problem is that the SelectShapes( ) function doesen't work. The following code which is red marked doesn't

 work. When I click the mouse to select the shapes in the shapefile, the MouseUpEven event is triggered.So the shapefile.NumSelected should be greater than

0,but  MessageBox.Show(sf.NumSelected.ToString()) is 0.I think the problem lies in the SelectShapes() function.Incidentally, I added MapWinGIS.ocx, no MapWindow in my

application.Can you tell me where my code wrong?

Greatly appreciate your help.

Jean Guan

        private void MapMain_MouseUpEvent(object sender, AxMapWinGIS._DMapEvents_MouseUpEvent e)
        {
           
            MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
            MapWinGIS.Extents extents = new MapWinGIS.Extents();
            sf = (MapWinGIS.Shapefile)MapMain.get_GetObject(handle);

            double xProjected = 0, yProjected = 0;
            object ShapeIDS = new object();
            bool Result;
            if (MapMain.CursorMode == MapWinGIS.tkCursorMode.cmSelection)
            {

                MapMain.PixelToProj(e.x, e.y, ref xProjected, ref yProjected);
               
                extents = (MapWinGIS.Extents)MapMain.Extents;

                extents.SetBounds(xProjected, yProjected, 0, xProjected, yProjected, 0);
                
                Result = sf.SelectShapes(extents, 0.0, MapWinGIS.SelectMode.INTERSECTION, ref ShapeIDS);
                MessageBox.Show(sf.NumSelected.ToString());

              }
       }

Aug 14, 2011 at 5:19 PM
hello sleschinski,
Thanks for your help again. I think you misunderstood my problem.My problem is that the SelectShapes( ) function doesen't work. The following code which is red marked doesn't work.
When I click the mouse to select the shapes in the shapefile, the MouseUpEven event is triggered.So the shapefile.NumSelected should be greater than 0,but MessageBox.Show(sf.NumSelected.ToString()) is 0.I think the problem lies in the SelectShapes() function.Incidentally, I added MapWinGIS.ocx only, no MapWindow in my application . Can you tell me where my code wrong?
Greatly appreciate your help.
Jean Guan
private void MapMain_MouseUpEvent(object sender, AxMapWinGIS._DMapEvents_MouseUpEvent e)
{

MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
MapWinGIS.Extents extents = new MapWinGIS.Extents();
sf = (MapWinGIS.Shapefile)MapMain.get_GetObject(handle);

double xProjected = 0, yProjected = 0;
object ShapeIDS = new object();
bool Result;
if (MapMain.CursorMode == MapWinGIS.tkCursorMode.cmSelection)
{

MapMain.PixelToProj(e.x, e.y, ref xProjected, ref yProjected);

extents = (MapWinGIS.Extents)MapMain.Extents;

extents.SetBounds(xProjected, yProjected, 0, xProjected, yProjected, 0);

Result = sf.SelectShapes(extents, 0.0, MapWinGIS.SelectMode.INTERSECTION, ref ShapeIDS);
MessageBox.Show(sf.NumSelected.ToString());
}
}



From: [email removed]
To: [email removed]
Date: Sun, 14 Aug 2011 01:39:45 -0700
Subject: Re: Problem about SelectShapes [mapwingis:266662]

From: sleschinski
Try to download either Second Release Candidate for v4.8: http://mapwingis.codeplex.com/releases/view/68791
or the one of the latest binaries: http://mapwingis.codeplex.com/releases/view/56060 (need to register with regsvr32)
In the previous versions one need just to set colors of selected shapes, like you tried to do initially. But array with shapes indices should be used all the same.
BTW, ShapeSelected was introduced quite long time ago (set prefix should be used - set_ShapeSelected in C#).
Read the full discussion online.
To add a post to this discussion, reply to this email (mapwingis@discussions.codeplex.com)
To start a new discussion for this project, email mapwingis@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Developer
Aug 16, 2011 at 12:23 PM
gqh227 wrote:
I think you misunderstood my problem.My problem is that the SelectShapes( ) function doesen't work. The following code which is red marked doesn't work.

Well, it works, it just doesn't work as you expect. SelectShapes function isn't supposed to change selected state of the shapes.
It's normal that Shapefile.numSelected will be equal to 0. Essentially Shapefile.SelectShapes just provides you the indices of shapes that lie within certain bounds.
Then it's your decision what to do with these shapes. Maybe include in the selection, maybe exclude from it, maybe perform some other 
actions like modifying certain values in dbf table.  It 's far more flexible  approach. 

Probably the name of the function is a bit confusing and it would be better to call it Shapefile.GetShapesWithinBounds(). But unfortunately it was written
 long time ago before the other selection-related functionality and now we just have to stick to it. That's the way to deal with API if you don't want to 
break client code.

I've already wrote you how to ACTUALLY select shapes in the previous posts. I hope it's more clear now.

Aug 16, 2011 at 3:36 PM

hello sleschinski,

I very appreciate your patient helps, I'm sorry to bring you a lot of trouble.I have sovled the problem using the methed you provided to me.Thank sleschinski very much!

Jean Guan