/// <summary> /// Returns the raw data grid for a given inventory item as a multidimensional float array /// Maybe you don't want to use this, unless you need to do something very specific or /// you encountered some mishap in NGribCS when using GetGriddedData /// </summary> /// <param gridTemplateName="pInvItem">The InventoryItem for which the data should be retrieved</param> /// <returns>A multidimensional array float[x,y], scanning direction as defined in the GDS</returns> public float[] GetRawData(InventoryItem pInvItem) { Grib2Data d = new Grib2Data(_StreamDictionary[pInvItem.SourceIndex]); float[] data = d.getData(pInvItem.Product.getGdsOffset(), pInvItem.Product.getPdsOffset()); return data; }
/// <summary> /// Returns the Grid Definition Section (GDS) for a given InventoryItem /// </summary> /// <param gridTemplateName="pInvItem">The InventoryItem for which the GDS should be retrieved</param> /// <returns>Grid Definition Section (GDS) for given InventoryItem</returns> public Grib2GridDefinitionSection GetGDS(InventoryItem pInvItem) { IGrib2Product p = _Grib2Inputs[pInvItem.SourceIndex].GetProduct(pInvItem.ProductIndex); return _Grib2Inputs[pInvItem.SourceIndex].GDSs[pInvItem.Product.GDSkey]; }
/// <summary> /// Returns a scanning corrected data grid for a given inventory item as a multidimensional float array /// </summary> /// <param gridTemplateName="pInvItem">The InventoryItem for which the data should be retrieved</param> /// <returns>A multidimensional array float[x,y], scanning is always left to right and top to bottom</returns> public float[,] GetGriddedData(InventoryItem iv) { Grib2GridDefinitionSection gds = GetGDS(iv); float[] rawdata = GetRawData(iv); // Determine Scanning Mode BitArray ba = new BitArray(new byte[] {(Byte)gds.ScanMode}); // Defining the array bounds float[,] fx = new float[gds.Nx, gds.Ny]; int n = 0; if (gds.IoLonMode != InterpretationOfListOfNumbersMode.NoAppendedList) throw new GribNotSupportedException("Lists of optional numbers in the GDS are currently not supported"); // I am certain there is a more elegant way to to this but right now it has 35 degrees, so I am aiming for the simple solution if (gds.ScanningDirection == ScanningDirectionMode.AdjacentRowsOppositeDirection) throw new NotImplementedException("This scanning mode is not supported."); if (gds.ScanningConsecutivity == ScanningConsecutivityMode.AdjacentPointsIDirectionConsecutive) { if (gds.VerticalScanning == VerticalScanningMode.TopToBottom) { for (int j = 0; j < gds.Ny; j++) { if (gds.HorizontalScanning == HorizontalScanningMode.LeftToRight) { for (int i = 0; i < gds.Nx; i++) { fx[i, j] = rawdata[n]; n++; } } else if (gds.HorizontalScanning == HorizontalScanningMode.RightToLeft) { for (int i = gds.Nx-1; i >= 0; i--) { fx[i, j] = rawdata[n]; n++; } } } } else if (gds.VerticalScanning == VerticalScanningMode.BottomToTop) { for (int j = gds.Ny - 1; j >= 0; j--) { if (gds.HorizontalScanning == HorizontalScanningMode.LeftToRight) { for (int i = 0; i < gds.Nx; i++) { fx[i, j] = rawdata[n]; n++; } } else if (gds.HorizontalScanning == HorizontalScanningMode.RightToLeft) { for (int i = gds.Nx - 1; i >= 0; i--) { fx[i, j] = rawdata[n]; n++; } } } } } else if (gds.ScanningConsecutivity == ScanningConsecutivityMode.AdjacentPointsJDirectionConsecutive) { if (gds.HorizontalScanning == HorizontalScanningMode.LeftToRight) { for (int i=0; i<gds.Nx; i++) { if (gds.VerticalScanning== VerticalScanningMode.TopToBottom) { for (int j = 0; j < gds.Ny; j++) { fx[i, j] = rawdata[n]; n++; } } else if (gds.VerticalScanning == VerticalScanningMode.BottomToTop) { for (int j= gds.Ny -1; j >= 0; j--) { fx[i, j] = rawdata[n]; n++; } } } } else if (gds.HorizontalScanning == HorizontalScanningMode.RightToLeft) { for (int i = gds.Nx - 1; i>=0; i--) { if (gds.VerticalScanning == VerticalScanningMode.TopToBottom) { for (int j = 0; j < gds.Ny; j++) { fx[i, j] = rawdata[n]; n++; } } else if (gds.VerticalScanning == VerticalScanningMode.BottomToTop) { for (int j = gds.Ny - 1; j >= 0; j--) { fx[i, j] = rawdata[n]; n++; } } } } } return fx; }
public PointF[,] GetCoordinateGrid(InventoryItem iv) { Grib2GridDefinitionSection gds = GetGDS(iv); if (gds.GridDefinitionTemplateNumber == 0) { PointF[,] coordinateGrid = new PointF[gds.Nx, gds.Ny]; for (int x = 0; x < gds.Nx; x++) for (int y = 0; y < gds.Ny; y++) { float xval = float.NaN; if (gds.HorizontalScanning == HorizontalScanningMode.LeftToRight) xval = gds.Lo1 + gds.Dx * x; else if (gds.HorizontalScanning == HorizontalScanningMode.RightToLeft) { xval = gds.Lo2 + gds.Dx * x; } float yval = float.NaN; if (gds.VerticalScanning == VerticalScanningMode.TopToBottom) yval = gds.La1 - gds.Dy * y; else if (gds.VerticalScanning == VerticalScanningMode.BottomToTop) { yval = gds.La2 + gds.Dy * y; } coordinateGrid[x, y] = new PointF(xval, yval); } return coordinateGrid; } throw new NotSupportedException("Other templates than Lat/Lon (0) are not supported right now"); }