Extrapolate from NMEA file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a file with thousands of these lines:


I must capture ONE line EVERY 10 LINES but only a block of 200 lines
with the first columns begin with $GPGGA.

I must to extrapolate the [column3] and the [column5]
I must write new file with the rows like these:


and so on

$fp = fopen("newfile.txt", "a");

can you help me ?

Re: Extrapolate from NMEA file

What have you unsuccessfully tried so far?


Re: Extrapolate from NMEA file

Hi Samuel,

thanks for your answer and sorry for my bad english.
Up to now I have stopped myself where you have read.
I do not have familiarity with the PHP language, but I must process the
GPS log.
I search someone that can help me to do this.

Re: Extrapolate from NMEA file

Hi Maggy,

If I understand you correctly, then the following pseudocode might be a
starting point



line_count=9 (assuming that you want the first line to count)

Open input file
Open output file

Do while not EOF
    Read line from input file
    Split line into an array
    If col_1 is '$GPGGA'
        Add 1 to line_count
        If line count >9
            write data to output file
            set line_count to 0
        end if
    end if

At this point, if you want to capture the last record even if it's noth
the tenth one
    if line_count <> 0 write data to output files

Close files

Re: Extrapolate from NMEA file

You have understand correctly the concept of my request, but now, I
don't know how can continue and this afternoon is been born a new
It must add also one conversion of column 3 and 5 of $GPGGA lines:
the value 4438.6259 will be convert in 44.38625 (latitude)


Re: Extrapolate from NMEA file

Quoted text here. Click to load it

Hm, you'll need to read some things. Here's a handful of things that
may help you. Just search for these keywords in php.net and it should
be easy to learn some stuff and go from there...

- file system
- array
- strings


Re: Extrapolate from NMEA file

cuba1@virgilio.it wrote:
Quoted text here. Click to load it

I didn't realy understand what did you say but this is what could i
write from Ian B pseudo-code:

$file1 = fopen("input.txt", "r");
$file2 = fopen("output.txt", "w");

// read every line (until EOF) and split it wiht space
while (($data = fgetcsv($file1, 1000, " ")) !== FALSE) {
    if($data[0] == '$GPGGA'){
    if($row >= 10){
        // Write output if got more than 10 lines
        fwrite($file2, "Point($data[4],$data[2]\n");

Site Timeline