Location: PHPKode > projects > AppForMap > appformap/libs/php_gpxtopgsql_class.php
<?
/* This notice must be untouched at all times.

phpgeometry class v. 0.6
The latest version is available at
http://sourceforge.net/projects/appformap/

Copyright (c) 2005 Martin Høgh. All rights reserved.
Created 28. 1. 2005 by Martin Høgh <hide@address.com>

Php class library. Creates geometry object from Well-known Text Representation or gml.
The class's have operations for manipulating the geometry and getting various types of information.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

See the GNU General Public License
at http://www.gnu.org/copyleft/gpl.html for more details.
*/
class gpxConverter
{
	var $parser;
	var $geomType;
	var $wkt;
	var $wktCoords;
	var $splitTag;
	var $srid;
	var $lat;
	var $lon;
	var $ele;
	var $time;
	var $_name;
	var $sym;
	var $type;
	var $trknum;
	var $trksegnum;
	var $rtenum;
	var $magvar;
	var $geoidheight;
	var $src;
	var $link;
	var $sym;
	var $type;
	var $fix;
	var $sat;
	var $hdop;
	var $vdop;
	var $pdop;
	var $ageofdgpsdata;
	var $dgpsid;
	var $number;
	var $desc;
	var $cmt;
	var $wptTrkId;
	var $wptTrksegId;
	var $wptRteId;
	var $rteName;
	var $rteNameNotArray;
	var $rteNum;
	var $rteNumNotArray;
	var $trkName;
	var $trkNameNotArray;
	var $trkNum;
	var $trkNumNotArray;
	var $rteLineStr;
	var $trkLineStr;
	var $trkDesc;
	var $trkDescNotArray;
	var $rteDesc;
	var $rteDescNotArray;
	var $trkCmt;
	var $trkCmtNotArray;
	var $rteCmt;
	var $rteCmtNotArray;
	var $trkType;
	var $trkTypeNotArray;
	var $rteType;
	var $rteTypeNotArray;
	var $trkLink;
	var $trkLinkNotArray;
	var $rteLink;
	var $rteLinkNotArray;
	var $trkSrc;
	var $trkSrcNotArray;
	var $rteSrc;
	var $rteSrcNotArray;
	var $idOffSet;

