OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.78k stars 2.5k forks source link

GDAL can't open Chang'E PDS file #796

Closed MinluLi closed 5 years ago

MinluLi commented 6 years ago

Expected behavior and actual behavior.

When I use GDAL to open the PDS data of Chang'E, the prompt cannot be opened. Chang'E data is stored in the NASA PDS format, you can find more details in the link http://moon.bao.ac.cn/index_en.jsp

The test data header like this:

PDS_VERSION_ID = PDS3 RECORD_TYPE = FIXED_LENGTH RECORD_BYTES = 581 FILE_RECORDS = 7536 LABEL_RECORDS = 8 INTERCHANGE_FORMAT = BINARY ^IMAGE_PREFIX = 9 ^IMAGE = 9 /IMAGE DESCRIPTION /

DATA_SET_ID = PRODUCT_NAME = CCD Stereo Camera Science Data Product PRODUCT_ID = CE1_CCD-N_2C PUBLICATION_DATE = 2009-02-24T00:38:45.000z

PRODUCT_CREATION_TIME = 2009-02-24T00:38:45.000z

SPACECRAFT_NAME = "CE1" OBJECT = IMAGE_PREFIX INTERCHANGE_FORMAT = Binary ROWS = 7528 ROW_BYTES = 581 ROW_SUFFIX_BYTES = 512 COLUMNS = 6 OBJECT = COLUMN NAME = "Time" COLUMN_NUMBER = 1 DATA_TYPE = DATE START_BYTE = 1 BYTES = 24 FORMAT = "A24" UNIT = N/A DESCRIPTION = "Satellite time(UTC)" END_OBJECT = COLUMN OBJECT = COLUMN NAME = "Flag" COLUMN_NUMBER = 2 DATA_TYPE = ASCII_INTEGER START_BYTE = 26 BYTES = 3 FORMAT = "I3" UNIT = N/A DESCRIPTION = "N/A" END_OBJECT = COLUMN OBJECT = COLUMN NAME = "Longitude 1" COLUMN_NUMBER = 3 DATA_TYPE = FLOAT START_BYTE = 30 BYTES = 9 FORMAT = "F9.4" UNIT = Degree DESCRIPTION = "N/A" END_OBJECT = COLUMN OBJECT = COLUMN NAME = "Latitude 1" COLUMN_NUMBER = 4 DATA_TYPE = FLOAT START_BYTE = 40 BYTES = 9 FORMAT = "F9.4" UNIT = Degree DESCRIPTION = "N/A" END_OBJECT = COLUMN OBJECT = COLUMN NAME = "Longitude 512" COLUMN_NUMBER = 5 DATA_TYPE = FLOAT START_BYTE = 50 BYTES = 9 FORMAT = "F9.4" UNIT = Degree DESCRIPTION = "N/A" END_OBJECT = COLUMN OBJECT = COLUMN NAME = "Latitude 512" COLUMN_NUMBER = 6 DATA_TYPE = FLOAT START_BYTE = 60 BYTES = 9 FORMAT = "F9.4" UNIT = Degree DESCRIPTION = "N/A" END_OBJECT = COLUMN END_OBJECT =IMAGE_PREFIX OBJECT = IMAGE LINES = 7528 LINE_SAMPLES = 512 SAMPLE_TYPE = UNSIGNED_INTEGER SAMPLE_BITS = 8 LINE_PREFIX_BYTES =69 END_OBJECT = IMAGE

END

Steps to reproduce the problem.

gdalinfo.exe D:\SatData\CE\CE1_BMYK_CCD-N_SCI_N_20080728230330_20080729011114_3005_B.2C --debug on GDAL: Auto register E:\gdal\gdalplugins\gdal_ECW_JP2ECW.dll using GDALRegister_ECW_JP2ECW. GDAL: Auto register E:\gdal\gdalplugins\gdal_FITS.dll using GDALRegister_FITS. GDAL: Auto register E:\gdal\gdalplugins\ogr_FileGDB.dll using RegisterOGRFileGDB. GNM: GNMRegisterAllInternal GNM: RegisterGNMFile GNM: RegisterGNMdatabase ERROR 4: `D:\SatData\CE\CE1_BMYK_CCD-N_SCI_N_20080728230330_20080729011114_3005_B.2C' not recognized as a supported file format. gdalinfo failed - unable to open 'D:\SatData\CE\CE1_BMYK_CCD-N_SCI_N_20080728230330_20080729011114_3005_B.2C'.

Operating system

Windows 10 64-bit

GDAL version and provenance

github trunk gdalinfo.exe --version GDAL 2.4.0dev, released 2018/99/99

MinluLi commented 6 years ago

test data

CE.zip

rouault commented 6 years ago

I've investigated. There are at least 2 issues in the PDS header of those datasets:

diff --git a/gdal/frmts/pds/nasakeywordhandler.cpp b/gdal/frmts/pds/nasakeywordhandler.cpp
index 6c2f539..dfeb907 100644
--- a/gdal/frmts/pds/nasakeywordhandler.cpp
+++ b/gdal/frmts/pds/nasakeywordhandler.cpp
@@ -231,9 +231,25 @@ int NASAKeywordHandler::ReadPair( CPLString &osName, CPLString &osValue,

     pszHeaderNext++;

-    SkipWhite();
+    if( !EQUAL(osName, "OBJECT") && !EQUAL(osName, "GROUP") &&
+        (*pszHeaderNext == 13 && pszHeaderNext[1] == 10) )
+    {
+        pszHeaderNext += 2;
+        oCur.Add(osName, "");
+        return TRUE;
+    }
+    else if( !EQUAL(osName, "OBJECT") && !EQUAL(osName, "GROUP") &&
+             *pszHeaderNext == 10 )
+    {
+        pszHeaderNext ++;
+        oCur.Add(osName, "");
+        return TRUE;
+    }
+    else
+    {
+        SkipWhite();
+    }

-    osValue = "";
     bool bIsString = true;

     // Handle value lists like:
rouault commented 6 years ago

@thareUSGS Do you think that the above datasets should be handled by the PDS driver ? See my above comment about 2 issues I found in their PDS header

thareUSGS commented 5 years ago

@MinluLi For PDS3 label it is good to have quotes around strings with spaces. Also for DATA_SET_ID, I would think either remove it or set it to "" or None. If you are okay to correct those labels, can we close this ticket?

MinluLi commented 5 years ago

@MinluLi For PDS3 label it is good to have quotes around strings with spaces. Also for DATA_SET_ID, I would think either remove it or set it to "" or None. If you are okay to correct those labels, can we close this ticket?

OK,you can close this