Solved

Using PHP to parse a text file and return a 'route' in Google Earth kml

Posted on 2007-12-06
5
715 Views
Last Modified: 2008-02-24
I am a noob trying to parse a basic text file and create a kml file.  I have seen this done with MySQL etc and the examples on google, but to be honest I want to avoid using a database to keep it portable.

I have seen lots of code examples for Google Earth, but not any that create a 'route' just ones that create points on the map.

In the code snippet I am trying to extract the following from the V records:
510949.54N 120108.50W (This would be 51°09'49.54"N, I am still confused about when it goes above 100, but get to that later....)

Latitude    (d.m.s. N/S)            26-35
Longitude (d.m.s. E/W)            36-46

Any help much appreciated.  I just need some ideas to get me going then I am sure I will get the hang of it..

Thanks,

Mark
V005A002        1    1001510949.54N 120108.50W 708426.45672377.31453.8202100643 

Z005A002        1    1001510950.24N 120107.11W 708452.65672400.11453.8202100643 

T005A002        1 1  1001511305.45N 115358.70W 716516.95678772.91453.8202100643 

S005A002        11   1001510951.74N 120102.79W 708534.65672450.01453.8202100643 

C005A002        111  1001510953.66N 120058.95W 708606.75672512.31453.8202100643 

R   1 708678.85672574.5 8.2                                                    1

V005A002        1    1002510949.03N 120109.89W 708400.15672360.41453.3202100658 

Z005A002        1    1002510949.76N 120108.54W 708425.45672384.11453.3202100658 

T005A002        1 1  1002511304.92N 115400.05W 716491.45678755.31453.3202100658 

S005A002        11   1002510951.27N 120104.22W 708507.45672434.21453.3202100658 

C005A002        111  1002510953.18N 120100.37W 708579.65672496.11453.3202100658 

R   1 708651.95672558.1 8.2                                                    1

V005A002        1    1003510948.48N 120111.23W 708374.85672342.41452.5202100713 

Z005A002        1    1003510949.24N 120109.92W 708399.25672367.11452.5202100713 

T005A002        1 1  1003511304.34N 115401.35W 716467.05678736.61452.5202100713 

S005A002        11   1003510950.80N 120105.65W 708480.15672418.71452.5202100713 

C005A002        111  1003510952.68N 120101.78W 708552.95672479.81452.5202100713 

R   1 708625.75672541.0 8.1                                                    1

V005A002        1    1004510947.95N 120112.59W 708349.05672325.01452.3202100728 

Z005A002        1    1004510948.70N 120111.27W 708373.75672349.31452.3202100728 

T005A002        1 1  1004511303.79N 115402.67W 716442.15678718.61452.3202100728 

S005A002        11   1004510950.33N 120107.07W 708453.35672403.11452.3202100728 

C005A002        111  1004510952.18N 120103.16W 708526.85672463.21452.3202100728 

R   1 708600.35672523.3 8.1                                                    1

V005A002        1    1005510947.40N 120113.95W 708323.35672306.91452.1202100742 

Z005A002        1    1005510948.15N 120112.63W 708348.05672331.31452.1202100742 

T005A002        1 1  1005511303.24N 115404.00W 716416.95678700.21452.1202100742 

S005A002        11   1005510949.82N 120108.47W 708426.75672386.21452.1202100742 

C005A002        111  1005510951.64N 120104.54W 708500.75672445.51452.1202100742

Open in new window

0
Comment
Question by:marky9074
  • 4
5 Comments
 

Author Comment

by:marky9074
ID: 20418070
I forgot to say that somewhere I need to convert this format into decimal degrees for GE
0
 

Author Comment

by:marky9074
ID: 20418087
OK, I realised what happens at 100, the space that is seen in the code is used for the extra digit....dooh!
0
 

Author Comment

by:marky9074
ID: 20420842
OK, I have had a play manually extracting the fields in excel and creating the xml code which seems to work ok in google maps and google earth.

It would seem best to keep appending the file with <placemark> events every time a new file is parsed (because then I can use it in google maps).....but this means I will end up with a large file...
<?xml version="1.0" encoding="UTF-8"?>

<kml xmlns="http://earth.google.com/kml/2.2">

  <Document>

    <name>Providence Resources Dunquin 2D 2006</name>

    <description>2D Seismic Post Plot</description>

    <Style id="BrownLine">

      <LineStyle>

        <color>7d000080</color>

        <width>1</width>

      </LineStyle>

    </Style>

    <Placemark>

      <name>001A003</name>

      <description>Prime Line</description>

      <styleUrl>#BrownLine</styleUrl>

      <LineString>

        <coordinates>

-12.296289,51.039664

-12.296533,51.039900

-12.296797,51.040128

-12.297067,51.040350

-12.297328,51.040578

-12.297575,51.040808

</coordinates>

      </LineString>

    </Placemark>

  </Document>

</kml>

Open in new window

0
 

Author Comment

by:marky9074
ID: 20427200
OK, I used this perl script in cygwin to strip out what I need from the files...


#!/usr/bin/perl -w
 

while ( <> )

{

	if ( /^V/ )

	{

		$latitude = substr($_,25,10);

		$longitude = substr($_,35,11);
 

		print "$longitude,$latitude\n";

	}

}

Open in new window

0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 20968135
uge,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now