private static SDataByProject <T> DoProject <T>(T[,] sourcedata, T fillValue, ref Size outStepSize, ref Size srcStepSize, T[,] dstData, UInt16[] rows, UInt16[] cols) { //投影不同分块的数据集 RasterProjector _rasterProjector = new RasterProjector(); _rasterProjector.ProjectNew <T>(sourcedata, srcStepSize, rows, cols, outStepSize, dstData, fillValue); SDataByProject <T> returnvalue = new SDataByProject <T>(); returnvalue.Data = dstData; return(returnvalue); }
private static void ConvertHdf4To5BySds <T>(Hdf4FileAttrs hdf4FileAttrs, int nyf5, int nxf5, int k, int rank, H5FileId fileId, string sdName, HDF4Helper.DataTypeDefinitions dtaDefinitions, Action <string, int, int> messageAction, SEnvelope envelopeNew, T fillValue, float dstResolution, ISpatialReference dstSpatialReference, ref UInt16[] rows, ref UInt16[] cols, ref Size srcStepSize, ref Size outSize) { T[,] data = new T[nyf5, nxf5]; H5DataSetId dsetId = null; T[,] dataNew = null; SDataByProject <T> dataByProject = null; try { for (int i = 0; i < hdf4FileAttrs.Count; i++) { Hdf4FileAttr hdf4FileAttr = hdf4FileAttrs[i]; if (messageAction != null) { messageAction(String.Format("正在转换数据集 {0}", sdName), k, i); } H4SDS sd = hdf4FileAttr.H4File.Datasets[k]; GetDataByHdf4(sd, rank, hdf4FileAttr, data); } dataNew = data; if (outSize.IsEmpty) { outSize = new Size(nxf5, nyf5); } if (dstSpatialReference != null && dstSpatialReference.IsSame(SpatialReference.GetDefault())) { if (rows == null && cols == null) { PrjEnvelope srcEnvelope = new PrjEnvelope(hdf4FileAttrs.Hdf4FileAttr.Envelope.XMin, hdf4FileAttrs.Hdf4FileAttr.Envelope.XMax, hdf4FileAttrs.Hdf4FileAttr.Envelope.YMin, hdf4FileAttrs.Hdf4FileAttr.Envelope.YMax); PrjEnvelope outenvelpoe = new PrjEnvelope(envelopeNew.XMin, envelopeNew.XMax, envelopeNew.YMin, envelopeNew.YMax); FilePrjSettings prjSetting = new FilePrjSettings(); prjSetting.OutEnvelope = outenvelpoe; prjSetting.OutResolutionX = dstResolution; prjSetting.OutResolutionY = dstResolution; outSize = prjSetting.OutSize; Size inSize = new Size(hdf4FileAttrs.Hdf4FileAttr.XDim, hdf4FileAttrs.Hdf4FileAttr.YDim); float dstResoultion = dstResolution; float srcResoultionX = (float)(hdf4FileAttrs.Hdf4FileAttr.CellWidth); float srcResoultionY = (float)(hdf4FileAttrs.Hdf4FileAttr.CellHeight); dataByProject = GetDataByProject <T>(dataNew, srcEnvelope, outenvelpoe, inSize, outSize, dstResoultion, srcResoultionX, srcResoultionY, fillValue, dstSpatialReference, out rows, out cols, out srcStepSize); } else { T[,] dstData = new T[outSize.Height, outSize.Width]; dataByProject = DoProject <T>(dataNew, fillValue, ref outSize, ref srcStepSize, dstData, rows, cols); } if (dataByProject != null) { dataNew = dataByProject.Data; } } long[] dims = new long[rank]; dims[0] = Convert.ToInt64(outSize.Height); dims[1] = Convert.ToInt64(outSize.Width); H5DataSpaceId dspaceId = H5S.create_simple(rank, dims); H5T.H5Type h5Type = Utility.GetH5Type(dtaDefinitions); // Define datatype for the data in the file. H5DataTypeId dtypeId = H5T.copy(h5Type); // Create the data set DATASETNAME. dsetId = H5D.create(fileId, sdName, dtypeId, dspaceId); // Write the one-dimensional data set array H5D.write(dsetId, new H5DataTypeId(h5Type), new H5Array <T>(dataNew));//H5A HDFAttributeDef[] attributeDef5s = hdf4FileAttrs[0].DatasetsAttributeDefs[k]; foreach (HDFAttributeDef attributeDef5 in attributeDef5s) { WriteHdfAttributes.WriteHdfAttribute(dsetId, attributeDef5); } } finally { // Close dataset and file. if (dsetId != null) { H5D.close(dsetId); } if (data != null) { data = null; } if (dataNew != null) { dataNew = null; } GC.Collect(); } }