def exportClicked(self): canceled = Control.questionBox() self.roi_name = canceled[1] if canceled[0]: return try: self.getROICoords() self.createGeoJSONtoExport() except OSError: Control.errorMessage("GeoJSON cannot be created.") code = "" if self.gj_loaded != "": code = self.gj_loaded else: code = str(self.roi_id) gj = fiona.open( Control.dirname + "/Output_data/GeoJSON/" + code + ".geojson", "r") str_coords = "" for ft in gj: str_coords = "".join( str(i) for i in ft["geometry"]["coordinates"][0]) content = "geometry;" + str_coords + ";\nindex;" + self.plotWidget.y_label \ + ";\narea;" + self.roi_name + ";\ngeojson;" + code + ";" stats = [["date", ""], ["min", ""], ["mean", ""], ["median", ""], ["max", ""], ["std", ""], ["count", ""]] for i in range(len(self.zss)): for j in range(len(stats)): if self.zss[i][stats[j][0]] is not None: if i + 1 < len(self.zss): if j == 0: stats[j][1] += ";" + self.zss[i][ stats[j][0]] + ";difference" + str(i + 1) elif j == 6: stats[j][1] += ";" + str( self.zss[i][stats[j][0]]) + ";0" else: stats[j][1] += ";"\ + ("{:.3f}".format(round(self.zss[i][stats[j][0]], 3))).replace(".", ",")\ + ";" + ("{:.3f}".format(round(self.zss[i][stats[j][0]] - self.zss[i + 1][stats[j][0]], 3))).replace(".", ",") else: if j == 0: stats[j][1] += ";" + self.zss[i][stats[j][0]] elif j == 6: stats[j][1] += ";" + str(self.zss[i][stats[j][0]]) else: stats[j][1] += ";" + ("{:.3f}".format( self.zss[i][stats[j][0]])).replace(".", ",") else: if i + 1 < len(self.zss): stats[j][1] += ";null;null" else: stats[j][1] += ";null" for i in range(len(stats)): content += "\n" + stats[i][0] + stats[i][1] content += "\n\n\n" try: mode = "w" if os.path.isfile(Control.dirname + "/Output_data/export.csv"): mode = "a" csv = open(Control.dirname + "/Output_data/export.csv", mode) csv.write(content) csv.close() mode_c = "w" header_c = "id;geometry;\n" if os.path.isfile(Control.dirname + "/Output_data/GeoJSON/coords.csv"): mode_c = "a" header_c = "" csv_coords = open( Control.dirname + "/Output_data/GeoJSON/coords.csv", mode) csv_coords.write(header_c + str(self.roi_id) + ";" + str(self.nodes_zs) + ";\n") csv_coords.close() Control.infoMessage( "Summary statistics was successfully exported.") except OSError: Control.errorMessage( "Cannot write to file 'export.csv'. Please close the file and try to export data again." )