Results 1 to 4 of 4

Thread: Convert line to polygon

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    3

    Convert line to polygon

    Hi,
    Need a help - how to convert a line (polyline) to polygon?

    See picture
    Attached Images Attached Images  
    Last edited by tores; Aug 16th, 2012 at 09:55 PM.

  2. #2
    New Member
    Join Date
    Aug 12
    Posts
    3

    Re: Convert line to polygon

    Well, i find some examples, but nothing to start with
    Hope there is visual basic code or algorithm (on c++ etc.)

    ps: i've transfer 10k objects map from Visio to Tilemill, and don't find a way to transfer a lines with constant width (KML)

  3. #3
    Frenzied Member
    Join Date
    Jul 01
    Location
    Tucson, AZ
    Posts
    1,814

    Re: Convert line to polygon

    This came from AllAPI:

    Code:
    Private Type COORD
        x As Long
        y As Long
    End Type
    Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
    Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
    Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
    Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Const ALTERNATE = 1 ' ALTERNATE and WINDING are
    Const WINDING = 2 ' constants for FillMode.
    Const BLACKBRUSH = 4 ' Constant for brush type.
    Private Sub Form_Paint()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: KPDTeam@Allapi.net
        Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
        Me.Cls
        ' Number of vertices in polygon.
        NumCoords = 3
        ' Set scalemode to pixels to set up points of triangle.
        Me.ScaleMode = vbPixels
        ' Assign values to points.
        poly(1).x = Form1.ScaleWidth / 2
        poly(1).y = Form1.ScaleHeight / 2
        poly(2).x = Form1.ScaleWidth / 4
        poly(2).y = 3 * Form1.ScaleHeight / 4
        poly(3).x = 3 * Form1.ScaleWidth / 4
        poly(3).y = 3 * Form1.ScaleHeight / 4
        ' Polygon function creates unfilled polygon on screen.
        ' Remark FillRgn statement to see results.
        Polygon Me.hdc, poly(1), NumCoords
        ' Gets stock black brush.
        hBrush = GetStockObject(BLACKBRUSH)
        ' Creates region to fill with color.
        hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
        ' If the creation of the region was successful then color.
        If hRgn Then FillRgn Me.hdc, hRgn, hBrush
        DeleteObject hRgn
    End Sub
    Private Sub Form_Resize()
        Form_Paint
    End Sub

  4. #4
    New Member
    Join Date
    Aug 12
    Posts
    3

    Re: Convert line to polygon


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •