~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to frmts/jaxapalsar/jaxapalsardataset.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: jaxapalsardataset.cpp 17664 2009-09-21 21:16:45Z rouault $
 
2
 * $Id: jaxapalsardataset.cpp 22636 2011-07-03 10:39:11Z rouault $
3
3
 *
4
4
 * Project:  PALSAR JAXA imagery reader
5
5
 * Purpose:  Support for PALSAR L1.1/1.5 imagery and appropriate metadata from
31
31
 
32
32
#include "gdal_pam.h"
33
33
 
34
 
CPL_CVSID("$Id: jaxapalsardataset.cpp 17664 2009-09-21 21:16:45Z rouault $");
 
34
CPL_CVSID("$Id: jaxapalsardataset.cpp 22636 2011-07-03 10:39:11Z rouault $");
35
35
 
36
36
CPL_C_START
37
37
void    GDALRegister_PALSARJaxa(void);
138
138
/* a few useful enums */
139
139
enum eFileType {
140
140
        level_11 = 0,
141
 
        level_15
 
141
        level_15,
 
142
    level_10
142
143
};
143
144
 
144
145
enum ePolarization {
171
172
 
172
173
    static GDALDataset *Open( GDALOpenInfo *poOpenInfo );
173
174
    static int Identify( GDALOpenInfo *poOpenInfo );
174
 
    static void ReadMetadata( PALSARJaxaDataset *poDS, FILE *fp );
 
175
    static void ReadMetadata( PALSARJaxaDataset *poDS, VSILFILE *fp );
175
176
};
176
177
 
177
178
PALSARJaxaDataset::PALSARJaxaDataset()
196
197
/************************************************************************/
197
198
 
198
199
class PALSARJaxaRasterBand : public GDALRasterBand {
199
 
    FILE *fp;
 
200
    VSILFILE *fp;
200
201
    int nRasterXSize;
201
202
    int nRasterYSize;
202
203
    ePolarization nPolarization;
205
206
    int nSamplesPerGroup;
206
207
    int nRecordSize;
207
208
public:
208
 
    PALSARJaxaRasterBand( PALSARJaxaDataset *poDS, int nBand, FILE *fp );
 
209
    PALSARJaxaRasterBand( PALSARJaxaDataset *poDS, int nBand, VSILFILE *fp );
209
210
    ~PALSARJaxaRasterBand();
210
211
 
211
212
    CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage );
216
217
/************************************************************************/
217
218
 
218
219
PALSARJaxaRasterBand::PALSARJaxaRasterBand( PALSARJaxaDataset *poDS, 
219
 
        int nBand, FILE *fp ) 
 
220
        int nBand, VSILFILE *fp )
220
221
{
221
222
    this->fp = fp;
222
223
 
231
232
        eDataType = GDT_CFloat32;
232
233
        nFileType = level_11;
233
234
    }
 
235
    else if (nBitsPerSample == 8 && nSamplesPerGroup == 2) {
 
236
        eDataType = GDT_CInt16; /* shuold be 2 x signed byte */
 
237
        nFileType = level_10;
 
238
    }
234
239
    else {
235
 
        eDataType = GDT_Int16;
 
240
        eDataType = GDT_UInt16;
236
241
        nFileType = level_15;
237
242
    }
238
243
 
243
248
    READ_CHAR_VAL( nRasterYSize, NUMBER_LINES_LENGTH, fp );
244
249
    VSIFSeekL( fp, SAR_DATA_RECORD_LENGTH_OFFSET, SEEK_SET );
245
250
    READ_CHAR_VAL( nRecordSize, SAR_DATA_RECORD_LENGTH_LENGTH, fp );
246
 
    nRasterXSize = (nRecordSize - 
247
 
                    (nFileType == level_11 ? SIG_DAT_REC_OFFSET : PROC_DAT_REC_OFFSET))
 
251
    nRasterXSize = (nRecordSize -
 
252
                    (nFileType != level_15 ? SIG_DAT_REC_OFFSET : PROC_DAT_REC_OFFSET))
248
253
        / ((nBitsPerSample / 8) * nSamplesPerGroup);
249
254
 
250
255
    poDS->nRasterXSize = nRasterXSize;
348
353
/*                            ReadMetadata()                            */
349
354
/************************************************************************/
350
355
 
351
 
void PALSARJaxaDataset::ReadMetadata( PALSARJaxaDataset *poDS, FILE *fp ) {
 
356
void PALSARJaxaDataset::ReadMetadata( PALSARJaxaDataset *poDS, VSILFILE *fp ) {
352
357
    /* seek to the end fo the leader file descriptor */
353
358
    VSIFSeekL( fp, LEADER_FILE_DESCRIPTOR_LENGTH, SEEK_SET );
354
 
    if (poDS->nFileType == level_11) {
 
359
    if (poDS->nFileType == level_10) {
 
360
        poDS->SetMetadataItem( "PRODUCT_LEVEL", "1.0" );
 
361
        poDS->SetMetadataItem( "AZIMUTH_LOOKS", "1.0" );
 
362
    }
 
363
    else if (poDS->nFileType == level_11) {
355
364
        poDS->SetMetadataItem( "PRODUCT_LEVEL", "1.1" );
356
365
        poDS->SetMetadataItem( "AZIMUTH_LOOKS", "1.0" );
357
366
    }
459
468
/************************************************************************/
460
469
 
461
470
int PALSARJaxaDataset::Identify( GDALOpenInfo *poOpenInfo ) {
462
 
    if ( poOpenInfo->fp == NULL || poOpenInfo->nHeaderBytes < 360 )
 
471
    if ( poOpenInfo->nHeaderBytes < 360 )
463
472
        return 0;
464
473
 
465
474
    /* First, check that this is a PALSAR image indeed */
470
479
        return 0;
471
480
    }
472
481
 
473
 
    FILE *fpL = VSIFOpenL( poOpenInfo->pszFilename, "r" );
 
482
    VSILFILE *fpL = VSIFOpenL( poOpenInfo->pszFilename, "r" );
474
483
    if( fpL == NULL )
475
484
        return FALSE;
476
485
 
536
545
    int nBandNum = 1;
537
546
 
538
547
    /* HH */
539
 
    FILE *fpHH;
 
548
    VSILFILE *fpHH;
540
549
    sprintf( pszImgFile, "%s%sIMG-HH%s", 
541
550
             CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix );
542
551
    fpHH = VSIFOpenL( pszImgFile, "rb" );
546
555
    }
547
556
 
548
557
    /* HV */
549
 
    FILE *fpHV;
 
558
    VSILFILE *fpHV;
550
559
    sprintf( pszImgFile, "%s%sIMG-HV%s", 
551
560
             CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix );
552
561
    fpHV = VSIFOpenL( pszImgFile, "rb" );
556
565
    }
557
566
 
558
567
    /* VH */
559
 
    FILE *fpVH;
 
568
    VSILFILE *fpVH;
560
569
    sprintf( pszImgFile, "%s%sIMG-VH%s", 
561
570
             CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix );
562
571
    fpVH = VSIFOpenL( pszImgFile, "rb" );
566
575
    }
567
576
 
568
577
    /* VV */
569
 
    FILE *fpVV;
 
578
    VSILFILE *fpVV;
570
579
    sprintf( pszImgFile, "%s%sIMG-VV%s",
571
580
             CPLGetDirname(poOpenInfo->pszFilename), SEP_STRING, pszSuffix );
572
581
    fpVV = VSIFOpenL( pszImgFile, "rb" );
582
591
        CPLError( CE_Failure, CPLE_AppDefined,
583
592
                  "Unable to find any image data. Aborting opening as PALSAR image.");
584
593
        delete poDS;
 
594
        VSIFree( pszSuffix );
 
595
        return NULL;
 
596
    }
 
597
 
 
598
    /* Level 1.0 products are not supported */
 
599
    if (poDS->nFileType == level_10) {
 
600
        CPLError( CE_Failure, CPLE_AppDefined,
 
601
                  "ALOS PALSAR Level 1.0 products are not supported. Aborting opening as PALSAR image.");
 
602
        delete poDS;
 
603
        VSIFree( pszSuffix );
585
604
        return NULL;
586
605
    }
587
606
 
592
611
    sprintf( pszLeaderFilename, "%s%sLED%s", 
593
612
             CPLGetDirname( poOpenInfo->pszFilename ) , SEP_STRING, pszSuffix );
594
613
 
595
 
    FILE *fpLeader = VSIFOpenL( pszLeaderFilename, "rb" );
 
614
    VSILFILE *fpLeader = VSIFOpenL( pszLeaderFilename, "rb" );
596
615
    /* check if the leader is actually present */
597
616
    if (fpLeader != NULL) {
598
617
        ReadMetadata(poDS, fpLeader);
633
652
                                   "frmt_palsar.html" );
634
653
        poDriver->pfnOpen = PALSARJaxaDataset::Open;
635
654
        poDriver->pfnIdentify = PALSARJaxaDataset::Identify;
 
655
        poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
 
656
 
636
657
        GetGDALDriverManager()->RegisterDriver( poDriver );
637
658
    }
638
659
}