]> dev.renevier.net Git - syj.git/blobdiff - application/controllers/PathController.php
merge linestrings for gpx containting multiple trkseg elements.
[syj.git] / application / controllers / PathController.php
index f0ef477e0969fdd32a6911aced09276a453ed689..af9d104fb2efb3bb5e78d9d3dfc0ef8492d11e12 100644 (file)
@@ -77,6 +77,18 @@ class PathController extends Zend_Controller_Action
             throw new Syj_Exception_InvalidGeomUpload();
         }
 
+        // merge linestrings for gpx containting multiple trkseg elements.
+        if ($classname == 'gisconverter\\GPX' && $geom::name == 'GeometryCollection') {
+          $geomstring = "";
+          foreach (array_filter($geom->components, function ($geom) {
+            return $geom::name == "LineString";
+          }) as $linestring) {
+            $geomstring .= str_replace("<trkseg>", "",
+                              str_replace("</trkseg>", "", $linestring->toGPX()));
+          }
+          $geom = $decoder->geomFromText("<trkseg>" . $geomstring . "</trkseg>");
+        }
+
         if ($geom::name != "LineString") {
             throw new Syj_Exception_InvalidGeomUpload();
         }
@@ -90,20 +102,7 @@ class PathController extends Zend_Controller_Action
 
         /* now, saving !*/
         $pathMapper = new Syj_Model_PathMapper();
-        try {
-            $pathMapper->save ($path);
-        } catch(Zend_Db_Statement_Exception $e) {
-            if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
-                $message = $e->getMessage();
-                if (strpos($message, 'paths_geom_key') !== false) {
-                    throw new Syj_Exception_InvalidGeomUpload("uniquepath");
-                } else {
-                    throw $e;
-                }
-            } else {
-                throw $e;
-            }
-        }
+        $pathMapper->save ($path);
     }
 
 }