[Mapbender-commits] r6275 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Jun 16 07:53:16 EDT 2010
Author: verenadiewald
Date: 2010-06-16 11:53:16 +0000 (Wed, 16 Jun 2010)
New Revision: 6275
Modified:
trunk/mapbender/http/classes/class_gml.php
Log:
added function toCsv and toFile
Modified: trunk/mapbender/http/classes/class_gml.php
===================================================================
--- trunk/mapbender/http/classes/class_gml.php 2010-06-15 14:55:17 UTC (rev 6274)
+++ trunk/mapbender/http/classes/class_gml.php 2010-06-16 11:53:16 UTC (rev 6275)
@@ -47,19 +47,59 @@
return $myGmlObj->toGml();
}
- /**
- *
- *
- *
- *
- *
- */
public function getBbox () {
if (is_null($this->featureCollection)) {
return null;
}
return $this->featureCollection->getBbox();
}
+
+ /**
+ * Exports the file to CSV.
+ *
+ * @param string $filenamePrefix the filename without an ending like .csv
+ */
+ public function toCsv ($xmlData, $filenamePrefix, $currentFeaturetype) {
+ $unique = TMPDIR . $filenamePrefix;
+ $fCsv = $unique.".csv";
+ $fGml = $unique.".gml";
+ $pathOgr = '/usr/bin/ogr2ogr';
+
+ $w = $this->toFile($fGml,$xmlData);
+
+ $exec = $pathOgr.' -f "CSV" "'.$unique.'" '.$fGml;
+ #$e = new mb_exception($exec);
+ exec($exec);
+
+ $exec = 'recode UTF-8..latin1 '.$unique.'/'.$currentFeaturetype.'.csv';
+ $e = new mb_exception($exec);
+ exec($exec);
+
+ $exec = 'chmod 777 '.$unique.'.*';
+ exec($exec);
+ }
+
+ /**
+ * Writes a file containing the GML.
+ *
+ * @param string $path the path to the file.
+ * @param string $path the path to the file.
+ * @return bool true if the file could be saved; else false.
+ */
+ public function toFile ($file,$xml) {
+ $handle = fopen($file, "w");
+ if (!$handle) {
+ $e = new mb_exception("class_gml.php: Filehandler error (" . $file . ").");
+ return false;
+ }
+ if (!fwrite($handle,$xml)) {
+ $e = new mb_exception("class_gml.php: Could not write file (" . $file . ").");
+ fclose($handle);
+ return false;
+ }
+ fclose($handle);
+ return true;
+ }
}
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list