	function gpxConverter()
	{
		$this->trknum=0;
		$this->trksegnum=0;

		$this->xml();
	}
	function xml()
	{
		$this -> parser = xml_parser_create();
		xml_set_object($this -> parser, & $this);
		xml_set_element_handler($this -> parser, "startElement", "endElement");
		xml_set_character_data_handler($this -> parser, "characterData");}
		/**
		* @return array
		* @param string $gml
		* @param string $splitTag
		* @desc Enter description here...
		*/
		function gpxToPgsql($gpx,$splitTag,$idOffSet=0,$srid=4326)
		{
			global $count;

			$this->rtenum=$idOffSet;
			$this->trknum=$idOffSet;
			$this->srid=$srid;
			$this->idOffSet=$idOffSet;
			$this->splitTag=strtoupper($splitTag);
			$count=$this->idOffSet;
			$currentTag = "";
			xml_parse($this -> parser, $gpx);
			// clean up
			xml_parser_free($this -> parser);

		}
		function startElement($parser, $name, $attrs)
		{
			global $currentTag;	//used by function characterData when parsing xml data
			global $count;
			global $_rte;
			global $_trk;
			global $go;
			global $checkTrkSeg;
			$currentTag = $name;
			//echo $count;
			if ($this->splitTag==$currentTag) {
				$go=true;
				$this->trkLineStr[$count]="";
				$this->rteLineStr[$count]="";
				$this->hdop[$count]="";
				$this->vdop[$count]="";
				$this->sym[$count]="";
				$this->type[$count]="";
				$this->magvar[$count]="";
				$this->geoidheight[$count]="";
				$this->src[$count]="";
				$this->link[$count]="";
				$this->sym[$count]="";
				$this->type[$count]="";
				$this->fix[$count]="";
				$this->sat[$count]="";
				$this->time[$count]="";
				$this->cmt[$count]="";
				$this->desc[$count]="";
				$this->pdop[$count]="";
				$this->ageofgpsdata[$count]="";
				$this->dgpsid[$count]="";



			}

			switch ($currentTag)
			{


				case "WPT" :
				$this->lat[$count]=$attrs['LAT'];
				$this->lon[$count]=$attrs['LON'];
				$_rte=false;
				$_trk=false;
				break;
				case "RTEPT" :
				$this->lat[$count]=$attrs['LAT'];
				$this->lon[$count]=$attrs['LON'];
				$this->wptRteId[$count]=$this->rtenum;
				$this->rteName[$count]=$this->rteNameNotArray;
				$this->rteNum[$count]=$this->rteNumNotArray;
				$this->rteDesc[$count]=$this->rteDescNotArray;
				$this->rteCmt[$count]=$this->rteCmtNotArray;
				$this->rteType[$count]=$this->rteTypeNotArray;
				$this->rteLink[$count]=$this->rteLinkNotArray;
				$this->rteSrc[$count]=$this->rteSrcNotArray;
				$this->rteLineStr[$count].=",".$attrs['LON']." ".$attrs['LAT'];
				$_rte=false;
				break;
				case "TRKPT" :
				$this->lat[$count]=$attrs['LAT'];
				$this->lon[$count]=$attrs['LON'];
				$this->wptTrkId[$count]=$this->trknum;
				$this->wptTrksegId[$count]=$this->trksegnum;
				$this->trkName[$count]=$this->trkNameNotArray;
				$this->trkNum[$count]=$this->trkNumNotArray;
				$this->trkDesc[$count]=$this->trkDescNotArray;
				$this->trkCmt[$count]=$this->trkCmtNotArray;
				$this->trkType[$count]=$this->trkTypeNotArray;
				$this->trkLink[$count]=$this->trkLinkNotArray;
				$this->trkSrc[$count]=$this->trkSrcNotArray;
				if ($checkTrkSeg) $seperator="),(";
				else $seperator=",";
				$checkTrkSeg=false;
				$this->trkLineStr[$count].=$seperator.$attrs['LON']." ".$attrs['LAT'];
				$seperator=",";
				$_trk=false;
				break;
				case "RTE" :
				$_rte=true;
				$_trk=false;
				break;
				case "TRK" :
				$_trk=true;
				$_rte=false;
				break;


			}
		}
		function endElement($parser, $name)
		{
			global $currentTag;
			global $count;
			global $checkTrkSeg;
			global $_rte;
			global $_trk;
			global $go;
			$currentTag=$name;
			//if ($this->splitTag==$currentTag) $go=false;

			//echo $currentTag;
			switch ($currentTag)
			{
				case $this->splitTag :
				$count++;
				if ($this->splitTag=="TRK")
				{
					$this->trkNumNotArray="";
					$this->trkDescNotArray="";
					$this->trkCmtNotArray="";
					$this->trkNameNotArray="";
					$this->trkTypeNotArray="";
					$this->trkLinkNotArray="";
					$this->trkSrcNotArray="";
				}
				if ($this->splitTag=="RTE")
				{
					$this->rteNumNotArray="";
					$this->rteDescNotArray="";
					$this->rteCmtNotArray="";
					$this->rteNameNotArray="";
					$this->rteTypeNotArray="";
					$this->rteLinkNotArray="";
					$this->rteSrcNotArray="";
				}
				break;
				case "TRK" :
				$this->trknum++;
				$this->trksegnum=0;
				$this->trkNumNotArray="";
				$this->trkDescNotArray="";
				$this->trkCmtNotArray="";
				$this->trkNameNotArray="";
				$this->trkTypeNotArray="";
				$this->trkLinkNotArray="";
				$this->trkSrcNotArray="";
				break;
				case "RTE" :
				$this->rtenum++;
				$this->rteNumNotArray="";
				$this->rteDescNotArray="";
				$this->rteCmtNotArray="";
				$this->rteNameNotArray="";
				$this->rteTypeNotArray="";
				$this->rteLinkNotArray="";
				$this->rteSrcNotArray="";
				break;
				case "TRKSEG" :
				$this->trksegnum++;
				$checkTrkSeg=true;
				break;
				case "RTEPT" :
				$_rte=true;
				break;
				case "TRKPT" :
				$_trk=true;
				break;
			}
			$currentTag = null;


		}
		function characterData($parser, $data)
		{
			global $currentTag;
			global $count;
			global $_rte;
			global $_trk;
			global $go;

			switch ($currentTag)
			{
				case "ELE" :
				$this->ele[$count]=$data;
				break;
				case "TIME" :
				$this->time[$count]=$data;
				break;
				case "SYM" :
				$this->sym[$count]=$data;
				break;
				case "MAGVAR" :
				$this->magvar[$count]=$data;
				break;
				case "SAT" :
				$this->sat[$count]=$data;
				break;
				case "GEOIDHEIGHT" :
				$this->geoidheight[$count]=$data;
				break;
				case "GEOIDHEIGHT" :
				$this->geoidheight[$count]=$data;
				break;
				case "FIX" :
				$this->fix[$count]=$data;
				break;
				case "HDOP" :
				$this->hdop[$count]=$data;
				break;
				case "VDOP" :
				$this->vdop[$count]=$data;
				break;
				case "PDOP" :
				$this->pdop[$count]=$data;
				break;
				case "AGEOFGPSDATA" :
				$this->ageofgpsdata[$count]=$data;
				break;
				case "DGPSID" :
				$this->dgpsid[$count]=$data;
				break;
				case "TYPE" :
				if ($_rte) $this->rteTypeNotArray=$data;
				else if ($_trk) $this->trkTypeNotArray=$data;
				else $this->type[$count]=$data;
				break;
				case "LINK" :
				if ($_rte) $this->rteLinkNotArray=$data;
				else if ($_trk) $this->trkLinkNotArray=$data;
				else $this->link[$count]=$data;
				break;
				case "SRC" :
				if ($_rte) $this->rteSrcNotArray=$data;
				else if ($_trk) $this->trkSrcNotArray=$data;
				else $this->src[$count]=$data;
				break;
				case "NAME" :
				if ($_rte) $this->rteNameNotArray=$data;
				else if ($_trk) $this->trkNameNotArray=$data;
				else $this->_name[$count]=$data;
				break;
				case "NUMBER" :
				if ($_rte) $this->rteNumNotArray=$data;
				else if ($_trk) $this->trkNumNotArray=$data;
				else $this->number[$count]=$data;
				break;
				case "DESC" :
				if ($_rte) $this->rteDescNotArray=$data;
				else if ($_trk) $this->trkDescNotArray=$data;
				else $this->desc[$count]=$data;
				break;
				case "CMT" :
				if ($_rte) $this->rteCmtNotArray=$data;
				else if ($_trk) $this->trkCmtNotArray=$data;
				else $this->cmt[$count]=$data;
				break;
			}
			if (!$go)
			{
				$this->_name="";
				$this->time="";
				$this->sym="";
				$this->ele="";
				$this->desc="";
				$this->number="";
				$this->cmt="";
				$this->type="";
				$this->link="";
				$this->src="";

			}
		}
		function removeChars($verticeStr,$i=1)
		{
			$verticeStr=substr($verticeStr, $i, strlen($verticeStr) - 1);
			return($verticeStr);
		}
		function toHTML()
		{
			global $count;
			$firstInteration=false;
			echo "<table border=1>";
			if ($this->splitTag=="WPT")
			{

				for ($i=$this->idOffSet ; $i<$count ; $i++)
				{
					echo "<tr><td>typeid</td><td>ele</td><td>time</td><td>magvar</td><td>geoidheight</td><td>cmt</td><td>desc</td><td>src</td><td>link</td><td>sym</td><td>type</td><td>fix</td><td>sat</td><td>hdop</td><td>vdop</td><td>pdop</td><td>ageofdgpsdata</td><td>dgpsid</td><td>point</td></tr>";

					for ($i=$this->idOffSet; $i<$count ; $i++)
					{
						$point="point(".$this->lon[$i]." ".$this->lat[$i].")";
						echo "<tr><td>".$this->splitTag."</td><td>".$this->ele[$i]."</td><td>".$this->time[$i]."</td><td>".$this->magvar[$i]."</td><td>".$this->geoidheight[$i]."</td><td>".$this->cmt[$i]."</td><td>".$this->desc[$i]."</td><td>".$this->src[$i]."</td><td>".$this->link[$i]."</td><td>".$this->sym[$i]."</td><td>".$this->type[$i]."</td><td>".$this->fix[$i]."</td><td>".$this->sat[$i]."</td><td>".$this->hdop[$i]."</td><td>".$this->vdop[$i]."</td><td>".$this->pdop[$i]."</td><td>".$this->ageofdgpsdata[$i]."</td><td>".$this->dgpsid[$i]."</td><td>".$point."</td><tr>";
					}
				}
			}
			if ($this->splitTag=="RTE")
			{

				echo "<tr><td>id</td><td>typeid</td><td>name</td><td>cmt</td><td>desc</td><td>src</td><td>link</td><td>number</td><td>type</td><td>wkt</td></tr>";
				for ($i=$this->idOffSet ; $i<$count ; $i++)
				{
					$lineStr="multilinetring((".$this->removeChars($this->rteLineStr[$i])."))";

					echo "<tr><td>".$i."</td><td>".$this->splitTag."</td><td>".$this->rteName[$i]."</td><td>".$this->rteCmt[$i]."</td><td>".$this->rteDesc[$i]."</td><td>".$this->rteSrc[$i]."</td><td>".$this->rteLink[$i]."</td><td>".$this->rteNum[$i]."</td><td>".$this->rteType[$i]."</td><td>".$lineStr."</td><tr>";
				}
			}
			if ($this->splitTag=="TRK")
			{

				echo "<tr><td>id</td><td>typeid</td><td>name</td><td>cmt</td><td>desc</td><td>src</td><td>link</td><td>number</td><td>type</td><td>wkt</td></tr>";
				for ($i=$this->idOffSet ; $i<$count ; $i++)
				{
					if (!$firstInteration)
					$lineStr="multilinetring((".$this->removeChars($this->trkLineStr[$i])."))";
					else
					$lineStr="multilinetring((".$this->removeChars($this->trkLineStr[$i],3)."))";
					$firstInteration=true;

					echo "<tr><td>".$i."</td><td>".$this->splitTag."</td><td>".$this->trkName[$i]."</td><td>".$this->trkCmt[$i]."</td><td>".$this->trkDesc[$i]."</td><td>".$this->trkSrc[$i]."</td><td>".$this->trkLink[$i]."</td><td>".$this->trkNum[$i]."</td><td>".$this->trkType[$i]."</td><td>".$lineStr."</td><tr>";
				}
			}

			if ($this->splitTag=="RTEPT")
			{
				echo "<tr><td>id</td><td>typeid</td><td>nameid</td><td>numberid</td><td>ele</td><td>time</td><td>magvar</td><td>geoidheight</td><td>cmt</td><td>desc</td><td>src</td><td>link</td><td>sym</td><td>type</td><td>fix</td><td>sat</td><td>hdop</td><td>vdop</td><td>pdop</td><td>ageofgpsdata</td><td>dgpsid</td><td>point</td></tr>";

				for ($i=$this->idOffSet; $i<$count ; $i++)
				{
					$point="point(".$this->lon[$i]." ".$this->lat[$i].")";
					echo "<tr><td>".$this->wptRteId[$i]."</td><td>".$this->splitTag."</td><td>".$this->rteName[$i]."</td><td>".$this->rteNum[$i]."</td><td>".$this->ele[$i]."</td><td>".$this->time[$i]."</td><td>".$this->magvar[$i]."</td><td>".$this->geoidheight[$i]."</td><td>".$this->cmt[$i]."</td><td>".$this->desc[$i]."</td><td>".$this->src[$i]."</td><td>".$this->link[$i]."</td><td>".$this->sym[$i]."</td><td>".$this->type[$i]."</td><td>".$this->fix[$i]."</td><td>".$this->sat[$i]."</td><td>".$this->hdop[$i]."</td><td>".$this->vdop[$i]."</td><td>".$this->pdop[$i]."</td><td>".$this->ageofgpsdata[$i]."</td><td>".$this->dgpsid[$i]."</td><td>".$point."</td><tr>";
				}
			}
			if ($this->splitTag=="TRKPT")
			{
				echo "<tr><td>id</td><td>typeid</td><td>nameid</td><td>trksegid</td><td>numberid</td><td>ele</td><td>time</td><td>magvar</td><td>geoidheight</td><td>cmt</td><td>desc</td><td>src</td><td>link</td><td>sym</td><td>type</td><td>fix</td><td>sat</td><td>hdop</td><td>vdop</td><td>pdop</td><td>ageofgpsdata</td><td>dgpsid</td><td>point</td></tr>";

				for ($i=$this->idOffSet; $i<$count ; $i++)
				{
					$point="point(".$this->lon[$i]." ".$this->lat[$i].")";
					echo "<tr><td>".$this->wptTrkId[$i]."</td><td>".$this->splitTag."</td><td>".$this->trkName[$i]."</td><td>".$this->wptTrksegId[$i]."</td><td>".$this->trkNum[$i]."</td><td>".$this->ele[$i]."</td><td>".$this->time[$i]."</td><td>".$this->magvar[$i]."</td><td>".$this->geoidheight[$i]."</td><td>".$this->cmt[$i]."</td><td>".$this->desc[$i]."</td><td>".$this->src[$i]."</td><td>".$this->link[$i]."</td><td>".$this->sym[$i]."</td><td>".$this->type[$i]."</td><td>".$this->fix[$i]."</td><td>".$this->sat[$i]."</td><td>".$this->hdop[$i]."</td><td>".$this->vdop[$i]."</td><td>".$this->pdop[$i]."</td><td>".$this->ageofgpsdata[$i]."</td><td>".$this->dgpsid[$i]."</td><td>".$point."</td><tr>";
				}
			}

			echo "</table>";
		}
		function toSQL()
		{
			global $currentTag;	//used by function characterData when parsing xml data
			global $count;
			global $_rte;
			global $_trk;
			global $go;
			global $checkTrkSeg;
			
			switch ($this->splitTag)
			{
				case "WPT":
				$sql="";
				for ($i=$this->idOffSet ; $i<$count ; $i++)
				{
					// set numric types to NULL if empty
					if (!$this->ele[$i]) $this->ele[$i]='NULL';
					if (!$this->magvar[$i]) $this->magvar[$i]='NULL';
					if (!$this->geoidheight[$i]) $this->geoidheight[$i]='NULL';
					if (!$this->sat[$i]) $this->sat[$i]='NULL';
					if (!$this->hdop[$i]) $this->hdop[$i]='NULL';
					if (!$this->vdop[$i]) $this->vdop[$i]='NULL';
					if (!$this->pdop[$i]) $this->pdop[$i]='NULL';
					if (!$this->ageofdgpsdata[$i]) $this->ageofdgpsdata[$i]='NULL';
					if (!$this->dgpsid[$i]) $this->dgpsid[$i]='NULL';
					$the_geom="GeometryFromText('POINT(".$this->lon[$i]." ".$this->lat[$i].")',4326)";
					$sql.="insert into wpt(userid,id,typeid,nameid,trksegid,numberid,ele,_time,magvar,geoidheight,cmt,_desc,src,link,sym,_type,fix,sat,hdop,vdop,pdop,ageofdgpsdata,dgpsid,the_geom) values(".$_SESSION['userid'].",NULL,'".$this->splitTag."','',NULL,NULL,".$this->ele[$i].",'".$this->time[$i]."',".$this->magvar[$i].",".$this->geoidheight[$i].",'".$this->cmt[$i]."','".$this->desc[$i]."','".$this->src[$i]."','".$this->link[$i]."','".$this->sym[$i]."','".$this->type[$i]."','".$this->fix[$i]."',".$this->sat[$i].",".$this->hdop[$i].",".$this->vdop[$i].",".$this->pdop[$i].",".$this->ageofdgpsdata[$i].",".$this->dgpsid[$i].",".$the_geom.");\n";
				}
				break;
				case "RTE":
				$sql="";
				for ($i=$this->idOffSet ; $i<$count ; $i++)
				{
					$the_geom="GeometryFromText('MULTILINESTRING((".$this->removeChars($this->rteLineStr[$i])."))',4326)";
					$this->rteName[$i]=pg_escape_string($this->rteName[$i]);
					$this->rteDesc[$i]=pg_escape_string($this->rteDesc[$i]);
					$this->rteSrc[$i]=pg_escape_string($this->rteSrc[$i]);
					$this->rteLink[$i]=pg_escape_string($this->rteLink[$i]);
					$sql.="insert into trk(userid,id,typeid,name,cmt,_desc,src,link,number,_type,the_geom) values(".$_SESSION['userid'].",".$i.",'".$this->splitTag."','".$this->rteName[$i]."','".$this->rteCmt[$i]."','".$this->rteDesc[$i]."','".$this->rteSrc[$i]."','".$this->rteLink[$i]."',".$this->rteNum[$i].",'".$this->rteType[$i]."',".$the_geom.");\n";
				}
				break;
				case "TRK":
				$sql="";
				$firstInteration=false;
				
				// set numric types to NULL if empty
				if (!$this->trkNum[$i]) $this->trkNum[$i]='NULL';
				
				for ($i=$this->idOffSet ; $i<$count ; $i++)
				{
					if (!$firstInteration)
					{
						$the_geom="GeometryFromText('MULTILINESTRING((".$this->removeChars($this->trkLineStr[$i])."))',4326)";
					}
					else
					{ 
						$the_geom="GeometryFromText('MULTILINESTRING((".$this->removeChars($this->trkLineStr[$i],3)."))',4326)";
					}
					$firstInteration=true;
					
					$this->trkName[$i]=pg_escape_string($this->trkName[$i]);
					$this->trkDesc[$i]=pg_escape_string($this->trkDesc[$i]);
					$this->trkSrc[$i]=pg_escape_string($this->trkSrc[$i]);
					$this->trkLink[$i]=pg_escape_string($this->trkLink[$i]);
					$sql.="insert into trk(userid,id,typeid,name,cmt,_desc,src,link,number,_type,the_geom) values(".$_SESSION['userid'].",".$i.",'".$this->splitTag."','".$this->trkName[$i]."','".$this->trkCmt[$i]."','".$this->trkDesc[$i]."','".$this->trkSrc[$i]."','".$this->trkLink[$i]."',".$this->trkNum[$i].",'".$this->trkType[$i]."',".$the_geom.");\n";
				}
				break;
				case "RTEPT":
				$sql="";
				for ($i=$this->idOffSet; $i<$count ; $i++)
				{
					// set numric types to NULL if empty
					if (!$this->rteNum[$i]) $this->rteNum[$i]='NULL';
					if (!$this->ele[$i]) $this->ele[$i]='NULL';
					if (!$this->magvar[$i]) $this->magvar[$i]='NULL';
					if (!$this->geoidheight[$i]) $this->geoidheight[$i]='NULL';
					if (!$this->sat[$i]) $this->sat[$i]='NULL';
					if (!$this->hdop[$i]) $this->hdop[$i]='NULL';
					if (!$this->vdop[$i]) $this->vdop[$i]='NULL';
					if (!$this->pdop[$i]) $this->pdop[$i]='NULL';
					if (!$this->ageofdgpsdata[$i]) $this->ageofdgpsdata[$i]='NULL';
					if (!$this->dgpsid[$i]) $this->dgpsid[$i]='NULL';
					$the_geom="GeometryFromText('POINT(".$this->lon[$i]." ".$this->lat[$i].")',4326)";
					$sql.="insert into wpt(id,typeid,nameid,trksegid,numberid,ele,_time,magvar,geoidheight,cmt,_desc,src,link,sym,_type,fix,sat,hdop,vdop,pdop,ageofdgpsdata,dgpsid,the_geom) values(".$this->wptRteId[$i].",'".$this->splitTag."','".$this->rteName[$i]."',NULL,".$this->rteNum[$i].",".$this->ele[$i].",'".$this->time[$i]."',".$this->magvar[$i].",".$this->geoidheight[$i].",'".$this->cmt[$i]."','".$this->desc[$i]."','".$this->src[$i]."','".$this->link[$i]."','".$this->sym[$i]."','".$this->type[$i]."','".$this->fix[$i]."',".$this->sat[$i].",".$this->hdop[$i].",".$this->vdop[$i].",".$this->pdop[$i].",".$this->ageofdgpsdata[$i].",".$this->dgpsid[$i].",".$the_geom.");\n";
				}
				break;
				case "TRKPT":
				$sql="";
				for ($i=$this->idOffSet; $i<$count ; $i++)
				{
					// set numric types to NULL if empty
					if (!$this->trkNum[$i]) $this->trkNum[$i]='NULL';
					if (!$this->ele[$i]) $this->ele[$i]='NULL';
					if (!$this->magvar[$i]) $this->magvar[$i]='NULL';
					if (!$this->geoidheight[$i]) $this->geoidheight[$i]='NULL';
					if (!$this->sat[$i]) $this->sat[$i]='NULL';
					if (!$this->hdop[$i]) $this->hdop[$i]='NULL';
					if (!$this->vdop[$i]) $this->vdop[$i]='NULL';
					if (!$this->pdop[$i]) $this->pdop[$i]='NULL';
					if (!$this->ageofdgpsdata[$i]) $this->ageofdgpsdata[$i]='NULL';
					if (!$this->dgpsid[$i]) $this->dgpsid[$i]='NULL';
					//$this->cmt[$i]=pg_escape_string($this->cmt[$i]);
					//$this->desc[$i]=pg_escape_string($this->desc[$i]);
					$the_geom="GeometryFromText('POINT(".$this->lon[$i]." ".$this->lat[$i].")',4326)";
					$sql.="insert into wpt(id,typeid,nameid,trksegid,numberid,ele,_time,magvar,geoidheight,cmt,_desc,src,link,sym,_type,fix,sat,hdop,vdop,pdop,ageofdgpsdata,dgpsid,the_geom) values(".$this->wptTrkId[$i].",'".$this->splitTag."','".$this->trkName[$i]."',".$this->wptTrksegId[$i].",".$this->trkNum[$i].",".$this->ele[$i].",'".$this->time[$i]."',".$this->magvar[$i].",".$this->geoidheight[$i].",'".$this->cmt[$i]."','".$this->desc[$i]."','".$this->src[$i]."','".$this->link[$i]."','".$this->sym[$i]."','".$this->type[$i]."','".$this->fix[$i]."',".$this->sat[$i].",".$this->hdop[$i].",".$this->vdop[$i].",".$this->pdop[$i].",".$this->ageofdgpsdata[$i].",".$this->dgpsid[$i].",".$the_geom.");\n";
				}
				break;
			}
			//reset global vars
			$currentTag=NULL;
			$count=NULL;;
			$_rte=NULL;;
			$_trk=NULL;;
			$go=NULL;;
			$checkTrkSeg=NULL;
			
			return($sql);
		}
}
?>
Return current item: AppForMap