Results 1 to 12 of 12

Thread: [RESOLVED] array data

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Resolved [RESOLVED] array data

    i have use the code below to represent each pixel of picture with it's value of latitude and longitude.

    Code:
    private sub form_load()
         with picture 1
              .autoredraw=true
              . scaleleft = 101.46667
              . scalewidth=99.7-101.46667
              .scaletop=2.85667
              .scaleheight=4.01666-2.85667
        end with
    end sub
    i want to make array data according to the pixel. how to do it?

  2. #2
    Lively Member Xium's Avatar
    Join Date
    Jan 2007
    Posts
    78

    Re: array data

    do u wanna to store pixel values in 2 dim array ?
    Hassan Khan

  3. #3
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: array data

    If pixels are your concern, I wonder if you are better off using vbpixels rather than a userscale, then you could use a few functions to convert a map coord to picturebox coord (and back).
    Code:
    Option Explicit
    Dim PicHght As Long
    Dim PicWdth As Long
    Dim MapHght As Double
    Dim MapWdth As Double
    Dim Map0X As Double
    Dim Map0Y As Double
    Dim MapPixels() As Byte 'or whatever
    
    Private Sub form_load()
         With Picture1
              .AutoRedraw = True
              .ScaleMode = vbPixels
              PicHght = .ScaleHeight
              PicWdth = .ScaleWidth
         End With
         Map0X = 101.46667
         Map0Y = 2.85667
         MapWdth = 99.7 - Map0X
         MapHght = 4.01666 - Map0Y
         ReDim MapPixels(PicHght, PicWdth)
    End Sub
    
    Private Function GetLatitude(ByRef Y As Long) As Double
     GetLatitude = Round((Y * MapHght / PicHght) + Map0Y, 5)
    End Function
    
    Private Function GetLongitude(ByRef X As Long) As Double
     GetLongitude = Round((X * MapWdth / PicWdth) + Map0X, 5)
    End Function
    
    Private Function GetY(ByRef Latitude As Double) As Long
     GetY = (Latitude - Map0Y) * PicHght / MapHght
    End Function
    
    Private Function GetX(ByRef Longitude As Double) As Long
     GetX = (Longitude - Map0X) * PicWdth / MapWdth
    End Function
    Last edited by Milk; Mar 31st, 2007 at 07:44 AM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: array data

    Quote Originally Posted by Xium
    do u wanna to store pixel values in 2 dim array ?
    actually, i have a set of data in text file. it contain latitude,longitude and depth. format as below:
    100.99773000 3.62534000;1.8
    100.99233000 3.61241000;4.3
    100.98487000 3.63044000;2.7
    100.96065000 3.59110000;8.5
    100.98844000 3.59599000;5.2
    100.98141000 3.57035000;5.8
    100.99719000 3.56166000;4
    101.01482000 3.55710000;1.5
    101.03017000 3.56568000;3
    101.00930000 3.58230000;4
    101.03179000 3.58469000;2

    i want use the mousemove event, when i piont the mouse to a point(lat,lon) in the picure. it will read the text file,and get the depth value correspond to that latitude and longitude.
    Attached Files Attached Files

  5. #5
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: array data

    If you want to display a depth for each pixel, you need to have the correct value for each pixel point! do yu have a data entry for each possible point in your file?

    If you have it, you could make an array with 2 dimensions (lat,long) which is giving the depth for each coordinate (in this case the cooredinate should be in pixel! i.e. an Long!). Just convert each coordinate with code like the one from milk to get the cooresponding index of the array and save the depth value.
    for example:
    Your value: 100.99773000 3.62534000;1.8

    saved like this: 2DArray(GetX(100.99773000);GetY(3.62534000)=1.8

    If you do not have values for all pixels you need to fill the gaps by the value of the next best data entry or interpolate a value.

    The mousemovement event could look like this:
    Code:
    Private Sub Picture_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Picture.ToolTipText="Depth " & CStr(2DArray(x,y))
    End Sub
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: array data

    Quote Originally Posted by opus
    If you have it, you could make an array with 2 dimensions (lat,long) which is giving the depth for each coordinate (in this case the cooredinate should be in pixel! i.e. an Long!). Just convert each coordinate with code like the one from milk to get the cooresponding index of the array and save the depth value.
    for example:
    Your value: 100.99773000 3.62534000;1.8

    saved like this: 2DArray(GetX(100.99773000);GetY(3.62534000)=1.8
    i not quite understand about it. can u provide more detail infro or code. thanks very much.

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: array data

    What do you have so far?
    If you have the Picturebox already, try this code:
    Code:
    Private Sub Picture_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Picture.ToolTipText="PixelX " & CStr(x) &" PixelY" & Cstr(y)
    End Sub
    When moving the mouse on your picturebox you will see the Pixelvalues for the location of your mousepostion.
    Instead of showing those pixel-values you want to show a depth value that corresponds with the X and Y value of the pixel your mouse is pointing on, correct?

    Instead of reading the data from a file each time the mouse moves, I'd suggest to read the data in the form_load event into an array.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: array data

    Quote Originally Posted by opus
    Instead of reading the data from a file each time the mouse moves, I'd suggest to read the data in the form_load event into an array.
    how to make the data in array?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: array data

    [QUOTE]

    Private Sub Picture_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Picture.ToolTipText="PixelX " & CStr(x) &" PixelY" & Cstr(y)
    End Sub

    [QUOTE]

    Do you mean add this code into the milk's code?

  10. #10
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: array data

    with this code I was able to see some depth data:
    Code:
    Dim PicHght As Long 'the height of your picturebox
    Dim PicWdth As Long 'the width of your picturebox
    Dim MapHght As Double 'the height of your map
    Dim MapWdth As Double 'the width of your picturebox
    Dim Map0X As Double 'the maximum X or width of your map
    Dim Map0Y As Double 'the maximum Y or height of your map
    Dim arrDepth(1000, 1000) As Single
    
    Private Sub Form_load()
    Dim filenr As Long
    Dim filename As String
    Dim data As String
    Dim i As Integer
    Dim j As Integer
    Dim latitude As Single
    Dim longitude As Single
    Dim depth As Single
    With Picture1
              .AutoRedraw = True
              .ScaleMode = vbPixels
              PicHght = .ScaleHeight
              PicWdth = .ScaleWidth
         End With
         Map0X = 101.46667
         Map0Y = 2.85667
         MapWdth = 99.7 - Map0X
         MapHght = 4.01666 - Map0Y
    filenr = FreeFile
    'put your filepath in here!!!!
    filename = "C:\XXX\depth.txt"
    Open filename For Input As filenr
    
    Do
    Input #filenr, data
    longitude = CSng(Left(data, InStr(1, data, " ") - 1))
    data = Mid(data, InStr(1, data, " ") + 1)
    latitude = CSng(Left(data, InStr(1, data, ";") - 1))
    data = Mid(data, InStr(1, data, ";") + 1)
    depth = CSng(data)
    arrDepth(GetX(longitude), GetY(latitude)) = depth
    Loop Until EOF(filenr)
    Close filenr
    
    End Sub
    Private Function GetLatitude(Y As Single) As Double
     GetLatitude = Round((Y * MapHght / PicHght) + Map0Y, 5)
    End Function
    
    Private Function GetLongitude(X As Single) As Double
     GetLongitude = Round((X * MapWdth / PicWdth) + Map0X, 5)
    End Function
    
    Private Function GetY(latitude As Single) As Long
     GetY = (latitude - Map0Y) * PicHght / MapHght
    End Function
    
    Private Function GetX(longitude As Single) As Long
     GetX = (longitude - Map0X) * PicWdth / MapWdth
    End Function
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Picture1.ToolTipText = "x=" & CStr(X) & " y=" & CStr(Y) & "Lat=" & CStr(GetLatitude(Y)) & " Long=" & CStr(GetLongitude(X)) & " Depth: " & CStr(arrDepth(X, Y))
    
    End Sub
    Remember to use your filepath!

    note only those Pixelspots that have an entry in your file will show a depth value! All other (and that are the most) won't!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  11. #11

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: array data

    opus, i have try your code. when i used "sample.txt" file.it can work. But, when i used another text.file(output.txt - i hv attach the file).it came out an error "invalid procedure call or argument" and highlight the line

    longitude = CSng(Left(data, InStr(1, data, " ") - 1)). Why???
    Attached Files Attached Files

  12. #12
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: array data

    Can't tell you why you get this error, you should look up the value of each var at the point of error. Especially what is the value of "data". Does the error occur on the first line of output.txt? If the error is an unwanted value of "data" [my guess is that data has no psace in it like "100"], you have to play arround with the string manipulation.
    I didn't put any error-catching in the code giving (that's something you can do!)

    Since the original question should be answered, you could close this thread!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

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



Click Here to Expand Forum to Full Width