[RESOLVED] Reading .ov2 (TomTom files)
Hi,
I've found an .ov2 parser, but it has been abandoned by the developer a few years ago. Can't find him unfortunately. Tried to convert it to VB.NET without any luck. Perhaps there's a way without the dll, but....
I can't get it to work and was wondering if someone here knows.
Code:
ReadOV2(Application.StartupPath & "\test.ov2")
Error 1 Reference to a non-shared member requires an object reference. (Readov2)
Imported everything, but no luck here.
Can't attach the dll, so I included the source:
Re: Reading .ov2 (TomTom files)
Re: Reading .ov2 (TomTom files)
1 Attachment(s)
Re: Reading .ov2 (TomTom files)
Here's a conversion to vb.net that I did. There aren't any compile errors but I don't really have any data to test it against.
Re: Reading .ov2 (TomTom files)
Will test it 2morrow m8 and see if it works. If you want to I can send you the ov2 I'm using.
1 Attachment(s)
Re: Reading .ov2 (TomTom files)
Thanks m8. Will have a look at it 2morrow. I believe my flue is getting back at me. Headache is starting. Time for bed. I've attached an ov2 for you.
Re: Reading .ov2 (TomTom files)
Ola Matt,
1) created a new ClassLib;
2) imported your classes;
The following Errors Occur:
Error 1 'ReadOnly' variable cannot be the target of an assignment. Line 19 col 13 OV2Parser
Error 2 Option Strict On disallows implicit conversions from 'Long' to 'Integer'. Line 49 col 48 OV2Parser
Error 3 Overload resolution failed because no accessible 'Read' can be called with these arguments:
'Public Overridable Function Read(buffer() As Byte, index As Integer, count As Integer) As Integer': Option Strict On disallows implicit conversions from 'Long' to 'Integer'.
'Public Overridable Function Read(buffer() As Char, index As Integer, count As Integer) As Integer': Value of type '1-dimensional array of Byte' cannot be converted to '1-dimensional array of Char' because 'Byte' is not derived from 'Char'.
'Public Overridable Function Read(buffer() As Char, index As Integer, count As Integer) As Integer': Option Strict On disallows implicit conversions from 'Long' to 'Integer'. Line 50 col 13 OV2Parser
Warning 4 Function 'SerializeRectangle' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. Line 301 col 5 OV2Parser
Warning 5 Function 'SerializeSimplePOI' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. Line 356 col 5 OV2Parser
Error 2/3 isn't interesting cause I fixed it easily, but the rest not.
Code:
Dim bytesRead As Byte() = New Byte(CInt(br.BaseStream.Length - 1)) {}
br.Read(bytesRead, 0, CInt(br.BaseStream.Length))
EDIT: added "Return returnByte" in the 2 functions, no warnings anymore.
Re: Reading .ov2 (TomTom files)
I remove the "readonly" and compiled it.
Works great, but I'd really like to to know how to loop through the ov2 to return all the values.
There are 4 values you can grab from the ov2: Lat/Long/Name/Telephone. I would like to list them something like:
1 lat, long, name, telephone
2 lat, long, name, telephone
Re: Reading .ov2 (TomTom files)
Hé Matt. Got some time?
Trying to loop through the file, but I can't get it correct.
vb.net Code:
dim filepath as string "C:\test.ov2"
debug.print(readov2(filepath)(1).lat.tostring)
debug.print(readov2(filepath)(1).long.tostring)
debug.print(readov2(filepath)(1).name.tostring)
' 1 = (index as integer) as ov2parser.poi
How do I loop through the file?
for each x as integer in ...... ???
Thanks in advance.
Re: Reading .ov2 (TomTom files)
vb.net Code:
Dim filePath As String = "C:\Temp\test.ov2"
Dim poiList = OV2Parser.ReadOV2(filePath)
From there you can loop through the List(Of POI) and get your values.
vb.net Code:
For i = 0 To poiList.Count - 1
Console.WriteLine(String.Format("{0} {1}", i, poiList(i).ToString()))
Next
And there are 5 values you can get for each point of interest Lat/Long/Name/Telephone/ExtendedData.
I would recommend overriding the ToString method of the POI class to make it easy for you.
vb.net Code:
Public Class POI
Public Property Name As String
Public Property ExtendedData As String
Public Property Lat As Double
Public Property [Long] As Double
Public Property Telephone As String
Public Overrides Function ToString() As String
If Me.ExtendedData IsNot Nothing Then
Return String.Format("{0}, {1}, {2}, {3}, {4}", Lat.ToString(), [Long].ToString(), Name, Telephone, ExtendedData)
Else
Return String.Format("{0}, {1}, {2}, {3}", Lat.ToString(), [Long].ToString(), Name, Telephone)
End If
End Function
End Class
Edit: & oops on the Option Strict errors. Switched to VS11 and hadn't changed the setting yet.
Re: Reading .ov2 (TomTom files)
Ola Matt,
Thanks, but somehow I don't get it. (can't find the lightswitch)
vb.net Code:
Dim poiList As List(Of OV2Parser.POI) = ReadOV2(filepath)
For each x as integer in .... (poiList not working)
Re: Reading .ov2 (TomTom files)
Here's POI.vb with the changes to ToString().
vb.net Code:
Public Class POI
Public Property Name As String
Public Property ExtendedData As String
Public Property Lat As Double
Public Property [Long] As Double
Public Property Telephone As String
Public Overrides Function ToString() As String
If Me.ExtendedData IsNot Nothing Then
Return String.Format("{0}, {1}, {2}, {3}, {4}", Lat.ToString(), [Long].ToString(), Name, Telephone, ExtendedData)
Else
Return String.Format("{0}, {1}, {2}, {3}", Lat.ToString(), [Long].ToString(), Name, Telephone)
End If
End Function
End Class
Here's my code to get the List(Of POI) and iterate through it. From your code it looks like you missed that ReadOV2 is a shared method.
vb.net Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim filePath As String = "C:\Temp\test.ov2"
Dim poiList As List(Of POI) = OV2Parser.ReadOV2(filePath)
For i = 0 To poiList.Count - 1
Console.WriteLine(String.Format("{0} {1}", i, poiList(i).ToString()))
Next
End Sub
End Class
Re: Reading .ov2 (TomTom files)
Thanks m8. The modification wasn't needed for my case, but it works like a charm.