Selecting Specific Polygon from a Shape File.

Dec 18, 2012 at 8:45 AM

Hello and thanks a ton for the Open Source Active x Component.

 

For the last few days I've been going through all the Discussion Boards, SVN Open Source Directory, User Manuals, but none of them have helped me to complete my Project.

 

I simply want to enter an attribute like "South Africa" in a Text Box and clicking a button would select/highlight the Country. I guess it should work similarly to the "Select" button or the "Query" button with the Query [Select Name = "South Africa"] provided in the MapWindowGIS App 4.8.6. Moreover I would be very grateful if you also also provide the Query Builder process present in the Application to use it effectively in my Custom GIS Project.

 

Coding Platform: VB.Net

Map: world_adm0.shp

Notes Followed: IntroductionCustomGIS.pdf [Brian Marchionni]  

 

Hoping and waiting to get help as soon as possible.

Regards,

Sol

Dec 18, 2012 at 9:16 AM

I also found this old process which was very much appropriate to my Query, but this I guess didn't worked with the New Library.

Code Referred: Selecting shapes from Mouse Down Button

http://www.mapwindow.org/apps/oldwiki/1282.html

 

My Code:

Public Class Form1
    Dim hndWorldShape As Integer
    Dim myWorldShape As New MapWinGIS.Shapefile

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myWorldShape.Open("D:\SampleShapefiles\World\world_adm0.shp")
        hndWorldShape = AxMap1.AddLayer(myWorldShape, True)
    End Sub

   
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AxMap1.SendSelectBoxFinal = True
        AxMap1.SendMouseDown = True
        AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone
        AxMap1.Cursor = Windows.Forms.Cursors.Hand
    End Sub

    Private Sub AxMap1_MouseDownEvent(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent
        Dim ext As New MapWinGIS.Extents
        Dim TL, BR As MapWinGIS.Point
        Dim shapes As Object 'Or Variant type in VB6
        Dim shp As Integer
        Dim Buffer As Integer
        TL = New MapWinGIS.Point 'Top Left Projected
        BR = New MapWinGIS.Point 'Bottom Right Projected
        Buffer = 5 'For points and lines give a 5 pixel buffer for selecting the shapes
        'For polygons, select shapes exactly
        If get_myClass() = "Polygon" Then Buffer = 0
        AxMap1.PixelToProj(e.x - Buffer, e.y + Buffer, TL.x, TL.y)
        AxMap1.PixelToProj(e.x + Buffer, e.y - Buffer, BR.x, BR.y)
        ext = New MapWinGIS.Extents
        ext.SetBounds(TL.x, BR.y, 0, BR.x, TL.y, 0)
        If Not myWorldShape.SelectShapes(ext, 0.0, MapWinGIS.SelectMode.INTERSECTION, shapes) = False Then
            'We found some shapes
            For shp = 0 To shapes.GetUpperBound(0)
                'Do something with shapes(shp)
            Next shp
        End If
    End Sub

    Private Function get_myClass() As String
        With myWorldShape
            If .ShapefileType = MapWinGIS.ShpfileType.SHP_MULTIPOINT Or _
               .ShapefileType = MapWinGIS.ShpfileType.SHP_MULTIPOINTM Or _
               .ShapefileType = MapWinGIS.ShpfileType.SHP_MULTIPOINTZ Or _
               .ShapefileType = MapWinGIS.ShpfileType.SHP_POINT Or _
               .ShapefileType = MapWinGIS.ShpfileType.SHP_POINTM Or _
               .ShapefileType = MapWinGIS.ShpfileType.SHP_POINTZ Then
                get_myClass = "Point"
                Exit Function
            End If
            If .ShapefileType = MapWinGIS.ShpfileType.SHP_POLYLINE Or _
               .ShapefileType = MapWinGIS.ShpfileType.SHP_POLYLINEM Or _
               .ShapefileType = MapWinGIS.ShpfileType.SHP_POLYLINEZ Then
                get_myClass = "Line"
                Exit Function
            End If
        End With
        get_myClass = "Polygon"
    End Function
End Class

Dec 18, 2012 at 11:03 AM

I was going through UsingMapWinGis.pdf by Sir Daniel P. Ames, and came to this code which ain' working as well.

 

Public Class Form1
    Dim hndWorldShape As Integer


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myWorldShape As New MapWinGIS.Shapefile
        myWorldShape.Open("D:\SampleShapefiles\World\world_adm0.shp")
        hndWorldShape = AxMap1.AddLayer(myWorldShape, True)
        
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myWorldShape As New MapWinGIS.Shapefile
        myWorldShape = AxMap1.get_GetObject(hndWorldShape)
        Dim ShapeNum As Integer
        Dim Region As String
        For ShapeNum = 0 To myWorldShape.NumShapes - 1
            Region = myWorldShape.CellValue(1, ShapeNum)
            If Region = "ZAF" Then
                AxMap1.set_ShapeFillColor(hndWorldShape, ShapeNum, Convert.ToUInt32(RGB(255, 0, 0)))
            End If
        Next
    End Sub
End Class

Trying to select South Africa on basis of the code "ZAF", as described with the Switch Case Example for the World Map.

Coordinator
Dec 18, 2012 at 2:58 PM
I wonder if the problem is that your click event isn't firing. If that's the problem then you need to set the property SendMouseDown = True on the control. This makes it possible for you to receive the mouse down events and act on them.
----------------------------------
Daniel P. Ames, Ph.D., P.E.
Associate Professor, Civil & Environmental Engineering
Brigham Young University, Provo, Utah




On Tue, Dec 18, 2012 at 5:03 AM, Sol_Gomez <notifications@codeplex.com> wrote:

From: Sol_Gomez

I was going through UsingMapWinGis.pdf by Sir Daniel P. Ames, and came to this code which ain' working as well.

Public Class Form1 Dim hndWorldShape As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim myWorldShape As New MapWinGIS.Shapefile myWorldShape.Open("D:\SampleShapefiles\World\world_adm0.shp") hndWorldShape = AxMap1.AddLayer(myWorldShape, True) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myWorldShape As New
MapWinGIS.Shapefile myWorldShape = AxMap1.get_GetObject(hndWorldShape) Dim ShapeNum As Integer Dim Region As String For ShapeNum = 0 To myWorldShape.NumShapes - 1 Region = myWorldShape.CellValue(1, ShapeNum) If Region = "ZAF" Then AxMap1.set_ShapeFillColor(hndWorldShape, ShapeNum, Convert.ToUInt32(RGB(255, 0, 0))) End If Next End Sub End Class

Trying to select South Africa on basis of the code "ZAF", as described with the Switch Case Example for the World Map.

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


Dec 19, 2012 at 3:29 AM

Sir,

 

Thanks a lot for your Reply. But, the solution provided is still not working. I did set the property of SendMouseDown to True, at the form load Sub, as well as in a Sub defined in the earlier example posted here, but it ain't working out.

Public Class Form1
    Dim hndWorldShape As Integer


        

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myWorldShape As New MapWinGIS.Shapefile
        myWorldShape.Open("D:\SampleShapefiles\World\world_adm0.shp")
        hndWorldShape = AxMap1.AddLayer(myWorldShape, True)
        AxMap1.SendSelectBoxFinal = True
        AxMap1.SendMouseDown = True
        AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone
        AxMap1.Cursor = Windows.Forms.Cursors.Hand
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myWorldShape As New MapWinGIS.Shapefile
        myWorldShape = AxMap1.get_GetObject(hndWorldShape)
        Dim ShapeNum As Integer
        Dim Region As String
        For ShapeNum = 0 To myWorldShape.NumShapes - 1
            Region = myWorldShape.CellValue(1, ShapeNum)
            If Region = "ZAF" Then
                TextBox1.Text = myWorldShape.CellValue(0, ShapeNum)
            End If
        Next
    End Sub
    Private Sub AxMap1_MouseDownEvent(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent
        AxMap1.SendMouseDown = True
        Dim myWorldShape As New MapWinGIS.Shapefile
        myWorldShape = AxMap1.get_GetObject(hndWorldShape)
        Dim ext As New MapWinGIS.Extents
        Dim TL, BR As MapWinGIS.Point
        Dim Buffer As Integer
        TL = New MapWinGIS.Point 'Top Left Projected
        BR = New MapWinGIS.Point 'Bottom Right Projected
        AxMap1.PixelToProj(e.x - Buffer, e.y + Buffer, TL.x, TL.y)
        AxMap1.PixelToProj(e.x + Buffer, e.y - Buffer, BR.x, BR.y)
        ext = New MapWinGIS.Extents
        ext.SetBounds(TL.x, BR.y, 0, BR.x, TL.y, 0)
    End Sub

    Private Function get_myClass() As String
        Dim myWorldShape As New MapWinGIS.Shapefile
        myWorldShape = AxMap1.get_GetObject(hndWorldShape)
        With myWorldShape
            If myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_MULTIPOINT Or myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_MULTIPOINTM Or myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_MULTIPOINTZ Or myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_POINT Or myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_POINTM Or myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_POINTZ Then
                get_myClass = "Point"
                Exit Function
            End If
            If myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_POLYLINE Or myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_POLYLINEM Or myWorldShape.ShapefileType = MapWinGIS.ShpfileType.SHP_POLYLINEZ Then
                get_myClass = "Line"
                Exit Function
            End If
        End With
        get_myClass = "Polygon"
    End Function
End Class

 

Dec 19, 2012 at 3:32 AM

Sir,

A specific polygon in a shapefile cannot be selected based on a specific attribute by the ShapeFillColor as well.  

Please help, I am in dire need.

 

For ShapeNum = 0 To myWorldShape.NumShapes - 1
            Region = myWorldShape.CellValue(1, ShapeNum)
            If Region = "ZAF" Then
                AxMap1.set_ShapeFillColor(hndWorldShape, ShapeNum, Convert.ToUInt32(RGB(255, 0, 0)))
            End If
        Next

- Regards

Dec 19, 2012 at 9:03 AM

Sir,

 

Thanks a lot. Now, the Mouse Down Event finally works, which I have verified by triggering a Msg Box on Mouse Click over the Map, but now how to change the color of the selected Polygon.

 

-Regards,

Sol

Coordinator
Dec 19, 2012 at 3:42 PM
Now you need to set the shapelayershowfill to true, and set the shapefillcolor(index) = your color...
----------------------------------
Daniel P. Ames, Ph.D., P.E.
Associate Professor, Civil & Environmental Engineering
Brigham Young University, Provo, Utah




On Wed, Dec 19, 2012 at 3:03 AM, Sol_Gomez <notifications@codeplex.com> wrote:

From: Sol_Gomez

Sir,

Thanks a lot. Now, the Mouse Down Event finally works, which I have verified by triggering a Msg Box on Mouse Click over the Map, but now how to change the color of the selected Polygon.

-Regards,

Sol

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


Dec 20, 2012 at 4:50 AM

Sir,

Thanks again for your immense support. But he code provided by you ain't working. It showing:

Error 1 'shapelayershowfill' is not a member of 'AxMapWinGIS.AxMap'. C:\Users\User\Documents\Visual Studio 2008\Projects\mapquery\mapquery\Form1.vb 25 9 mapquery

I would be very grateful to you if you provide me the solution, or a link to a step-wise documentation in Vb.net for the Select Button Event and Zoom to Select as in MapWindow 4.8.6.

Yours faithfully,

Sol

 

Coordinator
Dec 20, 2012 at 4:07 PM
Edited Dec 21, 2012 at 2:51 PM

Sol,

In the 4.8 version of the MapWinGIS ActiveX control, a few optional drawing methods are introduced. These methods are used to help speed up drawing of complex symbology. 

Historically, one would create symbology by manually setting the color of every shape using functions like AxMap1.set_ShapeFillColor. This became a bit tedious for certain applications so a new drawing method was developed that overrides this functionality.

If you want to use the old method (i.e. to make your sample code work) you would need to set the property  AxMap1.ShapeDrawingMethod = MapWinGIS.tkShapeDrawingMethod.dmStandard. Then the old sample code and your code snippets should work fine.

However, if you want to use the new method of showing selected shapes (which is essentially a form of symbolozing the map) then you should look at the source code for the MapWindow GIS 4.8 application. You can view that source code on the source code tab here: http://svn.mapwindow.org/svnroot/MapWindow4Dev/

Indeed, the MapWindow 4.8 desktop application implements nearly all the functionality of the MapWinGIS ActiveX control, so you ought to have that code on  your computer as a reference guide for how to use the control.

- Dan

Dec 21, 2012 at 9:19 AM

Sir,

Loads of Thanks for you support, It's finally working. And I did try to go through the code by downloading it via SVN, but I can't point to the proper segments where the Select Button Event and the Query Builder. has been documented.

I'll be very grateful to you if you can kindly post me the correct path of the documented codes. And lastly, I was wondering, that switching over to the DotSpatial Library would be a better option or not.

 

Eagerly waiting for your response,

-Regards

Yours sincerely,

Sol 

Coordinator
Dec 21, 2012 at 2:51 PM

Sorry there was an error in my last post. To get the source code to MapWindow 4, you need to browse this SVN repository: http://svn.mapwindow.org/svnroot. The MapWindow application source code is in a folder called MapWindow4Dev: http://svn.mapwindow.org/svnroot/MapWindow4Dev/

Unfortunately I can't take the time to walk you through the code, but you are welcome to download it and try to compile it and trace your way through the functions you need. 

You asked about DotSpatial. DotSpatial is a project that several of us worked on as a fully .NET set of libraries. The map visualization is not quite as fast and the libraries aren't as well tested or quite as robust as MapWindow 4, but it is much more "DotNet like" to code with and you are welcome to look at it as well. 

Best of luck!

Dec 26, 2012 at 3:55 AM

Sir,

 

Merry Christmas and Tons of Heartfelt Wishes and Thanks for your kind support. For the past few days I've been working on the Dotspatial Libraries and its working fine with small maps as well. But I wish to revert back to MapWIndow in few days and will be back with queries.

 

Am grateful for your immense support and wishes, without which I wouldn't had been able to progress.

Thanking you,

Yours faithfully

Sol