def rebuild(self): """ Rebuild the folium map. :return: None. """ if self.spatialData and self.selectedSpecies: allCoordinates = [n[0] for m in self.spatialData.values() for n in m] centerCoordinate = DatasetProcessor.randomEstimateLocation(allCoordinates) zoom = self.zoom + 4 self.fMap = folium.Map(location=centerCoordinate, zoom_start=zoom, tiles=self.tile, attr=self.attr) else: self.fMap = folium.Map(location=self.location, zoom_start=self.zoom, tiles=self.tile, attr=self.attr)
def importData(self): """ Import data from a Darwin Core Archive (DwC-A) file. |br| Store them in ``Dataset``. :return: None. """ if self.spatialData: title = "Dataset Already Imported" content = "To import new data, please clear data first." self.mainWindow.alert(title, content, 3) return title, extension = "Select a DwC-A File", "DwC-A File (*.zip)" filename = self.mainWindow.openFile(title, extension) if filename: try: archiveData, archiveMeta = DatasetProcessor.extractDarwinCoreArchive(filename) if archiveMeta["coreType"] not in Dataset.supportedCores: title = "Unsupported DwC Type" content = ( "The provided file has core type of " + archiveMeta["coreType"] + ".\n" "This program only support " + ", ".join(Dataset.supportedCores) + "." ) self.mainWindow.alert(title, content, 3) return columns = [ ("individualCount", True), ("eventDate", True), ("decimalLatitude", True), ("decimalLongitude", True), ("scientificName", True), ("vernacularName", False) ] try: dataList = DatasetProcessor.extractCsv(archiveData, archiveMeta, columns) except ValueError as e: title = "Invalid DwC-A File" content = str(e) + "\nPlease select a DwC-A file with such field." self.mainWindow.alert(title, content, 3) return except: title = "Invalid DwC-A File" content = ( "The provided file is either not in DwC-A format or corrupted.\n" "Please select a valid one.\n\n" ) self.mainWindow.alert(title, content + format_exc(), 3) return for r in dataList: try: r0int = int(r[0]) r1datetime = parse(r[1]) r2float = float(r[2]) r3float = float(r[3]) if not r[4]: raise ValueError("Field \"scientificName\" is empty.") except: title = "Invalid Record Found" content = "The following record is invalid and will be ignored:\n" self.mainWindow.alert(title, content + pformat(r), 2) else: self.spatialData[r[4]] = ((r2float, r3float), r0int) self.temporalData[r[4]] = (r1datetime, r0int) self.auxiliaryData[r[4]] = r[5] title = "Dataset Successfully Imported" content = "{:,d} records have been loaded.".format(len(dataList)) self.mainWindow.alert(title, content, 0)