/// <summary> /// Stretches the cell set definition (with optional timseries) into the GeoCellTuple sequence /// </summary> /// <param name="latmin"></param> /// <param name="latmax"></param> /// <param name="lonmin"></param> /// <param name="lonmax"></param> /// <param name="time"></param> /// <param name="mask"></param> /// <returns></returns> public static IEnumerable <IGeoCell> StretchCells(double[] latmin, double[] latmax, double[] lonmin, double[] lonmax, ITimeRegion time, Array mask = null) { int cellsLen = latmin.Length; int timeLen = time.SegmentsCount; ITimeSegment[] segments = time.GetSegments().ToArray(); if (mask == null) { for (int i = 0; i < cellsLen; i++) { double lonminV = lonmin[i]; double lonmaxV = lonmax[i]; double latminV = latmin[i]; double latmaxV = latmax[i]; for (int t = 0; t < timeLen; t++) { yield return new GeoCell { LatMin = latminV, LonMin = lonminV, LatMax = latmaxV, LonMax = lonmaxV, Time = segments[t] } } ; } } else { GCHandle?maskHandle = GCHandle.Alloc(mask, GCHandleType.Pinned); IntPtr maskPtr = maskHandle.Value.AddrOfPinnedObject(); try { for (int i = 0; i < cellsLen; i++) { double lonminV = lonmin[i]; double lonmaxV = lonmax[i]; double latminV = latmin[i]; double latmaxV = latmax[i]; for (int t = 0; t < timeLen; t++) { if (checkMdBoolArray(maskPtr, t + timeLen * i)) { yield return new GeoCell { LatMin = latminV, LonMin = lonminV, LatMax = latmaxV, LonMax = lonmaxV, Time = segments[t] } } } ; } } finally { maskHandle.Value.Free(); } } }
/// <summary> /// Stretches the point grid into the sequence of points /// </summary> /// <param name="lat"></param> /// <param name="lon"></param> /// <param name="region"></param> /// <param name="mask"></param> /// <returns></returns> public static IEnumerable <IGeoCell> StretchGrid(double[] lat, double[] lon, ITimeRegion region, Array mask = null) { //stretching to lon,lat,t int latLen = lat.Length; int lonLen = lon.Length; int times = region.SegmentsCount; ITimeSegment[] segments = region.GetSegments().ToArray(); if (mask == null) { for (int i = 0; i < lonLen; i++) { double lonV = lon[i]; for (int j = 0; j < latLen; j++) { double latV = lat[j]; for (int t = 0; t < times; t++) { yield return new GeoCell() { LatMin = latV, LatMax = latV, LonMin = lonV, LonMax = lonV, Time = segments[t] } } ; } } } else { GCHandle?maskHandle = GCHandle.Alloc(mask, GCHandleType.Pinned); IntPtr maskPtr = maskHandle.Value.AddrOfPinnedObject(); try { int lastTwoDimsLen = times * latLen; for (int i = 0; i < lonLen; i++) { double lonV = lon[i]; for (int j = 0; j < latLen; j++) { double latV = lat[j]; for (int t = 0; t < times; t++) { if (checkMdBoolArray(maskPtr, t + j * times + i * lastTwoDimsLen)) { yield return new GeoCell { LatMin = latV, LatMax = latV, LonMin = lonV, LonMax = lonV, Time = segments[t] } } } ; } } } finally { maskHandle.Value.Free(); } } }
/// <summary> /// Stretches the 3D cell cube into the sequence of GeoCellTuple /// </summary> /// <param name="lat"></param> /// <param name="lon"></param> /// <param name="region"></param> /// <param name="mask"></param> /// <returns></returns> public static IEnumerable <IGeoCell> StretchCellGrid(double[] lat, double[] lon, ITimeRegion region, Array mask = null) { int latLen = lat.Length; int lonLen = lon.Length; int timeLen = region.SegmentsCount; ITimeSegment[] segments = region.GetSegments().ToArray(); if (mask == null) { for (int i = 0; i < lonLen - 1; i++) { double lonminV = lon[i]; double lonmaxV = lon[i + 1]; for (int j = 0; j < latLen - 1; j++) { double latminV = lat[j]; double latmaxV = lat[j + 1]; for (int t = 0; t < timeLen; t++) { yield return new GeoCell { LatMin = latminV, LatMax = latmaxV, LonMin = lonminV, LonMax = lonmaxV, Time = segments[t] } } ; } } } else { GCHandle?maskHandle = GCHandle.Alloc(mask, GCHandleType.Pinned); IntPtr maskPtr = maskHandle.Value.AddrOfPinnedObject(); try { int firstDimLen = lonLen - 1; int secondDimLen = latLen - 1; int lastTwoDimsLen = timeLen * secondDimLen; for (int i = 0; i < firstDimLen; i++) { double lonminV = lon[i]; double lonmaxV = lon[i + 1]; for (int j = 0; j < secondDimLen; j++) { double latminV = lat[j]; double latmaxV = lat[j + 1]; for (int t = 0; t < timeLen; t++) { if (checkMdBoolArray(maskPtr, i * lastTwoDimsLen + j * timeLen + t)) { yield return new GeoCell { LatMin = latminV, LatMax = latmaxV, LonMin = lonminV, LonMax = lonmaxV, Time = segments[t] } } } ; } } } finally { maskHandle.Value.Free(); } } }