/// <summary> /// imageFileProcessor can be null - the default one will be used, same with insertWaypointHandler and insertEarthquakeHandler /// /// for a .jpg file just calls image file processor. /// for .gpx, .loc, .zip, .gpz and .wpt files calls BaseFormat.processor() and adds to foldersToProcess /// /// returns true on success /// </summary> /// <param name="fileName"></param> /// <param name="insertWaypointHandler"></param> /// <param name="insertEarthquakeHandler"></param> /// <param name="imageFileProcessor"></param> /// <param name="foldersToProcess"></param> /// <returns></returns> public static bool readFile(string fileName, InsertWaypoint insertWaypointHandler, InsertEarthquake insertEarthquakeHandler, ProcessFile imageFileProcessor, SortedList foldersToProcess, bool addToRecent) { bool isSuccess = false; fileName = Project.GetLongPathName(new FileInfo(fileName).FullName); // make sure we are not dealing with 8.3 notation here if (insertWaypointHandler == null) { insertWaypointHandler = new InsertWaypoint(WaypointsCache.insertWaypoint); } if (insertEarthquakeHandler == null) { insertEarthquakeHandler = new InsertEarthquake(EarthquakesCache.insertEarthquake); } if (imageFileProcessor == null) { imageFileProcessor = new ProcessFile(FileAndZipIO.processImageFile); } if (AllFormats.isTiffFile(fileName)) { #region Handle a GeoTiff file GeoTiff geoTiff = new GeoTiff(fileName); try { geoTiff.init(); } catch { } if (geoTiff.isValid) { CustomMapsCache.RemoveCustomMapsBySource(fileName); CustomMap cm = new CustomMapGeotiff(geoTiff); Project.customMapId++; cm.Id = Project.customMapId; CustomMapsCache.AddCustomMap(cm); WaypointsCache.pushBoundaries(cm.Location); WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.BottomLeftLng, geoTiff.BottomLeftLat)); WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.TopRightLng, geoTiff.TopRightLat)); WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.BottomRightLng, geoTiff.BottomRightLat)); // success, worth adding to imported list, if not repeat read: bool repeatRead = isRepeatRead(fileName); if (!repeatRead) { FormattedFileDescr ffd = new FormattedFileDescr(fileName, FileGeoTIFF.FormatName, false); Project.FileDescrList.Add(ffd); } string msg = "OK: read file " + fileName + (repeatRead ? " (repeat read)" : ""); LibSys.StatusBar.Trace(msg); LibSys.StatusBar.Trace("* " + msg); isSuccess = true; // will ensure refresh is called } else { LibSys.StatusBar.Error("readFile - not a GeoTIFF file: " + fileName); } #endregion // Handle a GeoTiff file } else if (fileName.ToLower().EndsWith(".jpg")) { #region Single JPEG image probably dropped PhotoWaypoints.cleanPhotoTrackpoints(fileName); try { LibSys.StatusBar.Trace(" ...readFile - processing image file: " + fileName); if (imageFileProcessor(null, null, fileName, fileName) > 0) { Project.photoFileName = fileName; isSuccess = true; // will ensure refresh is called } } catch (Exception exc) { LibSys.StatusBar.Error("Exception: " + exc.Message); } #endregion // Single JPEG image probably dropped } else { LibSys.StatusBar.Trace(" ...readFile - processing formatted file: " + fileName); #region Processing formatted file - zip, gpx BaseFormat format = AllFormats.formatByFileName(fileName); if (format != null) { string formatName = AllFormats.formatNameByFileName(fileName); format.InsertWaypoint = insertWaypointHandler; format.InsertEarthquake = insertEarthquakeHandler; FileListStruct fls = new FileListStruct(fileName, formatName, new FormatProcessor(format.process), false); WaypointsCache.RemoveWaypointsBySource(fls.filename); // actually read the file. If ZIP processor is there, it will read all enclosed .GPX files. if (fls.processor("", fls.filename, fls.filename)) // boundaries pushed in WaypointsCache.insertWaypoint() { // knows about .gpx files and Project.photoAnalyzeOnLoad: enlistPhotoFolder(fls.filename, foldersToProcess, imageFileProcessor); // success, worth adding to imported list, if not repeat read: bool repeatRead = isRepeatRead(fileName); if (!repeatRead) { FormattedFileDescr ffd = new FormattedFileDescr(fileName, formatName, false); Project.FileDescrList.Add(ffd); } string msg = "OK: read file " + fileName + (repeatRead ? " (repeat read)" : ""); LibSys.StatusBar.Trace(msg); LibSys.StatusBar.Trace("* " + msg); isSuccess = true; } else { LibSys.StatusBar.Trace("* Error: while processing file " + fileName); Project.ErrorBox(Project.mainForm, "Error processing file:\n\n" + fls.filename); } } else { LibSys.StatusBar.Trace("* Error: unrecognized format " + fileName); Project.ErrorBox(Project.mainForm, "Unrecognized format:\n\n" + fileName); } #endregion // Processing formatted file - zip, gpx } if (addToRecent && isSuccess) { Project.insertRecentFile(fileName); } return isSuccess; }
private void selectFileButton_Click(object sender, System.EventArgs e) { traceTextBox.Text = "selected: " + Project.togeotiffFileName; GeoTiff geoTiff = new GeoTiff(Project.togeotiffFileName); geoTiff.TopLeftLat = geoTiff.TopRightLat = CameraManager.This.CoverageTopLeft34.Lat; geoTiff.TopLeftLng = geoTiff.BottomLeftLng = CameraManager.This.CoverageTopLeft34.Lng; geoTiff.BottomRightLat = geoTiff.BottomLeftLat = CameraManager.This.CoverageBottomRight34.Lat; geoTiff.BottomRightLng = geoTiff.TopRightLng = CameraManager.This.CoverageBottomRight34.Lng; geoTiff.initImageOnly(); if(geoTiff.isValid) { CustomMapsCache.RemoveCustomMapsBySource(Project.togeotiffFileName); CustomMap cm = new CustomMapGeotiff(geoTiff); Project.customMapId++; cm.Id = Project.customMapId; CustomMapsCache.AddCustomMap(cm); WaypointsCache.pushBoundaries(cm.Location); WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.BottomLeftLng, geoTiff.BottomLeftLat)); WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.TopRightLng, geoTiff.TopRightLat)); WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.BottomRightLng, geoTiff.BottomRightLat)); string msg = "OK: read image file " + Project.togeotiffFileName; LibSys.StatusBar.Trace(msg); LibSys.StatusBar.Trace("* " + msg); toState(2); selectGeotiffPointButton.Enabled = true; selectMapPointButton.Enabled = false; PictureManager.This.Refresh(); } else { LibSys.StatusBar.Error("cannot make a GeoTIFF file: " + Project.togeotiffFileName); } }