<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog of Travis Hydzik &#187; Geocaching</title>
	<atom:link href="http://thydzik.com/category/geocaching/feed/" rel="self" type="application/rss+xml" />
	<link>http://thydzik.com</link>
	<description>random snippets and information</description>
	<lastBuildDate>Mon, 30 Apr 2012 15:46:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Convert from Google KML to GPS Exchange Format GPX with PHP</title>
		<link>http://thydzik.com/convert-from-google-kml-to-gps-exchange-format-gpx/</link>
		<comments>http://thydzik.com/convert-from-google-kml-to-gps-exchange-format-gpx/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 17:58:50 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Geocaching]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[GPX]]></category>
		<category><![CDATA[KML]]></category>
		<category><![CDATA[Map]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=740</guid>
		<description><![CDATA[Here is a quick post on converting from KML files used in Google Earth/Maps to GPX Exchange Format (GPX) with PHP. Code is quite explanatory, change $u with the location of the KML file, code will output GPX XML. Alternatively, download the code here. Let me know if you find any issues.<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/convert-from-google-kml-to-gps-exchange-format-gpx/' addthis:title='Convert from Google KML to GPS Exchange Format GPX with PHP ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Here is a quick post on converting from KML files used in Google Earth/Maps to GPX Exchange Format (GPX) with PHP.</p>
<p>Code is quite explanatory, change <em>$u</em> with the location of the KML file, code will output GPX XML.</p>
<p><a href="http://thydzik.com/downloads/kml-to-gpx.php.txt" title="Download PHP code to covert KML to GPX" target="_blank">Alternatively, download the code here.</a></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	//enter location of KML file here
	$u = &quot;http://code.google.com/apis/kml/documentation/KML_Samples.kml&quot;;

	function utcdate() {
		return gmdate(&quot;Y-m-d\Th:i:s\Z&quot;);
	}

	$u_parts = pathinfo($u); //array of url parts
	$u_ext = strtoupper($u_parts['extension']);
	if ($u_ext== &quot;KML&quot;) {

		$dom_kml = new DOMDocument();
		$dom_kml-&gt;load($u);

		$dom_gpx = new DOMDocument('1.0', 'UTF-8');
		$dom_gpx-&gt;formatOutput = true;

		//root node
		$gpx = $dom_gpx-&gt;createElement('gpx');
		$gpx = $dom_gpx-&gt;appendChild($gpx);

		$gpx_version = $dom_gpx-&gt;createAttribute('version');
		$gpx-&gt;appendChild($gpx_version);
		$gpx_version_text = $dom_gpx-&gt;createTextNode('1.0');
		$gpx_version-&gt;appendChild($gpx_version_text);

		$gpx_creator = $dom_gpx-&gt;createAttribute('creator');
		$gpx-&gt;appendChild($gpx_creator);
		$gpx_creator_text = $dom_gpx-&gt;createTextNode('http://thydzik.com');
		$gpx_creator-&gt;appendChild($gpx_creator_text);

		$gpx_xmlns_xsi = $dom_gpx-&gt;createAttribute('xmlns:xsi');
		$gpx-&gt;appendChild($gpx_xmlns_xsi);
		$gpx_xmlns_xsi_text = $dom_gpx-&gt;createTextNode('http://www.w3.org/2001/XMLSchema-instance');
		$gpx_xmlns_xsi-&gt;appendChild($gpx_xmlns_xsi_text);

		$gpx_xmlns = $dom_gpx-&gt;createAttribute('xmlns');
		$gpx-&gt;appendChild($gpx_xmlns);
		$gpx_xmlns_text = $dom_gpx-&gt;createTextNode('http://www.topografix.com/GPX/1/0');
		$gpx_xmlns-&gt;appendChild($gpx_xmlns_text);

		$gpx_xsi_schemaLocation = $dom_gpx-&gt;createAttribute('xsi:schemaLocation');
		$gpx-&gt;appendChild($gpx_xsi_schemaLocation);
		$gpx_xsi_schemaLocation_text = $dom_gpx-&gt;createTextNode('http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd');
		$gpx_xsi_schemaLocation-&gt;appendChild($gpx_xsi_schemaLocation_text);

		$gpx_url = $dom_gpx-&gt;createElement('url');
		$gpx_url = $gpx-&gt;appendChild($gpx_url);
		$gpx_url_text = $dom_gpx-&gt;createTextNode($u_parts['dirname']);
		$gpx_url-&gt;appendChild($gpx_url_text);

		$gpx_time = $dom_gpx-&gt;createElement('time');
		$gpx_time = $gpx-&gt;appendChild($gpx_time);
		$gpx_time_text = $dom_gpx-&gt;createTextNode(utcdate());
		$gpx_time-&gt;appendChild($gpx_time_text);

		// placemarks
		$names = array();
		foreach ($dom_kml-&gt;getElementsByTagName('Placemark') as $placemark) {
			//name
			foreach ($placemark-&gt;getElementsByTagName('name') as $name) {
				$name  = $name-&gt;nodeValue;
				//check if the key exists
				if (array_key_exists($name, $names)) {
					//increment the value
					++$names[$name];
					$name = $name.&quot; ({$names[$name]})&quot;;
				} else {
					$names[$name] = 0;
				}
			}
			//description
			foreach ($placemark-&gt;getElementsByTagName('description') as $description) {
				$description  = $description-&gt;nodeValue;
			}
			foreach ($placemark-&gt;getElementsByTagName('Point') as $point) {
				foreach ($point-&gt;getElementsByTagName('coordinates') as $coordinates) {
					//add the marker
					$coordinate = $coordinates-&gt;nodeValue;
					$coordinate = str_replace(&quot; &quot;, &quot;&quot;, $coordinate);//trim white space
					$latlng = explode(&quot;,&quot;, $coordinate);

					if (($lat = $latlng[1]) &amp;&amp; ($lng = $latlng[0])) {
						$gpx_wpt = $dom_gpx-&gt;createElement('wpt');
						$gpx_wpt = $gpx-&gt;appendChild($gpx_wpt);

						$gpx_wpt_lat = $dom_gpx-&gt;createAttribute('lat');
						$gpx_wpt-&gt;appendChild($gpx_wpt_lat);
						$gpx_wpt_lat_text = $dom_gpx-&gt;createTextNode($lat);
						$gpx_wpt_lat-&gt;appendChild($gpx_wpt_lat_text);

						$gpx_wpt_lon = $dom_gpx-&gt;createAttribute('lon');
						$gpx_wpt-&gt;appendChild($gpx_wpt_lon);
						$gpx_wpt_lon_text = $dom_gpx-&gt;createTextNode($lng);
						$gpx_wpt_lon-&gt;appendChild($gpx_wpt_lon_text);

						$gpx_time = $dom_gpx-&gt;createElement('time');
						$gpx_time = $gpx_wpt-&gt;appendChild($gpx_time);
						$gpx_time_text = $dom_gpx-&gt;createTextNode(utcdate());
						$gpx_time-&gt;appendChild($gpx_time_text);

						$gpx_name = $dom_gpx-&gt;createElement('name');
						$gpx_name = $gpx_wpt-&gt;appendChild($gpx_name);
						$gpx_name_text = $dom_gpx-&gt;createTextNode($name);
						$gpx_name-&gt;appendChild($gpx_name_text);

						$gpx_desc = $dom_gpx-&gt;createElement('desc');
						$gpx_desc = $gpx_wpt-&gt;appendChild($gpx_desc);
						$gpx_desc_text = $dom_gpx-&gt;createTextNode($description);
						$gpx_desc-&gt;appendChild($gpx_desc_text);

						//$gpx_url = $dom_gpx-&gt;createElement('url');
						//$gpx_url = $gpx_wpt-&gt;appendChild($gpx_url);
						//$gpx_url_text = $dom_gpx-&gt;createTextNode($ref);
						//$gpx_url-&gt;appendChild($gpx_url_text);

						$gpx_sym = $dom_gpx-&gt;createElement('sym');
						$gpx_sym = $gpx_wpt-&gt;appendChild($gpx_sym);
						$gpx_sym_text = $dom_gpx-&gt;createTextNode('Waypoint');
						$gpx_sym-&gt;appendChild($gpx_sym_text);
					}
				}
			}
			foreach ($placemark-&gt;getElementsByTagName('LineString') as $lineString) {
				foreach ($lineString-&gt;getElementsByTagName('coordinates') as $coordinates) {
					//add the new track
					$gpx_trk = $dom_gpx-&gt;createElement('trk');
					$gpx_trk = $gpx-&gt;appendChild($gpx_trk);

					$gpx_name = $dom_gpx-&gt;createElement('name');
					$gpx_name = $gpx_trk-&gt;appendChild($gpx_name);
					$gpx_name_text = $dom_gpx-&gt;createTextNode($name);
					$gpx_name-&gt;appendChild($gpx_name_text);

					$gpx_trkseg = $dom_gpx-&gt;createElement('trkseg');
					$gpx_trkseg = $gpx_trk-&gt;appendChild($gpx_trkseg);

					$coordinates = $coordinates-&gt;nodeValue;
					$coordinates = preg_split(&quot;/[\s\r\n]+/&quot;, $coordinates); //split the coords by new line
					foreach ($coordinates as $coordinate) {
						$latlng = explode(&quot;,&quot;, $coordinate);

						if (($lat = $latlng[1]) &amp;&amp; ($lng = $latlng[0])) {
							$gpx_trkpt = $dom_gpx-&gt;createElement('trkpt');
							$gpx_trkpt = $gpx_trkseg-&gt;appendChild($gpx_trkpt);

							$gpx_trkpt_lat = $dom_gpx-&gt;createAttribute('lat');
							$gpx_trkpt-&gt;appendChild($gpx_trkpt_lat);
							$gpx_trkpt_lat_text = $dom_gpx-&gt;createTextNode($lat);
							$gpx_trkpt_lat-&gt;appendChild($gpx_trkpt_lat_text);

							$gpx_trkpt_lon = $dom_gpx-&gt;createAttribute('lon');
							$gpx_trkpt-&gt;appendChild($gpx_trkpt_lon);
							$gpx_trkpt_lon_text = $dom_gpx-&gt;createTextNode($lng);
							$gpx_trkpt_lon-&gt;appendChild($gpx_trkpt_lon_text);

							$gpx_time = $dom_gpx-&gt;createElement('time');
							$gpx_time = $gpx_trkpt-&gt;appendChild($gpx_time);
							$gpx_time_text = $dom_gpx-&gt;createTextNode(utcdate());
							$gpx_time-&gt;appendChild($gpx_time_text);
						}
					}
				}
			}
		}
		header(&quot;Content-Type: text/xml&quot;);
		echo $dom_gpx-&gt;saveXML();
	}
?&gt;
</pre>
<p>Let me know if you find any issues.</p>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/convert-from-google-kml-to-gps-exchange-format-gpx/' addthis:title='Convert from Google KML to GPS Exchange Format GPX with PHP ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/convert-from-google-kml-to-gps-exchange-format-gpx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Karratha Geocaches (Pilbara, Western Australia)</title>
		<link>http://thydzik.com/karratha-geocaches-pilbara-western-australia/</link>
		<comments>http://thydzik.com/karratha-geocaches-pilbara-western-australia/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 01:50:05 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Geocaching]]></category>
		<category><![CDATA[thydzik Google Map]]></category>
		<category><![CDATA[Karratha]]></category>
		<category><![CDATA[RoboGeo]]></category>
		<category><![CDATA[Western Australia]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.thydzik.com/?p=46</guid>
		<description><![CDATA[From time to time I would like to share some of my Australian travels. It doesn&#8217;t really fit in technology or projects. Karratha is 1535km north of Perth, Western Australia. The XML for the map below was made with RoboGEO, which synchronises GPS data with photographs using the timestamp. The XML map data was then [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/karratha-geocaches-pilbara-western-australia/' addthis:title='Karratha Geocaches (Pilbara, Western Australia) ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>From time to time I would like to share some of my Australian travels. It doesn&#8217;t really fit in technology or projects. Karratha is 1535km north of Perth, Western Australia.</p>
<p>The XML for the map below was made with <a title="RoboGeo site" href="http://www.robogeo.com/" target="_blank">RoboGEO</a>, which synchronises GPS data with photographs using the timestamp. The XML map data was then displayed as a Google map using my WordPress plugin <a title="thydzikGoogleMap Plugin Directory" href="http://wordpress.org/extend/plugins/thydzik-google-map/" target="_blank">thydzikGoogleMap</a>.</p>
<p>One of the features of thydzikGoogleMap is the ability to show XML Google maps, while maintaining the internal links to photographs.</p>
<!--thydzikgooglemap-->
<div class='tgm_div' id='map46n1' style='width: 460px; height: 345px'></div>
<script type='text/javascript'>
google.maps.event.addDomListener(window, 'load', function () {thydzikgm('map46n1', 'aHR0cDovL3RoeWR6aWsuY29tL2dlb2NhY2hpbmcva2FycmF0aGEtbWFyMDgva2FycmF0aGEtbWFyMDgueG1s', -1, 'ROADMAP', 1, 'XML'); });
</script>
<!--/thydzikgooglemap-->

<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/karratha-geocaches-pilbara-western-australia/' addthis:title='Karratha Geocaches (Pilbara, Western Australia) ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/karratha-geocaches-pilbara-western-australia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Object Caching 575/577 objects using disk: basic
Content Delivery Network via t01.thydzik.com

Served from: thydzik.com @ 2012-05-18 14:52:38 -->
