Example #1
0
 public static double RawToFinalFormat(this UInt16 rawData, PgmDataDescription pgmParameters)
 {
     if (rawData > pgmParameters.MaxValue)
     {
         throw new ArgumentOutOfRangeException("rawData");
     }
     return rawData * pgmParameters.Scale + pgmParameters.Offset;
 }
 private static UInt16[] readScaledUndulationFromStream(Stream stream, PgmDataDescription dataDescription)
 {
     var dataLength = dataDescription.NumberOfPoints;
     var data = new UInt16[dataLength];
     using (var binReader = new EndianBinaryReader(EndianBitConverter.Big, stream))
     {
         for (int i = 0; i < dataLength; i++)
         {
             data[i] = binReader.ReadUInt16();
         }
     }
     return data;
 }
Example #3
0
        public static int CoordinatesToClosestGridPosition(double latitude, double longitude, PgmDataDescription dataDescription)
        {
            if (dataDescription.OriginLat != 90 || dataDescription.OriginLon != 0)
            {
                throw new ArgumentOutOfRangeException("dataDescription",
                                                      String.Format("Coordinates of the origin are {0} {1}, but should be 90 0.",
                                                                    dataDescription.OriginLat,
                                                                    dataDescription.OriginLon));
            }

            var gridAbsoluteLat = (dataDescription.OriginLat - latitude) * dataDescription.LatitudeIncrementDegrees;
            int closestAccessibleGridLat = (int)Math.Round(gridAbsoluteLat);
            var gridAbsoluteLon = (longitude - dataDescription.OriginLon) * dataDescription.LongitudeIncrementDegrees;
            int closestAccessibleGridLon = (int)Math.Round(gridAbsoluteLon);
            int closestAccessiblePosition = (closestAccessibleGridLon + closestAccessibleGridLat * dataDescription.GridGraphWidthPoints);

            if (closestAccessiblePosition < 0 || closestAccessiblePosition > dataDescription.NumberOfPoints)
                throw new InvalidOperationException(String.Format("Position is out of range. Probably latitude {0} or longitude {1} are out of range.",
                                                                  latitude,
                                                                  longitude));
            return closestAccessiblePosition;
        }
 internal void PgmGeographicLibPreamblesAreProperlyConvertToDataDescriptions(string preamble, PgmDataDescription expectedDescription)
 {
     var actualDescription = PgmDataDescriptionExtractor.getConstatantsFromPreamble(preamble);
     AssertDeep.Equal(actualDescription, expectedDescription);
 }
 public void CorrectPreambleWithChangedOffsetAndScaleFormatExtractCorrectly()
 {
     var expectedDescription = new PgmDataDescription(108, 5, 90, 0, 4320, 2161, 65535, 416, Level.GeoidEgm2008);
     var actualDescription = PgmDataDescriptionExtractor.getConstatantsFromPreamble(PgmAcceptablePreambles.WithChangedOffsetAndScaleFormat);
     AssertDeep.Equal(actualDescription, expectedDescription);
 }