This project is read-only.

Simple Shape Selection Demo in VB6

Sep 30, 2011 at 10:42 AM

Hi,

 

I'm new to MapWinGIS.ocx, just find it interesting and want to see if I can replace my old ESRI component with MapWinGIS

However, I still can't get / understand the documentation on how to use this component.

Do you have any sample code in VB6 on how to display 2 or more layer of shapefile, and then select (highlight) a region when user click on it?

I have try to display 1 layer with code like this:

    Dim sf2 As New Shapefile
    sf2.Open "c:\map\LIBE_BLK.shp"
    Map1.AddLayer sf2, True

When I try to insert another layer, the first layer is just replaced by this new layer, how to set the transparancy?

Sorry if my question is very basic.

Any sample code or link to tutorial will be very appreciated.

 

Thanks.

Oct 4, 2011 at 12:56 AM

dim sf1 as new mapwingis.shapefile

dim sf2 as new mapwingis.shapefile

sf1.open "file1.shp"

sf2.open "file2.shp"

Map1.addlayer sf1, true

map2.addlayer sf2, true

 

in "form_load" :

map.sendMouseDown = true

in "map_mousedown"

convert the X and Y pixels of mouse click to projected X and Y and then use shapefile.selectshapes to find the shapes that intersect your projected X and Y. Finally you can use Map.ShapeColor() to set the color of the selected shapes...

Oct 4, 2011 at 3:54 AM

hi danames,

thanks a lot for the response!

well, I have come up with the code like below, but still no luck.

2 questions:

- When calling SelectShape, the ShapeID below result nothing (Lbound = 0, UBound = -1), althoung I have clicked on a shape

- Adding the second layer replacing the first layer, how to set the transparancy background?

Thanks.

 

Dim sf1 As New MapWinGIS.Shapefile
Dim sf2 As New MapWinGIS.Shapefile
Dim ext As New MapWinGIS.extents

Private Sub Form_Load()
    sf1.Open "c:\map\LIBE_COM.shp"
    sf2.Open "c:\map\LIBE_BLK.shp"
    
    Map1.AddLayer sf1, True
    Map1.AddLayer sf2, True
    
    Map1.SendMouseDown = True
End Sub

Private Sub Map1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
    Dim xP As Double
    Dim yP As Double
    Dim i As Integer
    Dim ShapeID() As Object
    Dim ret As Boolean
    
    xP = 0
    XY = 0
    
    Map1.PixelToProj x, y, xP, yP
    
    Set ext = Map1.extents
    ext.SetBounds xP, yP, 0, xP, yP, 0
    
    ret = sf2.SelectShapes(ext, 10, INTERSECTION, ShapeID)

    For i = LBound(ShapeID) To UBound(ShapeID)
        sf2.ShapeSelected(ShapeID(i)) = True
    Next
End Sub
Oct 4, 2011 at 7:14 PM

Your code looks right. I think that your shapefile data are not overlapping so one "disappears". Check the extents of each shapefile. Does your xP and yP value fall within the bounding box/extents of the shapefile?

On Oct 3, 2011 8:54 PM, "jukylim" <notifications@codeplex.com> wrote:
> From: jukylim
>
> hi danames,thanks a lot for the response!well, I have come up with the code like below, but still no luck.2 questions:- When calling SelectShape, the ShapeID below result nothing (Lbound = 0, UBound = -1), althoung I have clicked on a shape- Adding the second layer replacing the first layer, how to set the transparancy background?Thanks. Dim sf1 As New MapWinGIS.ShapefileDim sf2 As New MapWinGIS.ShapefileDim ext As New MapWinGIS.extentsPrivate Sub Form_Load() sf1.Open "c:\map\LIBE_COM.shp" sf2.Open "c:\map\LIBE_BLK.shp" Map1.AddLayer sf1, True Map1.AddLayer sf2, True Map1.SendMouseDown = TrueEnd SubPrivate Sub Map1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long) Dim xP As Double Dim yP As Double Dim i As Integer Dim ShapeID() As Object Dim ret As Boolean xP = 0 XY = 0 Map1.PixelToProj x, y, xP, yP Set ext = Map1.extents ext.SetBounds xP, yP, 0, xP, yP, 0 ret = sf2.SelectShapes(ext, 10, INTERSECTION, ShapeID) For i = LBound(ShapeID) To UBound(ShapeID) sf2.ShapeSelected(ShapeID(i)) = True NextEnd Sub
>
>
Oct 6, 2011 at 8:58 AM

hi danames,

thank you, really appreciate your guide.

i try to remark the ShapeID variable declaration, and let VB6 to dynamically generate this variable, the result is success!

    'Dim ShapeID() As Object
    ret = sf2.SelectShapes(ext, 10, INTERSECTION, ShapeID)

now I'm confused, how should I declare the variable of ShapeID if I want to explicitly define it?

and also I miss one syntax: Map1.Redraw, that spend me hours to find how to highlight the selected shape. silly, but yes I'm novice in this thing :)

thanks.

Oct 7, 2011 at 2:04 AM
ShapeID() is an array of integers that are the indices of the shapes that resulted from the selection.

Dim ShapeID() as Integer

To change the color of a shape use:

Map.ShapeColor


- Dan

--------------------------
Daniel P. Ames, Ph.D. PE
Associate Professor, Geosciences
Idaho State University - Idaho Falls
dan.ames@isu.edu
geology.isu.edu
www.mapwindow.org



On Thu, Oct 6, 2011 at 1:58 AM, jukylim <notifications@codeplex.com> wrote:

From: jukylim

hi danames,

thank you, really appreciate your guide.

i try to remark the ShapeID variable declaration, and let VB6 to dynamically generate this variable, the result is success!

'Dim ShapeID() As Object


ret = sf2.SelectShapes(ext, 10, INTERSECTION, ShapeID)

now I'm confused, how should I declare the variable of ShapeID if I want to explicitly define it?

and also I miss one syntax: Map1.Redraw, that spend me hours to find how to highlight the selected shape. silly, but yes I'm novice in this thing :)

thanks.

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 or change your settings 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


Oct 7, 2011 at 4:48 AM

hi daniel,

i still can't get the returned value in ShapeID correctly if i declare the variable.

i think it's something with the function parameter parsing option in VB6.

i'm not an VB6 expert also, but it's ok... in the real development we'll use .NET and i think this issue should be solved there.

i have another issue regarding threading model, i'll create a new post since it's not related to this subject.

i think MapWindows is a really nice GIS software, wish i have find it years before.

thanks again!

 

Best Regards,

Juky

Apr 3, 2012 at 2:10 AM

Hi Daniel,

taking up this issue from a Powerbuilder point of view: I don't get this returned object 'ShapeID' type casted correctly because there is nothing like

li_shapes[] = Integer(lobj)

because lobj is just an object and I run into the problem that I try to assign a non-array object to an array...

Anybody encountered the same problem and found a solution?

Best regards

Juergen