/// <summary> /// Returns a series of four corner coordinates from a provided string of coordinate information. /// </summary> /// <param name="cornerCoordinatesString">The coordinate information to parse</param> /// <returns>An ImageObservationCornerCoordinates object containing four coordinate points for each side of a square</returns> protected ImageObservationCornerCoordinates GetCornerCoordinates(string cornerCoordinatesString) { string[] coordinates = Regex.Split(cornerCoordinatesString, @"(?<=[N,S,E,W])"); // disable the celestial information (not needed) EagerLoad load = new EagerLoad { Celestial = false, Cartesian = true, UTM_MGRS = true }; ImageObservationCornerCoordinates cornerCoords = new ImageObservationCornerCoordinates(load); // upper left latitude if (!String.IsNullOrEmpty(coordinates[0])) { cornerCoords.UpperLeft.Latitude = GetLatitude(coordinates[0].Trim(), cornerCoords.UpperLeft); } // upper left longitude if (!String.IsNullOrEmpty(coordinates[2])) { cornerCoords.UpperLeft.Longitude = GetLongitude(coordinates[2].Trim(), cornerCoords.UpperLeft); } // upper right latitude if (!String.IsNullOrEmpty(coordinates[1])) { cornerCoords.UpperRight.Latitude = GetLatitude(coordinates[1].Trim(), cornerCoords.UpperRight); } // upper right longitude if (!String.IsNullOrEmpty(coordinates[3])) { cornerCoords.UpperRight.Longitude = GetLongitude(coordinates[3].Trim(), cornerCoords.UpperRight); } // lower left latitude if (!String.IsNullOrEmpty(coordinates[4])) { cornerCoords.LowerLeft.Latitude = GetLatitude(coordinates[4].Trim(), cornerCoords.LowerLeft); } // lower left longitude if (!String.IsNullOrEmpty(coordinates[6])) { cornerCoords.LowerLeft.Longitude = GetLongitude(coordinates[6].Trim(), cornerCoords.LowerLeft); } // lower right latitude if (!String.IsNullOrEmpty(coordinates[5])) { cornerCoords.LowerRight.Latitude = GetLatitude(coordinates[5].Trim(), cornerCoords.LowerRight); } // lower right longitude if (!String.IsNullOrEmpty(coordinates[7])) { cornerCoords.LowerRight.Longitude = GetLongitude(coordinates[7].Trim(), cornerCoords.LowerRight); } return(cornerCoords); }
public Radarsat1Observation( int?tenantId, string sceneId, string mdaOrderNumber, string geographicalArea, DateTime sceneStart, DateTime sceneStop, string orbit, string orbitDataType, string applicationLut, string beamMode, string productType, string format, int numberImageLines, int numberImagePixels, string pixelSpacing, GeographicLocation sceneCentre, ImageObservationCornerCoordinates cornerCoordinates ) : base() { Id = Guid.NewGuid(); CurrentLocation = new SpaceTimeInformation(); SceneId = sceneId; MdaOrderNumber = mdaOrderNumber; GeographicalArea = geographicalArea; SceneStartTime = sceneStart; SceneStopTime = sceneStop; Orbit = orbit; OrbitDataType = orbitDataType; ApplicationLut = applicationLut; BeamMode = beamMode; ProductType = productType; Format = format; NumberImageLines = numberImageLines; NumberImagePixels = numberImagePixels; PixelSpacing = pixelSpacing; SceneCentre = sceneCentre; Corners = cornerCoordinates; CreationTime = Clock.Now; LastModificationTime = Clock.Now; CurrentLocation.PhysicalLocation = SceneCentre; CurrentLocation.PointInTime = SceneStartTime; }
public Radarsat1Observation( TPrimaryKey id, int?tenantId, string sceneId, string mdaOrderNumber, string geographicalArea, DateTime sceneStart, DateTime sceneStop, string orbit, string orbitDataType, string applicationLut, string beamMode, string productType, string format, int numberImageLines, int numberImagePixels, string pixelSpacing, GeographicLocation sceneCentre, ImageObservationCornerCoordinates cornerCoordinates ) : base() { Id = id; new Radarsat1Observation <TPrimaryKey, TFileStorageLocationType>( tenantId, sceneId, mdaOrderNumber, geographicalArea, sceneStart, sceneStop, orbit, orbitDataType, applicationLut, beamMode, productType, format, numberImageLines, numberImagePixels, pixelSpacing, sceneCentre, cornerCoordinates ); }
/// <summary> /// Main utility method to parse a Radarsat1 Metadata text file and populate the Radarsat1 Image Observation from the information /// contained within the file. /// /// The metadata is in RADARSAT CEOS format and is (c) Canadian Space Agency 1997 Agence spatiale canadienne, and processed and distributed by MDA Geospatial Services Inc. /// The data and metadata used within this software has been made freely available by the Canadian Federal Government under its Open Government initiative, /// subject to the following license terms: https://open.canada.ca/en/open-government-licence-canada /// </summary> /// <param name="metadataFileKey">The filepath/filename of the Radarsat1 metadata file</param> /// <exception cref="ArgumentNullException"></exception> /// <returns>A populated Radarsat1Observation object containing the metadata values, or null if the object couldn't be populated</returns> /// <throws>A FileLoadException if the file cannot be found or loaded</throws> public Radarsat1Observation <TPrimaryKey, TFileStorageLocationType> GetRadarsat1ObservationFromMetadataFile(string radarsat1MetadataFilename) { Radarsat1Observation <TPrimaryKey, TFileStorageLocationType> observation = null; // Radarsat 1 metadata files are in .txt format // ReSharper disable once RedundantAssignment var metadataFileText = string.Empty; if (radarsat1MetadataFilename.EndsWith(".txt")) { try { // Open the Radarsat1 Metadata text file using (StreamReader sr = new StreamReader(radarsat1MetadataFilename, Encoding.GetEncoding("iso-8859-1"))) { metadataFileText = sr.ReadToEnd(); } } catch (Exception ex) { throw new FileLoadException(ex.Message); } String radarsatUniqueId = Path.GetFileNameWithoutExtension(radarsat1MetadataFilename); String sceneId = metadataFileText.FindStringWithinAnchorText("SCENE_ID", "MDA ORDER NUMBER", true, true); String mdaOrderNumber = metadataFileText.FindStringWithinAnchorText("MDA ORDER NUMBER", "GEOGRAPHICAL AREA", true, true); String geographicalArea = metadataFileText.FindStringWithinAnchorText("GEOGRAPHICAL AREA", "SCENE START TIME", true, true); String sceneStartTimeText = metadataFileText.FindStringWithinAnchorText("SCENE START TIME", "SCENE STOP TIME", true, true); const string dateFormatPattern = "MMM dd yyyy HH:mm:ss.FFF"; Guard.Against <ArgumentNullException>( String.IsNullOrEmpty(sceneStartTimeText), DeploySoftware_LaunchPad_Space_Resources.Exception_Radarsat1MetadataParser_GetRadarsat1ObservationFromMetadataFile_SceneStartTime_ArgumentNullExpection ); DateTime.TryParseExact(sceneStartTimeText, dateFormatPattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime sceneStartTime); String sceneStopTimeText = metadataFileText.FindStringWithinAnchorText("SCENE STOP TIME", "ORBIT", true, true); Guard.Against <ArgumentNullException>( String.IsNullOrEmpty(sceneStopTimeText), DeploySoftware_LaunchPad_Space_Resources.Exception_Radarsat1MetadataParser_GetRadarsat1ObservationFromMetadataFile_SceneStopTime_ArgumentNullExpection ); DateTime.TryParseExact(sceneStopTimeText, dateFormatPattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime sceneStopTime); String orbit = metadataFileText.FindStringWithinAnchorText("ORBIT", "ORBIT DATA TYPE", true, true); String orbitDataType = metadataFileText.FindStringWithinAnchorText("ORBIT DATA TYPE", "APPLICATION LUT", true, true); String applicationLut = metadataFileText.FindStringWithinAnchorText("APPLICATION LUT", "BEAM MODE", true, true); String beamMode = metadataFileText.FindStringWithinAnchorText("BEAM MODE", "PRODUCT TYPE", true, true); String productType = metadataFileText.FindStringWithinAnchorText("PRODUCT TYPE", "FORMAT", true, true); String format = metadataFileText.FindStringWithinAnchorText("FORMAT", "# OF IMAGE LINES", true, true); Int32.TryParse(metadataFileText.FindStringWithinAnchorText("# OF IMAGE LINES", "# OF IMAGE PIXELS", true, true), out var numberImageLines); Int32.TryParse(metadataFileText.FindStringWithinAnchorText("# OF IMAGE PIXELS", "PIXEL SPACING", true, true), out var numberImagePixels); String pixelSpacing = metadataFileText.FindStringWithinAnchorText("PIXEL SPACING", "SCENE CENTRE", true, true); // when loading coordinates, disable celestial calculations (not needed) EagerLoad load = new EagerLoad { Celestial = false, Cartesian = true, UTM_MGRS = true }; // get the scene centre coordinates. Centre is spelled properly in Canadian, eh. String sceneCentre = metadataFileText.FindStringWithinAnchorText("SCENE CENTRE", "CORNER COORDINATES", true, true); Guard.Against <ArgumentNullException>( String.IsNullOrEmpty(sceneCentre), DeploySoftware_LaunchPad_Space_Resources.Exception_Radarsat1MetadataParser_GetRadarsat1ObservationFromMetadataFile_SceneCentre_ArgumentNullExpection ); // ReSharper disable once PossibleNullReferenceException string[] latLongSplit = sceneCentre.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Coordinate c = new Coordinate(load); c.Latitude = GetLatitude(latLongSplit[0], c); c.Longitude = GetLongitude(latLongSplit[1], c); GeographicLocation centre = new GeographicLocation ( c.Latitude.ToDouble(), c.Longitude.ToDouble(), c.EagerLoadSettings ); // get the image corner coordinates String cornerCoordinatesString = metadataFileText.FindStringWithinAnchorText("CORNER COORDINATES:", "For information on RADARSAT CEOS format see README.TXT", true, true); Guard.Against <ArgumentNullException>( String.IsNullOrEmpty(cornerCoordinatesString), DeploySoftware_LaunchPad_Space_Resources.Exception_Radarsat1MetadataParser_GetRadarsat1ObservationFromMetadataFile_CornerCoordinates_ArgumentNullExpection ); ImageObservationCornerCoordinates cornerCoords = GetCornerCoordinates(cornerCoordinatesString); ILicense license = new OpenGovernmentCanadaLicense(); IUsageRights copyright = new Radarsat1DataUsageRights(); // Create a new Radarsat1 Earth Observation image observation = new Radarsat1Observation <TPrimaryKey, TFileStorageLocationType>( null, // tenant Id - not used in this application sceneId, mdaOrderNumber, geographicalArea, sceneStartTime, sceneStopTime, orbit, orbitDataType, applicationLut, beamMode, productType, format, numberImageLines, numberImagePixels, pixelSpacing, centre, cornerCoords ) { Name = radarsatUniqueId, //Metadata.Description = radarsatUniqueId, Copyright = copyright }; } // ReSharper disable once PossibleNullReferenceException observation.Files = LoadExpectedObservationFiles(observation, radarsat1MetadataFilename); return(observation); }