|
|||||||
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello everyone,
I am trying to write a file in HDF-EOS2 format with VC++6.0 by using hdf4.2 libs and hdfeos v2 libs. I have written one, but the geographic information of it cannot be identified by MRT and ENVI. The following is my code to write HDF-EOS2 files. long GlassAlbedo03HDF::WriteHDFEOS(const char* pathname, ImageSampler16i *albedoimg[2], ImageSampler16u *newQCimage,float64 ulc[2],float64 lrc[2],int32 dimsizes[2]) //the pathname is the name of the file to write. //the second and third parament is the image data to write. //the ulc and lrc is the coner point coordinate which read from a MODIS file. //the element of dimsizes is both 1200*1200 { int fileID = 0, gridID = 0 , status = 0; //define grid parameters char gridName[] = "GLASS03_AB1_Albedo"; int32 Line = dimsizes[0], Sample = dimsizes[1]; int32 rank = 2; int32 start[2] = {0,0}; int32 edges[2] = {Line,Sample};int32 stride[2] = {1,1}; //define the Projection Parameters int32 projcode = 16; int32 zonecode = -1; int32 spherecode = -1; float64 projparam[16] = {6371007.1809999999,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ; char outputname[512]; strcpy(outputname,pathname); //define data field Parameters char Band1[] = "Albedo_BSA_shortwave"; char Band2[] = "Albedo_WSA_shortwave"; char Band3[] = "QA"; char dimName[] = "YDim,XDim"; int compparm[] ={5}; int fillvalue = -1; //Create HDF-EOS File fileID = GDopen(outputname,DFACC_CREATE); if (fileID == -1) { printf("Create HDFEOS Failed!\n"); return 4; } // GDclose(fileID); //Create grid field // fileID = GDopen(outputname,DFACC_RDWR); if (fileID == -1) { printf("Attach HDFEOS Failed!\n"); return 4; } gridID = GDcreate(fileID,gridName,Line,Sample,ulc,lrc); if(gridID == -1) { printf("Create Albedo Grid Failed\n"); return 4; } status = GDdefproj(gridID,projcode,zonecode,spherecode,proj param); if(status != 0 ) printf("error in projection define!\n"); GDdetach(gridID); //Create data field BSA gridID = GDattach(fileID,gridName); if(gridID == -1) { printf("Attach HDF Grid failed\n"); return 4; } status = GDdeforigin(gridID,HDFE_GD_UL); // status = GDdefcomp(gridID,HDFE_COMP_RLE,NULL); status = GDdeffield(gridID,Band1,dimName,DFNT_INT16,HDFE_NO MERGE); if(status != 0) { printf("error in data field defining!\n"); return 4; } status = GDsetfillvalue(gridID,Band1,&fillvalue); status = GDsettilecomp(gridID,Band1,rank,dimsizes,HDFE_COMP _DEFLATE,compparm); // GDdetach(gridID); // GDclose(fileID); //Write data field BSA // fileID = GDopen(outputname,DFACC_RDWR); // gridID = GDattach(fileID,gridName); status = GDwritefield(gridID,Band1,start,stride,edges,albed oimg[0]->pimg); if(status != 0) { printf("%d %s\n",gridID,Band1); printf("error in data field1 writing!\n"); return 4; } GDdetach(gridID); //Create data field WSA gridID = GDattach(fileID,gridName); if(gridID == -1) { printf("Attach HDF Grid failed\n"); return 4; } // status = GDdefcomp(gridID,HDFE_COMP_RLE,NULL); status = GDdeforigin(gridID,HDFE_GD_UL); status = GDdeffield(gridID,Band2,dimName,DFNT_INT16,HDFE_NO MERGE); if(status != 0) { printf("error in data field defining!\n"); return 4; } status = GDsetfillvalue(gridID,Band2,&fillvalue); status = GDsettilecomp(gridID,Band2,rank,dimsizes,HDFE_COMP _DEFLATE,compparm); // GDdetach(gridID); //Write data field WSA // gridID = GDattach(fileID,gridName); status = GDwritefield(gridID,Band2,start,stride,edges,albed oimg[1]->pimg); if(status != 0) { printf("error in data field2 writing!\n"); return 4; } GDdetach(gridID); //Create data field QC gridID = GDattach(fileID,gridName); if(gridID == -1) { printf("Attach HDF Grid failed\n"); return 4; } status = GDdeforigin(gridID,HDFE_GD_UL); // status = GDdefcomp(gridID,HDFE_COMP_RLE,NULL); status = GDdeffield(gridID,Band3,dimName,DFNT_UINT16,HDFE_N OMERGE); if(status != 0) { printf("error in data field defining!\n"); return 4; } int fillvalue2 = 39171; status = GDsetfillvalue(gridID,Band3,&fillvalue2); status = GDsettilecomp(gridID,Band3,rank,dimsizes,HDFE_COMP _DEFLATE,compparm); // GDdetach(gridID); //Write data field QC // gridID = GDattach(fileID,gridName); status = GDwritefield(gridID,Band3,start,stride,edges,newQC image->pimg); if(status != 0) { printf("error in data field3 writing!\n"); return 4; } GDdetach(gridID); GDclose(fileID); return status; } How can I solve this problem?
|
| Tags |
| coordinate, hdf-eos, modis, projection |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|