public Radarsat1DataUsageRights() : base()
 {
     Owner            = DeploySoftware_LaunchPad_Space_Resources.Text_Radarsat1DataUsageRights_Owner;
     Attribution      = DeploySoftware_LaunchPad_Space_Resources.Text_Radarsat1DataUsageRights_Attribution;
     GoverningLicense = new OpenGovernmentCanadaLicense();
     ProjectLink      = new Uri("http://www.asc-csa.gc.ca/eng/satellites/radarsat1/");
 }
예제 #2
0
        /// <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);
        }