Get mwShapeID after selection

Hello.

Tell me how to get, you can get mwShapeID in a simple way, after the shape has been selected on the map.
Now I use this method:
Unfortunately the Delphi code, but I think it will be clear…

  1. EzMap1.CursorMode := cmSelection;

2 . procedure EzMap1ChooseLayer(ASender: TObject; xProj, yProj: Double; var LayerHandle: Integer);

  var shp: Shapefile;
  var ext: Extents;
  var ShID: OleVariant;
  var ShapeSelectedIndex: Integer;
  LayerHandle := EzMap1.LayerHandle[PositionLayerByName('OBJECTS')];
  shp := EzMap1.Shapefile[LayerHandle];
  ext := CoExtents.Create;
  ext.SetBounds(xProj, yProj, 0.0, xProj, yProj, 0.0);
  if shp.SelectShapes(ext, 0.0, INTERSECTION, ShID) = True then
   begin
      ShapeSelectedIndex := ShID[0];
   end;

It works on a layer with a shape of polygon type. On the layer where I have the points … and they are drawning in circles Point Symbol:

shp.DefaultDrawingOptions.SetDefaultPointSymbol(dpsCircle);
shp.DefaultDrawingOptions.PointSize := 30;

This method does not work. What can be done? I need a ShapeSelectedIndex - Point Symbol.
Maybe there are much easier methods to work with selected objects?

I’m not sure I understand.
Do you want the value of a field (i.e. mwShapeID) after selection or do you want to change the appearence of the selected shape?

You say it is working on a polygon shape. What is working?
And it is not working on a point shape. What is not working and what did you expect to happen?

No. Not change the appearence of the selected shape.
I want get the value of a field (i.e. mwShapeID and other) after selection, or get index selected point from geometry data.
Above code work on the layer with shape of polygon type and on the layer with point shape not work.
What I need to do, I can’t understand yet.
It would be nice something like ShapeFile.Selected.Index …

It looks to me like your search extents have no width/height; it is just a point. And you have specified 0.0 tolerance. So it is highly unlikely that you will intersect with a point shape.

Keep in mind that no matter how large a circular symbol you draw (PointSize = 30), it is still just a point geometrically, so you would have to intersect the center of it.

Does that make sense?

1 Like

Of course that makes sense. I will experiment. However, I would like to know if there are simpler methods of working with selected objects. Find out the number of selected objects on the layer. Get information about these objects. Are there any examples? In the existing help very little is given to this topic. Many things have to be studied by trial and error.

Good.
Here is an example:

var ShapeIndex: Integer;
ShapeIndex = 10;
sf.ShapeSelected [ShapeIndex] = True;

After that, a shape with the index 10 will be selected on our map.

But in another way? Did I select a shape with index 10 on the map with my mouse?
How do I get this index of selected shape 10?

For example, abstract code:

var ShapeIndex: Integer;
ShapeIndex = sf.selection.ShapeIndex;

ShapeIndex… AfterSelect ???

I understand now what you mean. You want a list of the selected shapes.
I see MapWinGIS has SelectionList but I’m not completely sure how it works.
It is used with the identifier.

Perhaps it can also be used with sf.SelectShapes.
@jerryfaust What are your thought about this?

I found an earlier issue on GitHub, answering an almost identical question. Hopefully this helps.

select point by mouse click #96

The main activity is done in the Shapefile.SelectShapes method. This method returns an array of indices which, in the example, intersected the specified Extents. You can also ask for containment, etc.

The shapes are not ‘selected’ in the visual sense; you only do that if you want them to be seen visually. This is done with the ShapeSelected property for each element in the result set.

I admit that the terminology (the use of the word ‘selected’) is a little ambiguous, but it is what it is, resulting from the original authors of the library.

1 Like

Oh, thank you very much. I’ll deal with the code. I’ll text you about the results later…

Well, I figured out what was happening.

@jerryfaust
It’s really all in tolerance;

var tolerance: Double
layer.SelectShapes(ext, tolerance, mode, ShID)

Now I can select points and get values from the attribute table.
However, you need to understand the values depending on the scale.
I don’t want to use the event OnMouseDown and translate x, y in xProj, yProj , I want to use event OnChooseLayer and will need to develop a change in the tolerance value depending on the scale of the map.
Well with this I think, will understand.
@pmeems
SelectionList still used when you select a tool CursorMode = cmIdentify.
Which doesn’t suit me, though…

Wondering whether it is possible to change Drawing Options FillColor and other for CursorMode = cmIdentify? I found none.