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?
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
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.
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!
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.
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!
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
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!
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
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!