From cb0ad03990fa53ea56f4b7620d0f214841bbf09a Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Sat, 5 May 2012 12:50:18 -0700 Subject: [PATCH] Adding namespace write support --- lib/adapters/GPX.class.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/adapters/GPX.class.php b/lib/adapters/GPX.class.php index c2cc1d81..90f9ac33 100644 --- a/lib/adapters/GPX.class.php +++ b/lib/adapters/GPX.class.php @@ -12,6 +12,8 @@ */ class GPX extends GeoAdapter { + private $namespace = FALSE; + private $nss = ''; // Name-space string. eg 'georss:' /** * Read KML string into geometry objects @@ -31,9 +33,13 @@ public function read($gpx) { * * @return string The GPX string representation of the input geometries */ - public function write(Geometry $geometry) { + public function write(Geometry $geometry, $namespace = FALSE) { if ($geometry->isEmpty()) return NULL; - return ''.$this->geometryToGPX($geometry).''; + if ($namespace) { + $this->namespace = $namespace; + $this->nss = $namespace.':'; + } + return '<'.$this->nss.'gpx creator="geoPHP" version="1.0">'.$this->geometryToGPX($geometry).'nss.'gpx>'; } public function geomFromText($text) { @@ -146,17 +152,17 @@ protected function geometryToGPX($geom) { } private function pointToGPX($geom) { - return ''; + return '<'.$this->nss.'wpt lat="'.$geom->getY().'" lon="'.$geom->getX().'" />'; } private function linestringToGPX($geom) { - $gpx = ''; + $gpx = '<'.$this->nss.'trk><'.$this->nss.'trkseg>'; foreach ($geom->getComponents() as $comp) { - $gpx .= ''; + $gpx .= '<'.$this->nss.'trkpt lat="'.$comp->getY().'" lon="'.$comp->getX().'" />'; } - $gpx .= ''; + $gpx .= 'nss.'trkseg>nss.'trk>'; return $gpx; }