SIGDEMRasterBand::SIGDEMRasterBand( SIGDEMDataset *poDSIn, VSILFILE *fpRawIn, double dfMinZ, double dfMaxZ) : dfOffsetZ(poDSIn->sHeader.dfOffsetZ), dfScaleFactorZ(poDSIn->sHeader.dfScaleFactorZ), fpRawL(fpRawIn) { this->poDS = poDSIn; this->nBand = 1; this->nRasterXSize = poDSIn->GetRasterXSize(); this->nRasterYSize = poDSIn->GetRasterYSize(); this->nBlockXSize = this->nRasterXSize; this->nBlockYSize = 1; this->eDataType = GDT_Float64; this->nBlockSizeBytes = nRasterXSize * CELL_SIZE_FILE; this->pBlockBuffer = static_cast<int32_t*>( VSI_MALLOC2_VERBOSE(nRasterXSize, sizeof(int32_t))); SetNoDataValue(-9999); CPLString osValue; SetMetadataItem("STATISTICS_MINIMUM", osValue.Printf("%.15g", dfMinZ)); SetMetadataItem("STATISTICS_MAXIMUM", osValue.Printf("%.15g", dfMaxZ)); }
TSXRasterBand::TSXRasterBand( TSXDataset *poDS, GDALDataType eDataType, ePolarization ePol, GDALDataset *poBand ) { this->poDS = poDS; this->eDataType = eDataType; this->ePol = ePol; switch (ePol) { case HH: SetMetadataItem( "POLARIMETRIC_INTERP", "HH" ); break; case HV: SetMetadataItem( "POLARIMETRIC_INTERP", "HV" ); break; case VH: SetMetadataItem( "POLARIMETRIC_INTERP", "VH" ); break; case VV: SetMetadataItem( "POLARIMETRIC_INTERP", "VV" ); break; } /* now setup the actual raster reader */ this->poBand = poBand; GDALRasterBand *poSrcBand = poBand->GetRasterBand( 1 ); poSrcBand->GetBlockSize( &nBlockXSize, &nBlockYSize ); }
TSXRasterBand::TSXRasterBand( TSXDataset *poDSIn, GDALDataType eDataTypeIn, ePolarization ePolIn, GDALDataset *poBandIn ) : poBand(poBandIn), ePol(ePolIn) { poDS = poDSIn; eDataType = eDataTypeIn; switch (ePol) { case HH: SetMetadataItem( "POLARIMETRIC_INTERP", "HH" ); break; case HV: SetMetadataItem( "POLARIMETRIC_INTERP", "HV" ); break; case VH: SetMetadataItem( "POLARIMETRIC_INTERP", "VH" ); break; case VV: SetMetadataItem( "POLARIMETRIC_INTERP", "VV" ); break; } /* now setup the actual raster reader */ GDALRasterBand *poSrcBand = poBandIn->GetRasterBand( 1 ); poSrcBand->GetBlockSize( &nBlockXSize, &nBlockYSize ); }
CPLErr VRTRasterBand::CopyCommonInfoFrom( GDALRasterBand * poSrcBand ) { SetMetadata( poSrcBand->GetMetadata() ); const char* pszNBits = poSrcBand->GetMetadataItem("NBITS", "IMAGE_STRUCTURE"); SetMetadataItem( "NBITS", pszNBits, "IMAGE_STRUCTURE" ); const char* pszPixelType = poSrcBand->GetMetadataItem("PIXELTYPE", "IMAGE_STRUCTURE"); SetMetadataItem( "PIXELTYPE", pszPixelType, "IMAGE_STRUCTURE" ); SetColorTable( poSrcBand->GetColorTable() ); SetColorInterpretation(poSrcBand->GetColorInterpretation()); if( strlen(poSrcBand->GetDescription()) > 0 ) SetDescription( poSrcBand->GetDescription() ); int bSuccess; double dfNoData; dfNoData = poSrcBand->GetNoDataValue( &bSuccess ); if( bSuccess ) SetNoDataValue( dfNoData ); SetOffset( poSrcBand->GetOffset() ); SetScale( poSrcBand->GetScale() ); SetCategoryNames( poSrcBand->GetCategoryNames() ); if( !EQUAL(poSrcBand->GetUnitType(),"") ) SetUnitType( poSrcBand->GetUnitType() ); return CE_None; }
CALSWrapperSrcDataset( GDALDataset* poSrcDS, const char* pszPadding ) { nRasterXSize = poSrcDS->GetRasterXSize(); nRasterYSize = poSrcDS->GetRasterYSize(); SetBand(1, new CALSWrapperSrcBand(poSrcDS)); SetMetadataItem("TIFFTAG_DOCUMENTNAME", pszPadding); }
void OGRGeoJSONLayer::AddFeature( OGRFeature* poFeature ) { CPLAssert( NULL != poFeature ); // NOTE - mloskot: // Features may not be sorted according to FID values. // TODO: Should we check if feature already exists? // TODO: Think about sync operation, upload, etc. OGRFeature* poNewFeature = NULL; poNewFeature = poFeature->Clone(); if( -1 == poNewFeature->GetFID() ) { int nFID = static_cast<int>(seqFeatures_.size()); poNewFeature->SetFID( nFID ); // TODO - mlokot: We need to redesign creation of FID column int nField = poNewFeature->GetFieldIndex( DefaultFIDColumn ); if( -1 != nField && GetLayerDefn()->GetFieldDefn(nField)->GetType() == OFTInteger ) { poNewFeature->SetField( nField, nFID ); } } if( (GIntBig)(int)poNewFeature->GetFID() != poNewFeature->GetFID() ) SetMetadataItem(OLMD_FID64, "YES"); seqFeatures_.push_back( poNewFeature ); }
/*! \param map PCRaster map handle. It is ours to close. */ PCRasterDataset::PCRasterDataset( MAP* map) : GDALPamDataset(), d_map(map), d_west(0.0), d_north(0.0), d_cellSize(0.0) { // Read header info. nRasterXSize = RgetNrCols(d_map); nRasterYSize = RgetNrRows(d_map); d_west = static_cast<double>(RgetXUL(d_map)); d_north = static_cast<double>(RgetYUL(d_map)); d_cellSize = static_cast<double>(RgetCellSize(d_map)); d_cellRepresentation = RgetUseCellRepr(d_map); CPLAssert(d_cellRepresentation != CR_UNDEFINED); d_valueScale = RgetValueScale(d_map); CPLAssert(d_valueScale != VS_UNDEFINED); d_defaultNoDataValue = ::missingValue(d_cellRepresentation); d_location_changed = false; // Create band information objects. nBands = 1; SetBand(1, new PCRasterRasterBand(this)); SetMetadataItem("PCRASTER_VALUESCALE", valueScale2String( d_valueScale).c_str()); }
GRIBRasterBand::GRIBRasterBand( GRIBDataset *poDS, int nBand, inventoryType *psInv ) : m_Grib_Data(NULL), m_Grib_MetaData(NULL) { this->poDS = poDS; this->nBand = nBand; this->start = psInv->start; this->subgNum = psInv->subgNum; this->longFstLevel = CPLStrdup(psInv->longFstLevel); eDataType = GDT_Float64; // let user do -ot Float32 if needed for saving space, GRIB contains Float64 (though not fully utilized most of the time) nBlockXSize = poDS->nRasterXSize; nBlockYSize = 1; nGribDataXSize = poDS->nRasterXSize; nGribDataYSize = poDS->nRasterYSize; SetMetadataItem( "GRIB_UNIT", psInv->unitName ); SetMetadataItem( "GRIB_COMMENT", psInv->comment ); SetMetadataItem( "GRIB_ELEMENT", psInv->element ); SetMetadataItem( "GRIB_SHORT_NAME", psInv->shortFstLevel ); SetMetadataItem( "GRIB_REF_TIME", CPLString().Printf("%12.0f sec UTC", psInv->refTime ) ); SetMetadataItem( "GRIB_VALID_TIME", CPLString().Printf("%12.0f sec UTC", psInv->validTime ) ); SetMetadataItem( "GRIB_FORECAST_SECONDS", CPLString().Printf("%.0f sec", psInv->foreSec ) ); }
void NTv2Dataset::CaptureMetadataItem( char *pszItem ) { CPLString osKey, osValue; osKey.assign( pszItem, 8 ); osValue.assign( pszItem+8, 8 ); SetMetadataItem( osKey.Trim(), osValue.Trim() ); }
CPLErr GeoRasterRasterBand::GetStatistics( int bApproxOK, int bForce, double *pdfMin, double *pdfMax, double *pdfMean, double *pdfStdDev ) { (void) bForce; (void) bApproxOK; char szMin[MAX_DOUBLE_STR_REP + 1]; char szMax[MAX_DOUBLE_STR_REP + 1]; char szMean[MAX_DOUBLE_STR_REP + 1]; char szMedian[MAX_DOUBLE_STR_REP + 1]; char szMode[MAX_DOUBLE_STR_REP + 1]; char szStdDev[MAX_DOUBLE_STR_REP + 1]; char szSampling[MAX_DOUBLE_STR_REP + 1]; if( ! bValidStats ) { bValidStats = poGeoRaster->GetStatistics( nBand, szMin, szMax, szMean, szMedian, szMode, szStdDev, szSampling ); } if( bValidStats ) { dfMin = CPLScanDouble( szMin, MAX_DOUBLE_STR_REP ); dfMax = CPLScanDouble( szMax, MAX_DOUBLE_STR_REP ); dfMean = CPLScanDouble( szMean, MAX_DOUBLE_STR_REP ); dfMedian = CPLScanDouble( szMedian, MAX_DOUBLE_STR_REP ); dfMode = CPLScanDouble( szMode, MAX_DOUBLE_STR_REP ); dfStdDev = CPLScanDouble( szStdDev, MAX_DOUBLE_STR_REP ); SetMetadataItem( "STATISTICS_MINIMUM", szMin ); SetMetadataItem( "STATISTICS_MAXIMUM", szMax ); SetMetadataItem( "STATISTICS_MEAN", szMean ); SetMetadataItem( "STATISTICS_MEDIAN", szMedian ); SetMetadataItem( "STATISTICS_MODE", szMode ); SetMetadataItem( "STATISTICS_STDDEV", szStdDev ); SetMetadataItem( "STATISTICS_SKIPFACTORX", szSampling ); SetMetadataItem( "STATISTICS_SKIPFACTORY", szSampling ); *pdfMin = dfMin; *pdfMax = dfMax; *pdfMean = dfMean; *pdfStdDev = dfStdDev; return CE_None; } return CE_Failure; }
SAFERasterBand::SAFERasterBand( SAFEDataset *poDSIn, GDALDataType eDataTypeIn, const char *pszSwath, const char *pszPolarisation, GDALDataset *poBandFileIn ) : poBandFile(poBandFileIn) { poDS = poDSIn; GDALRasterBand *poSrcBand = poBandFile->GetRasterBand( 1 ); poSrcBand->GetBlockSize( &nBlockXSize, &nBlockYSize ); eDataType = eDataTypeIn; if( *pszSwath != '\0' ) { SetMetadataItem( "SWATH", pszSwath ); } if( *pszPolarisation != '\0' ) { SetMetadataItem( "POLARISATION", pszPolarisation ); } }
AirSARRasterBand::AirSARRasterBand( AirSARDataset *poDSIn, int nBandIn ) { poDS = poDSIn; nBand = nBandIn; nBlockXSize = poDS->GetRasterXSize(); nBlockYSize = 1; if( this->nBand == 2 || this->nBand == 3 || this->nBand == 5 ) eDataType = GDT_CFloat32; else eDataType = GDT_Float32; switch( nBand ) { case 1: SetMetadataItem( "POLARIMETRIC_INTERP", "Covariance_11" ); SetDescription( "Covariance_11" ); eDataType = GDT_CFloat32; break; case 2: SetMetadataItem( "POLARIMETRIC_INTERP", "Covariance_12" ); SetDescription( "Covariance_12" ); eDataType = GDT_CFloat32; break; case 3: SetMetadataItem( "POLARIMETRIC_INTERP", "Covariance_13" ); SetDescription( "Covariance_13" ); eDataType = GDT_CFloat32; break; case 4: SetMetadataItem( "POLARIMETRIC_INTERP", "Covariance_22" ); SetDescription( "Covariance_22" ); eDataType = GDT_CFloat32; break; case 5: SetMetadataItem( "POLARIMETRIC_INTERP", "Covariance_23" ); SetDescription( "Covariance_23" ); eDataType = GDT_CFloat32; break; case 6: SetMetadataItem( "POLARIMETRIC_INTERP", "Covariance_33" ); SetDescription( "Covariance_33" ); eDataType = GDT_CFloat32; break; } }
void EnvisatDataset::CollectDSDMetadata() { char *pszDSName, *pszFilename; int iDSD; for( iDSD = 0; EnvisatFile_GetDatasetInfo( hEnvisatFile, iDSD, &pszDSName, NULL, &pszFilename, NULL, NULL, NULL, NULL ) == SUCCESS; iDSD++ ) { if( pszFilename == NULL || strlen(pszFilename) == 0 || EQUALN(pszFilename,"NOT USED",8) || EQUALN(pszFilename," ",8)) continue; char szKey[128], szTrimmedName[128]; int i; strcpy( szKey, "DS_" ); strcat( szKey, pszDSName ); // strip trailing spaces. for( i = strlen(szKey)-1; i && szKey[i] == ' '; i-- ) szKey[i] = '\0'; // convert spaces into underscores. for( i = 0; szKey[i] != '\0'; i++ ) { if( szKey[i] == ' ' ) szKey[i] = '_'; } strcat( szKey, "_NAME" ); strcpy( szTrimmedName, pszFilename ); for( i = strlen(szTrimmedName)-1; i && szTrimmedName[i] == ' '; i--) szTrimmedName[i] = '\0'; SetMetadataItem( szKey, szTrimmedName ); } }
CALSWrapperSrcBand(GDALDataset* poSrcDSIn) { this->poSrcDS = poSrcDSIn; SetMetadataItem("NBITS", "1", "IMAGE_STRUCTURE"); poSrcDS->GetRasterBand(1)->GetBlockSize(&nBlockXSize, &nBlockYSize); eDataType = GDT_Byte; bInvertValues = TRUE; GDALColorTable* poCT = poSrcDS->GetRasterBand(1)->GetColorTable(); if( poCT != NULL && poCT->GetColorEntryCount() >= 2 ) { const GDALColorEntry* psEntry1 = poCT->GetColorEntry(0); const GDALColorEntry* psEntry2 = poCT->GetColorEntry(1); if( psEntry1->c1 == 255 && psEntry1->c2 == 255 && psEntry1->c3 == 255 && psEntry2->c1 == 0 && psEntry2->c2 == 0 && psEntry2->c3 == 0 ) { bInvertValues = FALSE; } } }
MEMRasterBand::MEMRasterBand( GDALDataset *poDSIn, int nBandIn, GByte *pabyDataIn, GDALDataType eTypeIn, GSpacing nPixelOffsetIn, GSpacing nLineOffsetIn, int bAssumeOwnership, const char * pszPixelType) : GDALPamRasterBand(FALSE), pabyData(pabyDataIn), // Skip nPixelOffset and nLineOffset. bOwnData(bAssumeOwnership), bNoDataSet(FALSE), dfNoData(0.0), poColorTable(NULL), eColorInterp(GCI_Undefined), pszUnitType(NULL), papszCategoryNames(NULL), dfOffset(0.0), dfScale(1.0), psSavedHistograms(NULL) { poDS = poDSIn; nBand = nBandIn; eAccess = poDS->GetAccess(); eDataType = eTypeIn; nBlockXSize = poDS->GetRasterXSize(); nBlockYSize = 1; if( nPixelOffsetIn == 0 ) nPixelOffsetIn = GDALGetDataTypeSizeBytes(eTypeIn); if( nLineOffsetIn == 0 ) nLineOffsetIn = nPixelOffsetIn * static_cast<size_t>(nBlockXSize); nPixelOffset = nPixelOffsetIn; nLineOffset = nLineOffsetIn; bOwnData = bAssumeOwnership; if( pszPixelType && EQUAL(pszPixelType,"SIGNEDBYTE") ) SetMetadataItem( "PIXELTYPE", "SIGNEDBYTE", "IMAGE_STRUCTURE" ); }
void EnvisatDataset::CollectMetadata( EnvisatFile_HeaderFlag eMPHOrSPH ) { int iKey; for( iKey = 0; TRUE; iKey++ ) { const char *pszValue, *pszKey; char szHeaderKey[128]; pszKey = EnvisatFile_GetKeyByIndex(hEnvisatFile, eMPHOrSPH, iKey); if( pszKey == NULL ) break; pszValue = EnvisatFile_GetKeyValueAsString( hEnvisatFile, eMPHOrSPH, pszKey, NULL ); if( pszValue == NULL ) continue; // skip some uninteresting structural information. if( EQUAL(pszKey,"TOT_SIZE") || EQUAL(pszKey,"SPH_SIZE") || EQUAL(pszKey,"NUM_DSD") || EQUAL(pszKey,"DSD_SIZE") || EQUAL(pszKey,"NUM_DATA_SETS") ) continue; if( eMPHOrSPH == MPH ) sprintf( szHeaderKey, "MPH_%s", pszKey ); else sprintf( szHeaderKey, "SPH_%s", pszKey ); SetMetadataItem( szHeaderKey, pszValue ); } }
void EnvisatDataset::CollectADSMetadata() { int nDSIndex, nNumDsr, nDSRSize; int nRecord; const char *pszDSName, *pszDSType, *pszDSFilename; const char *pszProduct; char *pszRecord; char szPrefix[128], szKey[128], szValue[1024]; int i; CPLErr ret; const EnvisatRecordDescr *pRecordDescr = NULL; const EnvisatFieldDescr *pField; pszProduct = EnvisatFile_GetKeyValueAsString( hEnvisatFile, MPH, "PRODUCT", "" ); for( nDSIndex = 0; EnvisatFile_GetDatasetInfo( hEnvisatFile, nDSIndex, (char **) &pszDSName, (char **) &pszDSType, (char **) &pszDSFilename, NULL, NULL, &nNumDsr, &nDSRSize ) == SUCCESS; ++nDSIndex ) { if( EQUALN(pszDSFilename,"NOT USED",8) || (nNumDsr <= 0) ) continue; if( !EQUAL(pszDSType,"A") && !EQUAL(pszDSType,"G") ) continue; for ( nRecord = 0; nRecord < nNumDsr; ++nRecord ) { strncpy( szPrefix, pszDSName, sizeof(szPrefix) - 1); szPrefix[sizeof(szPrefix) - 1] = '\0'; // strip trailing spaces for( i = strlen(szPrefix)-1; i && szPrefix[i] == ' '; --i ) szPrefix[i] = '\0'; // convert spaces into underscores for( i = 0; szPrefix[i] != '\0'; i++ ) { if( szPrefix[i] == ' ' ) szPrefix[i] = '_'; } pszRecord = (char *) CPLMalloc(nDSRSize+1); if( EnvisatFile_ReadDatasetRecord( hEnvisatFile, nDSIndex, nRecord, pszRecord ) == FAILURE ) { CPLFree( pszRecord ); return; } pRecordDescr = EnvisatFile_GetRecordDescriptor(pszProduct, pszDSName); if (pRecordDescr) { pField = pRecordDescr->pFields; while ( pField && pField->szName ) { ret = EnvisatFile_GetFieldAsString(pszRecord, nDSRSize, pField, szValue); if ( ret == CE_None ) { if (nNumDsr == 1) sprintf(szKey, "%s_%s", szPrefix, pField->szName); else // sprintf(szKey, "%s_%02d_%s", szPrefix, nRecord, sprintf(szKey, "%s_%d_%s", szPrefix, nRecord, pField->szName); SetMetadataItem(szKey, szValue, "RECORDS"); } // silently ignore conversion errors ++pField; } } CPLFree( pszRecord ); } } }
PALSARJaxaRasterBand::PALSARJaxaRasterBand( PALSARJaxaDataset *poDS, int nBand, FILE *fp ) { this->fp = fp; /* Read image options record to determine the type of data */ VSIFSeekL( fp, BITS_PER_SAMPLE_OFFSET, SEEK_SET ); nBitsPerSample = 0; nSamplesPerGroup = 0; READ_CHAR_VAL( nBitsPerSample, BITS_PER_SAMPLE_LENGTH, fp ); READ_CHAR_VAL( nSamplesPerGroup, SAMPLES_PER_GROUP_LENGTH, fp ); if (nBitsPerSample == 32 && nSamplesPerGroup == 2) { eDataType = GDT_CFloat32; nFileType = level_11; } else { eDataType = GDT_Int16; nFileType = level_15; } poDS->nFileType = nFileType; /* Read number of range/azimuth lines */ VSIFSeekL( fp, NUMBER_LINES_OFFSET, SEEK_SET ); READ_CHAR_VAL( nRasterYSize, NUMBER_LINES_LENGTH, fp ); VSIFSeekL( fp, SAR_DATA_RECORD_LENGTH_OFFSET, SEEK_SET ); READ_CHAR_VAL( nRecordSize, SAR_DATA_RECORD_LENGTH_LENGTH, fp ); nRasterXSize = (nRecordSize - (nFileType == level_11 ? SIG_DAT_REC_OFFSET : PROC_DAT_REC_OFFSET)) / ((nBitsPerSample / 8) * nSamplesPerGroup); poDS->nRasterXSize = nRasterXSize; poDS->nRasterYSize = nRasterYSize; /* Polarization */ switch (nBand) { case 0: nPolarization = hh; SetMetadataItem( "POLARIMETRIC_INTERP", "HH" ); break; case 1: nPolarization = hv; SetMetadataItem( "POLARIMETRIC_INTERP", "HV" ); break; case 2: nPolarization = vh; SetMetadataItem( "POLARIMETRIC_INTERP", "VH" ); break; case 3: nPolarization = vv; SetMetadataItem( "POLARIMETRIC_INTERP", "VV" ); break; } /* size of block we can read */ nBlockXSize = nRasterXSize; nBlockYSize = 1; /* set the file pointer to the first SAR data record */ VSIFSeekL( fp, IMAGE_OPT_DESC_LENGTH, SEEK_SET ); }
CPLErr OGRMSSQLSpatialLayer::BuildFeatureDefn( const char *pszLayerName, CPLODBCStatement *poStmt ) { poFeatureDefn = new OGRFeatureDefn( pszLayerName ); int nRawColumns = poStmt->GetColCount(); poFeatureDefn->Reference(); CPLFree(panFieldOrdinals); panFieldOrdinals = (int *) CPLMalloc( sizeof(int) * nRawColumns ); for( int iCol = 0; iCol < nRawColumns; iCol++ ) { if ( pszGeomColumn == NULL ) { /* need to identify the geometry column */ if ( EQUAL(poStmt->GetColTypeName( iCol ), "geometry") ) { nGeomColumnType = MSSQLCOLTYPE_GEOMETRY; pszGeomColumn = CPLStrdup( poStmt->GetColName(iCol) ); if (poFeatureDefn->GetGeomFieldCount() == 1) poFeatureDefn->GetGeomFieldDefn(0)->SetNullable( poStmt->GetColNullable(iCol) ); continue; } else if ( EQUAL(poStmt->GetColTypeName( iCol ), "geography") ) { nGeomColumnType = MSSQLCOLTYPE_GEOGRAPHY; pszGeomColumn = CPLStrdup( poStmt->GetColName(iCol) ); if (poFeatureDefn->GetGeomFieldCount() == 1) poFeatureDefn->GetGeomFieldDefn(0)->SetNullable( poStmt->GetColNullable(iCol) ); continue; } } else { if( EQUAL(poStmt->GetColName(iCol),pszGeomColumn) ) { if (poFeatureDefn->GetGeomFieldCount() == 1) poFeatureDefn->GetGeomFieldDefn(0)->SetNullable( poStmt->GetColNullable(iCol) ); continue; } } if( pszFIDColumn != NULL) { if (EQUAL(poStmt->GetColName(iCol), pszFIDColumn) ) { if (EQUALN(poStmt->GetColTypeName( iCol ), "bigint", 6)) SetMetadataItem(OLMD_FID64, "YES"); if ( EQUAL(poStmt->GetColTypeName( iCol ), "int identity") || EQUAL(poStmt->GetColTypeName( iCol ), "bigint identity")) bIsIdentityFid = TRUE; /* skip FID */ continue; } } else { if (EQUAL(poStmt->GetColTypeName( iCol ), "int identity")) { pszFIDColumn = CPLStrdup( poStmt->GetColName(iCol) ); bIsIdentityFid = TRUE; continue; } else if (EQUAL(poStmt->GetColTypeName( iCol ), "bigint identity")) { pszFIDColumn = CPLStrdup( poStmt->GetColName(iCol) ); bIsIdentityFid = TRUE; SetMetadataItem(OLMD_FID64, "YES"); continue; } } OGRFieldDefn oField( poStmt->GetColName(iCol), OFTString ); oField.SetWidth( MAX(0,poStmt->GetColSize( iCol )) ); switch( CPLODBCStatement::GetTypeMapping(poStmt->GetColType(iCol)) ) { case SQL_C_SSHORT: case SQL_C_USHORT: case SQL_C_SLONG: case SQL_C_ULONG: oField.SetType( OFTInteger ); break; case SQL_C_SBIGINT: case SQL_C_UBIGINT: oField.SetType( OFTInteger64 ); break; case SQL_C_BINARY: oField.SetType( OFTBinary ); break; case SQL_C_NUMERIC: oField.SetType( OFTReal ); oField.SetPrecision( poStmt->GetColPrecision(iCol) ); break; case SQL_C_FLOAT: case SQL_C_DOUBLE: oField.SetType( OFTReal ); oField.SetWidth( 0 ); break; case SQL_C_DATE: oField.SetType( OFTDate ); break; case SQL_C_TIME: oField.SetType( OFTTime ); break; case SQL_C_TIMESTAMP: oField.SetType( OFTDateTime ); break; default: /* leave it as OFTString */; } oField.SetNullable( poStmt->GetColNullable(iCol) ); if ( poStmt->GetColColumnDef(iCol) ) { /* process default value specification */ if ( EQUAL(poStmt->GetColColumnDef(iCol), "(getdate())") ) oField.SetDefault( "CURRENT_TIMESTAMP" ); else if ( EQUALN(poStmt->GetColColumnDef(iCol), "(CONVERT([time],getdate(),0))", 25) ) oField.SetDefault( "CURRENT_TIME" ); else if ( EQUALN(poStmt->GetColColumnDef(iCol), "(CONVERT([date],getdate(),0))", 25) ) oField.SetDefault( "CURRENT_DATE" ); else { char* pszDefault = CPLStrdup(poStmt->GetColColumnDef(iCol)); int nLen = strlen(pszDefault); if (nLen >= 1 && pszDefault[0] == '(' && pszDefault[nLen-1] == ')') { /* all default values are encapsulated in backets by MSSQL server */ if (nLen >= 4 && pszDefault[1] == '(' && pszDefault[nLen-2] == ')') { /* for numeric values double brackets are used */ pszDefault[nLen-2] = '\0'; oField.SetDefault(pszDefault + 2); } else { pszDefault[nLen-1] = '\0'; oField.SetDefault(pszDefault + 1); } } else oField.SetDefault( pszDefault ); CPLFree(pszDefault); } } poFeatureDefn->AddFieldDefn( &oField ); panFieldOrdinals[poFeatureDefn->GetFieldCount() - 1] = iCol; } /* -------------------------------------------------------------------- */ /* If we don't already have an FID, check if there is a special */ /* FID named column available. */ /* -------------------------------------------------------------------- */ if( pszFIDColumn == NULL ) { const char *pszOGR_FID = CPLGetConfigOption("MSSQLSPATIAL_OGR_FID","OGR_FID"); if( poFeatureDefn->GetFieldIndex( pszOGR_FID ) != -1 ) pszFIDColumn = CPLStrdup(pszOGR_FID); } if( pszFIDColumn != NULL ) CPLDebug( "OGR_MSSQLSpatial", "Using column %s as FID for table %s.", pszFIDColumn, poFeatureDefn->GetName() ); else CPLDebug( "OGR_MSSQLSpatial", "Table %s has no identified FID column.", poFeatureDefn->GetName() ); return CE_None; }
/*********************************************************************** * \brief Returns the metadata for this band * * If the metadata is actually stored in band's properties, simply * returns them. Otherwise, it raises a query to fetch metadata * FROM db **********************************************************************/ GBool PostGISRasterRasterBand::GetBandMetadata( GDALDataType * peDataType, GBool * pbHasNoData, double * pdfNoData) { // No need to raise a query if (eDataType != GDT_Unknown) { if (peDataType) *peDataType = eDataType; if (pbHasNoData) *pbHasNoData = bNoDataValueSet; if (pdfNoData) *pdfNoData = dfNoDataValue; return true; } /** * Queries are expensive. So, we only raise them if all parameters * are not null **/ if (!peDataType || !pbHasNoData || !pdfNoData) { return false; } /** * It is safe to assume all the tiles will have the same values for * metadata properties. That was checked during band's construction * (or we simply trusted the user, to avoid expensive checkings). * So, we can limit the results to just one. **/ int nTuples = 0; CPLString osCommand = NULL; PGresult * poResult = NULL; PostGISRasterDataset * poRDS = (PostGISRasterDataset *)poDS; osCommand.Printf("st_bandpixeltype(%s, %d), " "st_bandnodatavalue(%s, %d) is not null, " "st_bandnodatavalue(%s, %d) FROM %s.%s limit 1", pszColumn, nBand, pszColumn, nBand, pszColumn, nBand, pszSchema, pszTable); #ifdef DEBUG_QUERY CPLDebug("PostGIS_Raster", "PostGISRasterRasterBand::GetBandMetadata(): Query: %s", osCommand.c_str()); #endif poResult = PQexec(poRDS->poConn, osCommand.c_str()); nTuples = PQntuples(poResult); /* Error getting info FROM database */ if (poResult == NULL || PQresultStatus(poResult) != PGRES_TUPLES_OK || nTuples <= 0) { ReportError(CE_Failure, CPLE_AppDefined, "Error getting band metadata while creating raster " "bands"); CPLDebug("PostGIS_Raster", "PostGISRasterDataset::GetBandMetadata(): %s", PQerrorMessage(poRDS->poConn)); if (poResult) PQclear(poResult); return false; } // Fill band metadata values GBool bSignedByte = false; int nBitsDepth = 8; char* pszDataType = NULL; pszDataType = CPLStrdup(PQgetvalue(poResult, 0, 0)); TranslateDataType(pszDataType, &eDataType, &nBitsDepth, &bSignedByte); // Add pixeltype to image structure domain if (bSignedByte) { SetMetadataItem("PIXELTYPE", "SIGNEDBYTE", "IMAGE_STRUCTURE" ); } // Add NBITS to metadata only for sub-byte types if (nBitsDepth < 8) SetMetadataItem("NBITS", CPLString().Printf( "%d", nBitsDepth ), "IMAGE_STRUCTURE" ); CPLFree(pszDataType); bNoDataValueSet = EQUALN(PQgetvalue(poResult, 0, 1), "t", sizeof(char)); dfNoDataValue = CPLAtof(PQgetvalue(poResult, 0, 2)); // Fill output arguments *peDataType = eDataType; *pbHasNoData = bNoDataValueSet; *pdfNoData = dfNoDataValue; return true; }
GIFRasterBand::GIFRasterBand( GIFDataset *poDS, int nBand, SavedImage *psSavedImage, int nBackground ) { this->poDS = poDS; this->nBand = nBand; eDataType = GDT_Byte; nBlockXSize = poDS->nRasterXSize; nBlockYSize = 1; psImage = psSavedImage; poColorTable = NULL; panInterlaceMap = NULL; nTransparentColor = 0; if (psImage == NULL) return; /* -------------------------------------------------------------------- */ /* Setup interlacing map if required. */ /* -------------------------------------------------------------------- */ panInterlaceMap = NULL; if( psImage->ImageDesc.Interlace ) { int i, j, iLine = 0; panInterlaceMap = (int *) CPLCalloc(poDS->nRasterYSize,sizeof(int)); for (i = 0; i < 4; i++) { for (j = InterlacedOffset[i]; j < poDS->nRasterYSize; j += InterlacedJumps[i]) panInterlaceMap[j] = iLine++; } } /* -------------------------------------------------------------------- */ /* Check for transparency. We just take the first graphic */ /* control extension block we find, if any. */ /* -------------------------------------------------------------------- */ int iExtBlock; nTransparentColor = -1; for( iExtBlock = 0; iExtBlock < psImage->ExtensionBlockCount; iExtBlock++ ) { unsigned char *pExtData; if( psImage->ExtensionBlocks[iExtBlock].Function != 0xf9 ) continue; pExtData = (unsigned char *) psImage->ExtensionBlocks[iExtBlock].Bytes; /* check if transparent color flag is set */ if( !(pExtData[0] & 0x1) ) continue; nTransparentColor = pExtData[3]; } /* -------------------------------------------------------------------- */ /* Setup colormap. */ /* -------------------------------------------------------------------- */ ColorMapObject *psGifCT = psImage->ImageDesc.ColorMap; if( psGifCT == NULL ) psGifCT = poDS->hGifFile->SColorMap; poColorTable = new GDALColorTable(); for( int iColor = 0; iColor < psGifCT->ColorCount; iColor++ ) { GDALColorEntry oEntry; oEntry.c1 = psGifCT->Colors[iColor].Red; oEntry.c2 = psGifCT->Colors[iColor].Green; oEntry.c3 = psGifCT->Colors[iColor].Blue; if( iColor == nTransparentColor ) oEntry.c4 = 0; else oEntry.c4 = 255; poColorTable->SetColorEntry( iColor, &oEntry ); } /* -------------------------------------------------------------------- */ /* If we have a background value, return it here. Some */ /* applications might want to treat this as transparent, but in */ /* many uses this is inappropriate so we don't return it as */ /* nodata or transparent. */ /* -------------------------------------------------------------------- */ if( nBackground != 255 ) { char szBackground[10]; sprintf( szBackground, "%d", nBackground ); SetMetadataItem( "GIF_BACKGROUND", szBackground ); } }
void GRIBRasterBand::FindPDSTemplate() { GRIBDataset *poGDS = (GRIBDataset *) poDS; /* -------------------------------------------------------------------- */ /* Collect section 4 octet information ... we read the file */ /* ourselves since the GRIB API does not appear to preserve all */ /* this for us. */ /* -------------------------------------------------------------------- */ GIntBig nOffset = VSIFTellL( poGDS->fp ); GByte abyHead[5]; GUInt32 nSectSize; VSIFSeekL( poGDS->fp, start+16, SEEK_SET ); VSIFReadL( abyHead, 5, 1, poGDS->fp ); while( abyHead[4] != 4 ) { memcpy( &nSectSize, abyHead, 4 ); CPL_MSBPTR32( &nSectSize ); if( VSIFSeekL( poGDS->fp, nSectSize-5, SEEK_CUR ) != 0 || VSIFReadL( abyHead, 5, 1, poGDS->fp ) != 1 ) break; } if( abyHead[4] == 4 ) { GUInt16 nCoordCount; GUInt16 nPDTN; CPLString osOctet; int i; GByte *pabyBody; memcpy( &nSectSize, abyHead, 4 ); CPL_MSBPTR32( &nSectSize ); pabyBody = (GByte *) CPLMalloc(nSectSize-5); VSIFReadL( pabyBody, 1, nSectSize-5, poGDS->fp ); memcpy( &nCoordCount, pabyBody + 5 - 5, 2 ); CPL_MSBPTR16( &nCoordCount ); memcpy( &nPDTN, pabyBody + 7 - 5, 2 ); CPL_MSBPTR16( &nPDTN ); SetMetadataItem( "GRIB_PDS_PDTN", CPLString().Printf( "%d", nPDTN ) ); for( i = 9; i < (int) nSectSize; i++ ) { char szByte[10]; if( i == 9 ) sprintf( szByte, "%d", pabyBody[i-5] ); else sprintf( szByte, " %d", pabyBody[i-5] ); osOctet += szByte; } SetMetadataItem( "GRIB_PDS_TEMPLATE_NUMBERS", osOctet ); CPLFree( pabyBody ); } VSIFSeekL( poGDS->fp, nOffset, SEEK_SET ); }
OGRErr OGRMySQLTableLayer::ICreateFeature( OGRFeature *poFeature ) { MYSQL_RES *hResult=NULL; CPLString osCommand; int i, bNeedComma = FALSE; /* -------------------------------------------------------------------- */ /* Form the INSERT command. */ /* -------------------------------------------------------------------- */ osCommand.Printf( "INSERT INTO `%s` (", poFeatureDefn->GetName() ); if( poFeature->GetGeometryRef() != NULL ) { osCommand = osCommand + "`" + pszGeomColumn + "` "; bNeedComma = TRUE; } if( poFeature->GetFID() != OGRNullFID && pszFIDColumn != NULL ) { if( bNeedComma ) osCommand += ", "; osCommand = osCommand + "`" + pszFIDColumn + "` "; bNeedComma = TRUE; } for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if( !poFeature->IsFieldSet( i ) ) continue; if( !bNeedComma ) bNeedComma = TRUE; else osCommand += ", "; osCommand = osCommand + "`" + poFeatureDefn->GetFieldDefn(i)->GetNameRef() + "`"; } osCommand += ") VALUES ("; // Set the geometry bNeedComma = poFeature->GetGeometryRef() != NULL; if( poFeature->GetGeometryRef() != NULL) { char *pszWKT = NULL; if( poFeature->GetGeometryRef() != NULL ) { OGRGeometry *poGeom = (OGRGeometry *) poFeature->GetGeometryRef(); poGeom->closeRings(); poGeom->flattenTo2D(); poGeom->exportToWkt( &pszWKT ); } if( pszWKT != NULL ) { osCommand += CPLString().Printf( "GeometryFromText('%s',%d) ", pszWKT, nSRSId ); OGRFree( pszWKT ); } else osCommand += "''"; } // Set the FID if( poFeature->GetFID() != OGRNullFID && pszFIDColumn != NULL ) { GIntBig nFID = poFeature->GetFID(); if( !CPL_INT64_FITS_ON_INT32(nFID) && GetMetadataItem(OLMD_FID64) == NULL ) { CPLString osCommand2; osCommand2.Printf( "ALTER TABLE `%s` MODIFY COLUMN `%s` BIGINT UNIQUE NOT NULL AUTO_INCREMENT", poFeatureDefn->GetName(), pszFIDColumn ); if( mysql_query(poDS->GetConn(), osCommand2 ) ) { poDS->ReportError( osCommand2 ); return OGRERR_FAILURE; } // make sure to attempt to free results of successful queries hResult = mysql_store_result( poDS->GetConn() ); if( hResult != NULL ) mysql_free_result( hResult ); hResult = NULL; SetMetadataItem(OLMD_FID64, "YES"); } if( bNeedComma ) osCommand += ", "; osCommand += CPLString().Printf( CPL_FRMT_GIB, nFID ); bNeedComma = TRUE; } for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if( !poFeature->IsFieldSet( i ) ) continue; if( bNeedComma ) osCommand += ", "; else bNeedComma = TRUE; const char *pszStrValue = poFeature->GetFieldAsString(i); if( poFeatureDefn->GetFieldDefn(i)->GetType() != OFTInteger && poFeatureDefn->GetFieldDefn(i)->GetType() != OFTInteger64 && poFeatureDefn->GetFieldDefn(i)->GetType() != OFTReal && poFeatureDefn->GetFieldDefn(i)->GetType() != OFTBinary ) { int iChar; //We need to quote and escape string fields. osCommand += "'"; for( iChar = 0; pszStrValue[iChar] != '\0'; iChar++ ) { if( poFeatureDefn->GetFieldDefn(i)->GetType() != OFTIntegerList && poFeatureDefn->GetFieldDefn(i)->GetType() != OFTInteger64List && poFeatureDefn->GetFieldDefn(i)->GetType() != OFTRealList && poFeatureDefn->GetFieldDefn(i)->GetWidth() > 0 && iChar == poFeatureDefn->GetFieldDefn(i)->GetWidth() ) { CPLDebug( "MYSQL", "Truncated %s field value, it was too long.", poFeatureDefn->GetFieldDefn(i)->GetNameRef() ); break; } if( pszStrValue[iChar] == '\\' || pszStrValue[iChar] == '\'' ) { osCommand += '\\'; osCommand += pszStrValue[iChar]; } else osCommand += pszStrValue[iChar]; } osCommand += "'"; } else if( poFeatureDefn->GetFieldDefn(i)->GetType() == OFTBinary ) { int binaryCount = 0; GByte* binaryData = poFeature->GetFieldAsBinary(i, &binaryCount); char* pszHexValue = CPLBinaryToHex( binaryCount, binaryData ); osCommand += "x'"; osCommand += pszHexValue; osCommand += "'"; CPLFree( pszHexValue ); } else { osCommand += pszStrValue; } } osCommand += ")"; //CPLDebug("MYSQL", "%s", osCommand.c_str()); int nQueryResult = mysql_query(poDS->GetConn(), osCommand.c_str() ); const my_ulonglong nFID = mysql_insert_id( poDS->GetConn() ); if( nQueryResult ){ int eErrorCode = mysql_errno(poDS->GetConn()); if (eErrorCode == 1153) {//ER_NET_PACKET_TOO_LARGE) poDS->ReportError("CreateFeature failed because the MySQL server " \ "cannot read the entire query statement. Increase " \ "the size of statements your server will allow by " \ "altering the 'max_allowed_packet' parameter in "\ "your MySQL server configuration."); } else { CPLDebug("MYSQL","Error number %d", eErrorCode); poDS->ReportError( osCommand.c_str() ); } // make sure to attempt to free results hResult = mysql_store_result( poDS->GetConn() ); if( hResult != NULL ) mysql_free_result( hResult ); hResult = NULL; return OGRERR_FAILURE; } if( nFID > 0 ) { poFeature->SetFID( nFID ); } // make sure to attempt to free results of successful queries hResult = mysql_store_result( poDS->GetConn() ); if( hResult != NULL ) mysql_free_result( hResult ); hResult = NULL; return OGRERR_NONE; }
void BSBDataset::ScanForGCPs( bool isNos, const char *pszFilename ) { /* -------------------------------------------------------------------- */ /* Collect GCPs as appropriate to source. */ /* -------------------------------------------------------------------- */ nGCPCount = 0; if ( isNos ) { ScanForGCPsNos(pszFilename); } else { ScanForGCPsBSB(); } /* -------------------------------------------------------------------- */ /* Apply heuristics to re-wrap GCPs to maintain continguity */ /* over the international dateline. */ /* -------------------------------------------------------------------- */ if( nGCPCount > 1 ) GDALHeuristicDatelineWrapGCPs( nGCPCount, pasGCPList ); /* -------------------------------------------------------------------- */ /* Collect coordinate system related parameters from header. */ /* -------------------------------------------------------------------- */ int i; const char *pszKNP=NULL, *pszKNQ=NULL; for( i = 0; psInfo->papszHeader[i] != NULL; i++ ) { if( EQUALN(psInfo->papszHeader[i],"KNP/",4) ) { pszKNP = psInfo->papszHeader[i]; SetMetadataItem( "BSB_KNP", pszKNP + 4 ); } if( EQUALN(psInfo->papszHeader[i],"KNQ/",4) ) { pszKNQ = psInfo->papszHeader[i]; SetMetadataItem( "BSB_KNQ", pszKNQ + 4 ); } } /* -------------------------------------------------------------------- */ /* Can we derive a reasonable coordinate system definition for */ /* this file? For now we keep it simple, just handling */ /* mercator. In the future we should consider others. */ /* -------------------------------------------------------------------- */ CPLString osUnderlyingSRS; if( pszKNP != NULL ) { const char *pszPR = strstr(pszKNP,"PR="); const char *pszGD = strstr(pszKNP,"GD="); const char *pszValue, *pszEnd = NULL; const char *pszGEOGCS = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; CPLString osPP; // Capture the PP string. pszValue = strstr(pszKNP,"PP="); if( pszValue ) pszEnd = strstr(pszValue,","); if( pszValue && pszEnd ) osPP.assign(pszValue+3,pszEnd-pszValue-3); // Look at the datum if( pszGD == NULL ) { /* no match. We'll default to EPSG:4326 */ } else if( EQUALN(pszGD,"GD=European 1950", 16) ) { pszGEOGCS = "GEOGCS[\"ED50\",DATUM[\"European_Datum_1950\",SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY[\"EPSG\",\"6230\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4230\"]]"; } // Look at the projection if( pszPR == NULL ) { /* no match */ } else if( EQUALN(pszPR,"PR=MERCATOR", 11) ) { // We somewhat arbitrarily select our first GCPX as our // central meridian. This is mostly helpful to ensure // that regions crossing the dateline will be contiguous // in mercator. osUnderlyingSRS.Printf( "PROJCS[\"Global Mercator\",%s,PROJECTION[\"Mercator_2SP\"],PARAMETER[\"standard_parallel_1\",0],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",%d],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]", pszGEOGCS, (int) pasGCPList[0].dfGCPX ); } else if( EQUALN(pszPR,"PR=TRANSVERSE MERCATOR", 22) && osPP.size() > 0 ) { osUnderlyingSRS.Printf( "PROJCS[\"unnamed\",%s,PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",%s],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0]]", pszGEOGCS, osPP.c_str() ); } else if( EQUALN(pszPR,"PR=UNIVERSAL TRANSVERSE MERCATOR", 32) && osPP.size() > 0 ) { // This is not *really* UTM unless the central meridian // matches a zone which it does not in some (most?) maps. osUnderlyingSRS.Printf( "PROJCS[\"unnamed\",%s,PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",%s],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0]]", pszGEOGCS, osPP.c_str() ); } else if( EQUALN(pszPR,"PR=POLYCONIC", 12) && osPP.size() > 0 ) { osUnderlyingSRS.Printf( "PROJCS[\"unnamed\",%s,PROJECTION[\"Polyconic\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",%s],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0]]", pszGEOGCS, osPP.c_str() ); } else if( EQUALN(pszPR,"PR=LAMBERT CONFORMAL CONIC", 26) && osPP.size() > 0 && pszKNQ != NULL ) { CPLString osP2, osP3; // Capture the KNQ/P2 string. pszValue = strstr(pszKNQ,"P2="); if( pszValue ) pszEnd = strstr(pszValue,","); if( pszValue && pszEnd ) osP2.assign(pszValue+3,pszEnd-pszValue-3); // Capture the KNQ/P3 string. pszValue = strstr(pszKNQ,"P3="); if( pszValue ) pszEnd = strstr(pszValue,","); if( pszValue ) { if( pszEnd ) osP3.assign(pszValue+3,pszEnd-pszValue-3); else osP3.assign(pszValue+3); } if( osP2.size() > 0 && osP3.size() > 0 ) osUnderlyingSRS.Printf( "PROJCS[\"unnamed\",%s,PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",%s],PARAMETER[\"standard_parallel_2\",%s],PARAMETER[\"latitude_of_origin\",0.0],PARAMETER[\"central_meridian\",%s],PARAMETER[\"false_easting\",0.0],PARAMETER[\"false_northing\",0.0]]", pszGEOGCS, osP2.c_str(), osP3.c_str(), osPP.c_str() ); } } /* -------------------------------------------------------------------- */ /* If we got an alternate underlying coordinate system, try */ /* converting the GCPs to that coordinate system. */ /* -------------------------------------------------------------------- */ if( osUnderlyingSRS.length() > 0 ) { OGRSpatialReference oGeog_SRS, oProjected_SRS; OGRCoordinateTransformation *poCT; oProjected_SRS.SetFromUserInput( osUnderlyingSRS ); oGeog_SRS.CopyGeogCSFrom( &oProjected_SRS ); poCT = OGRCreateCoordinateTransformation( &oGeog_SRS, &oProjected_SRS ); if( poCT != NULL ) { for( i = 0; i < nGCPCount; i++ ) { poCT->Transform( 1, &(pasGCPList[i].dfGCPX), &(pasGCPList[i].dfGCPY), &(pasGCPList[i].dfGCPZ) ); } osGCPProjection = osUnderlyingSRS; delete poCT; } else CPLErrorReset(); } /* -------------------------------------------------------------------- */ /* Attempt to prepare a geotransform from the GCPs. */ /* -------------------------------------------------------------------- */ if( GDALGCPsToGeoTransform( nGCPCount, pasGCPList, adfGeoTransform, FALSE ) ) { bGeoTransformSet = TRUE; } }
GIFAbstractRasterBand::GIFAbstractRasterBand( GIFAbstractDataset *poDSIn, int nBandIn, SavedImage *psSavedImage, int nBackground, int bAdvertizeInterlacedMDI ) : psImage(psSavedImage), panInterlaceMap(nullptr), poColorTable(nullptr), nTransparentColor(0) { poDS = poDSIn; nBand = nBandIn; eDataType = GDT_Byte; nBlockXSize = poDS->GetRasterXSize(); nBlockYSize = 1; if( psImage == nullptr ) return; /* -------------------------------------------------------------------- */ /* Setup interlacing map if required. */ /* -------------------------------------------------------------------- */ panInterlaceMap = nullptr; if( psImage->ImageDesc.Interlace ) { int iLine = 0; if( bAdvertizeInterlacedMDI ) poDS->SetMetadataItem( "INTERLACED", "YES", "IMAGE_STRUCTURE" ); panInterlaceMap = (int *) CPLCalloc(poDSIn->nRasterYSize,sizeof(int)); for (int i = 0; i < 4; i++) { for (int j = InterlacedOffset[i]; j < poDSIn->nRasterYSize; j += InterlacedJumps[i]) panInterlaceMap[j] = iLine++; } } else if( bAdvertizeInterlacedMDI ) { poDS->SetMetadataItem( "INTERLACED", "NO", "IMAGE_STRUCTURE" ); } /* -------------------------------------------------------------------- */ /* Check for transparency. We just take the first graphic */ /* control extension block we find, if any. */ /* -------------------------------------------------------------------- */ nTransparentColor = -1; for( int iExtBlock = 0; iExtBlock < psImage->ExtensionBlockCount; iExtBlock++ ) { if( psImage->ExtensionBlocks[iExtBlock].Function != 0xf9 || psImage->ExtensionBlocks[iExtBlock].ByteCount < 4 ) continue; unsigned char *pExtData = reinterpret_cast<unsigned char *>( psImage->ExtensionBlocks[iExtBlock].Bytes); /* check if transparent color flag is set */ if( !(pExtData[0] & 0x1) ) continue; nTransparentColor = pExtData[3]; } /* -------------------------------------------------------------------- */ /* Setup colormap. */ /* -------------------------------------------------------------------- */ ColorMapObject *psGifCT = psImage->ImageDesc.ColorMap; if( psGifCT == nullptr ) psGifCT = poDSIn->hGifFile->SColorMap; poColorTable = new GDALColorTable(); for( int iColor = 0; iColor < psGifCT->ColorCount; iColor++ ) { GDALColorEntry oEntry; oEntry.c1 = psGifCT->Colors[iColor].Red; oEntry.c2 = psGifCT->Colors[iColor].Green; oEntry.c3 = psGifCT->Colors[iColor].Blue; if( iColor == nTransparentColor ) oEntry.c4 = 0; else oEntry.c4 = 255; poColorTable->SetColorEntry( iColor, &oEntry ); } /* -------------------------------------------------------------------- */ /* If we have a background value, return it here. Some */ /* applications might want to treat this as transparent, but in */ /* many uses this is inappropriate so we don't return it as */ /* nodata or transparent. */ /* -------------------------------------------------------------------- */ if( nBackground != 255 ) { char szBackground[10]; snprintf( szBackground, sizeof(szBackground), "%d", nBackground ); SetMetadataItem( "GIF_BACKGROUND", szBackground ); } }
IntergraphRasterBand::IntergraphRasterBand( IntergraphDataset *poDS, int nBand, int nBandOffset, GDALDataType eType ) { this->poColorTable = new GDALColorTable(); this->poDS = poDS; this->nBand = nBand != 0 ? nBand : poDS->nBands; this->nTiles = 0; this->eDataType = eType; this->pabyBlockBuf = NULL; this->pahTiles = NULL; this->nRGBIndex = 0; this->nBandStart = nBandOffset; this->bTiled = FALSE; // -------------------------------------------------------------------- // Get Header Info // -------------------------------------------------------------------- memcpy(&hHeaderOne, &poDS->hHeaderOne, sizeof(hHeaderOne)); memcpy(&hHeaderTwo, &poDS->hHeaderTwo, sizeof(hHeaderTwo)); // -------------------------------------------------------------------- // Get the image start from Words to Follow (WTF) // -------------------------------------------------------------------- nDataOffset = nBandOffset + 2 + ( 2 * ( hHeaderOne.WordsToFollow + 1 ) ); // -------------------------------------------------------------------- // Get Color Tabel from Color Table Type (CTV) // -------------------------------------------------------------------- uint32 nEntries = hHeaderTwo.NumberOfCTEntries; if( nEntries > 0 ) { switch ( hHeaderTwo.ColorTableType ) { case EnvironVColorTable: INGR_GetEnvironVColors( poDS->fp, nBandOffset, nEntries, poColorTable ); if (poColorTable->GetColorEntryCount() == 0) return; break; case IGDSColorTable: INGR_GetIGDSColors( poDS->fp, nBandOffset, nEntries, poColorTable ); if (poColorTable->GetColorEntryCount() == 0) return; break; default: CPLDebug( "INGR", "Wrong Color table type (%d), number of colors (%d)", hHeaderTwo.ColorTableType, nEntries ); } } // -------------------------------------------------------------------- // Set Dimension // -------------------------------------------------------------------- nRasterXSize = hHeaderOne.PixelsPerLine; nRasterYSize = hHeaderOne.NumberOfLines; nBlockXSize = nRasterXSize; nBlockYSize = 1; // -------------------------------------------------------------------- // Get tile directory // -------------------------------------------------------------------- this->eFormat = (INGR_Format) hHeaderOne.DataTypeCode; this->bTiled = (hHeaderOne.DataTypeCode == TiledRasterData); if( bTiled ) { nTiles = INGR_GetTileDirectory( poDS->fp, nDataOffset, nRasterXSize, nRasterYSize, &hTileDir, &pahTiles ); if (nTiles == 0) return; eFormat = (INGR_Format) hTileDir.DataTypeCode; // ---------------------------------------------------------------- // Set blocks dimensions based on tiles // ---------------------------------------------------------------- nBlockXSize = MIN( hTileDir.TileSize, (uint32) nRasterXSize ); nBlockYSize = MIN( hTileDir.TileSize, (uint32) nRasterYSize ); } if (nBlockXSize <= 0 || nBlockYSize <= 0) { pabyBlockBuf = NULL; CPLError(CE_Failure, CPLE_AppDefined, "Invalid block dimensions"); return; } // -------------------------------------------------------------------- // Incomplete tiles have Block Offset greater than: // -------------------------------------------------------------------- nFullBlocksX = ( nRasterXSize / nBlockXSize ); nFullBlocksY = ( nRasterYSize / nBlockYSize ); // -------------------------------------------------------------------- // Get the Data Type from Format // -------------------------------------------------------------------- this->eDataType = INGR_GetDataType( (uint16) eFormat ); // -------------------------------------------------------------------- // Allocate buffer for a Block of data // -------------------------------------------------------------------- nBlockBufSize = nBlockXSize * nBlockYSize * GDALGetDataTypeSize( eDataType ) / 8; pabyBlockBuf = (GByte*) VSIMalloc3( nBlockXSize, nBlockYSize, GDALGetDataTypeSize( eDataType ) / 8); if (pabyBlockBuf == NULL) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot allocate %d bytes", nBlockBufSize); return; } // -------------------------------------------------------------------- // More Metadata Information // -------------------------------------------------------------------- SetMetadataItem( "FORMAT", INGR_GetFormatName( (uint16) eFormat ), "IMAGE_STRUCTURE" ); if( bTiled ) { SetMetadataItem( "TILESSIZE", CPLSPrintf ("%d", hTileDir.TileSize), "IMAGE_STRUCTURE" ); } else { SetMetadataItem( "TILED", "NO", "IMAGE_STRUCTURE" ); } SetMetadataItem( "ORIENTATION", INGR_GetOrientation( hHeaderOne.ScanlineOrientation ), "IMAGE_STRUCTURE" ); }
PALSARJaxaRasterBand::PALSARJaxaRasterBand( PALSARJaxaDataset *poDSIn, int nBandIn, VSILFILE *fpIn ) : nPolarization(hh) { poDS = poDSIn; nBand = nBandIn; this->fp = fpIn; /* Read image options record to determine the type of data */ VSIFSeekL( fp, BITS_PER_SAMPLE_OFFSET, SEEK_SET ); nBitsPerSample = 0; nSamplesPerGroup = 0; READ_CHAR_VAL( nBitsPerSample, BITS_PER_SAMPLE_LENGTH, fp ); READ_CHAR_VAL( nSamplesPerGroup, SAMPLES_PER_GROUP_LENGTH, fp ); if (nBitsPerSample == 32 && nSamplesPerGroup == 2) { eDataType = GDT_CFloat32; nFileType = level_11; } else if (nBitsPerSample == 8 && nSamplesPerGroup == 2) { eDataType = GDT_CInt16; /* shuold be 2 x signed byte */ nFileType = level_10; } else { eDataType = GDT_UInt16; nFileType = level_15; } poDSIn->nFileType = nFileType; /* Read number of range/azimuth lines */ VSIFSeekL( fp, NUMBER_LINES_OFFSET, SEEK_SET ); READ_CHAR_VAL( nRasterYSize, NUMBER_LINES_LENGTH, fp ); VSIFSeekL( fp, SAR_DATA_RECORD_LENGTH_OFFSET, SEEK_SET ); READ_CHAR_VAL( nRecordSize, SAR_DATA_RECORD_LENGTH_LENGTH, fp ); int nDenom = ((nBitsPerSample / 8) * nSamplesPerGroup); if( nDenom == 0 ) nRasterXSize = 0; else nRasterXSize = (nRecordSize - (nFileType != level_15 ? SIG_DAT_REC_OFFSET : PROC_DAT_REC_OFFSET)) / nDenom; poDSIn->nRasterXSize = nRasterXSize; poDSIn->nRasterYSize = nRasterYSize; /* Polarization */ switch (nBand) { case 0: nPolarization = hh; SetMetadataItem( "POLARIMETRIC_INTERP", "HH" ); break; case 1: nPolarization = hv; SetMetadataItem( "POLARIMETRIC_INTERP", "HV" ); break; case 2: nPolarization = vh; SetMetadataItem( "POLARIMETRIC_INTERP", "VH" ); break; case 3: nPolarization = vv; SetMetadataItem( "POLARIMETRIC_INTERP", "VV" ); break; // TODO: What about the default? } /* size of block we can read */ nBlockXSize = nRasterXSize; nBlockYSize = 1; /* set the file pointer to the first SAR data record */ VSIFSeekL( fp, IMAGE_OPT_DESC_LENGTH, SEEK_SET ); }
BIGGifRasterBand::BIGGifRasterBand( BIGGIFDataset *poDS, int nBackground ) { SavedImage *psImage = poDS->hGifFile->SavedImages + 0; this->poDS = poDS; this->nBand = 1; eDataType = GDT_Byte; nBlockXSize = poDS->nRasterXSize; nBlockYSize = 1; /* -------------------------------------------------------------------- */ /* Setup interlacing map if required. */ /* -------------------------------------------------------------------- */ panInterlaceMap = NULL; if( psImage->ImageDesc.Interlace ) { int i, j, iLine = 0; poDS->SetMetadataItem( "INTERLACED", "YES", "IMAGE_STRUCTURE" ); panInterlaceMap = (int *) CPLCalloc(poDS->nRasterYSize,sizeof(int)); for (i = 0; i < 4; i++) { for (j = InterlacedOffset[i]; j < poDS->nRasterYSize; j += InterlacedJumps[i]) panInterlaceMap[j] = iLine++; } } else poDS->SetMetadataItem( "INTERLACED", "NO", "IMAGE_STRUCTURE" ); /* -------------------------------------------------------------------- */ /* Setup colormap. */ /* -------------------------------------------------------------------- */ ColorMapObject *psGifCT = psImage->ImageDesc.ColorMap; if( psGifCT == NULL ) psGifCT = poDS->hGifFile->SColorMap; poColorTable = new GDALColorTable(); for( int iColor = 0; iColor < psGifCT->ColorCount; iColor++ ) { GDALColorEntry oEntry; oEntry.c1 = psGifCT->Colors[iColor].Red; oEntry.c2 = psGifCT->Colors[iColor].Green; oEntry.c3 = psGifCT->Colors[iColor].Blue; oEntry.c4 = 255; poColorTable->SetColorEntry( iColor, &oEntry ); } /* -------------------------------------------------------------------- */ /* If we have a background value, return it here. Some */ /* applications might want to treat this as transparent, but in */ /* many uses this is inappropriate so we don't return it as */ /* nodata or transparent. */ /* -------------------------------------------------------------------- */ if( nBackground != 255 ) { char szBackground[10]; sprintf( szBackground, "%d", nBackground ); SetMetadataItem( "GIF_BACKGROUND", szBackground ); } }
int AAIGDataset::ParseHeader(const char *pszHeader, const char *pszDataType) { char **papszTokens = CSLTokenizeString2(pszHeader, " \n\r\t", 0); const int nTokens = CSLCount(papszTokens); int i = 0; if ( (i = CSLFindString(papszTokens, "ncols")) < 0 || i + 1 >= nTokens) { CSLDestroy(papszTokens); return FALSE; } nRasterXSize = atoi(papszTokens[i + 1]); if ( (i = CSLFindString(papszTokens, "nrows")) < 0 || i + 1 >= nTokens) { CSLDestroy(papszTokens); return FALSE; } nRasterYSize = atoi(papszTokens[i + 1]); if (!GDALCheckDatasetDimensions(nRasterXSize, nRasterYSize)) { CSLDestroy(papszTokens); return FALSE; } // TODO(schwehr): Would be good to also factor the file size into the max. // TODO(schwehr): Allow the user to disable this check. // The driver allocates a panLineOffset array based on nRasterYSize constexpr int kMaxDimSize = 10000000; // 1e7 cells. if (nRasterXSize > kMaxDimSize || nRasterYSize > kMaxDimSize) { CSLDestroy(papszTokens); return FALSE; } double dfCellDX = 0.0; double dfCellDY = 0.0; if ( (i = CSLFindString(papszTokens, "cellsize")) < 0 ) { int iDX, iDY; if( (iDX = CSLFindString(papszTokens, "dx")) < 0 || (iDY = CSLFindString(papszTokens, "dy")) < 0 || iDX + 1 >= nTokens || iDY + 1 >= nTokens ) { CSLDestroy(papszTokens); return FALSE; } dfCellDX = CPLAtofM(papszTokens[iDX + 1]); dfCellDY = CPLAtofM(papszTokens[iDY + 1]); } else { if (i + 1 >= nTokens) { CSLDestroy(papszTokens); return FALSE; } dfCellDY = CPLAtofM(papszTokens[i + 1]); dfCellDX = dfCellDY; } int j = 0; if ((i = CSLFindString(papszTokens, "xllcorner")) >= 0 && (j = CSLFindString(papszTokens, "yllcorner")) >= 0 && i + 1 < nTokens && j + 1 < nTokens) { adfGeoTransform[0] = CPLAtofM(papszTokens[i + 1]); // Small hack to compensate from insufficient precision in cellsize // parameter in datasets of // http://ccafs-climate.org/data/A2a_2020s/hccpr_hadcm3 if ((nRasterXSize % 360) == 0 && fabs(adfGeoTransform[0] - (-180.0)) < 1e-12 && dfCellDX == dfCellDY && fabs(dfCellDX - (360.0 / nRasterXSize)) < 1e-9) { dfCellDY = 360.0 / nRasterXSize; dfCellDX = dfCellDY; } adfGeoTransform[1] = dfCellDX; adfGeoTransform[2] = 0.0; adfGeoTransform[3] = CPLAtofM(papszTokens[j + 1]) + nRasterYSize * dfCellDY; adfGeoTransform[4] = 0.0; adfGeoTransform[5] = -dfCellDY; } else if ((i = CSLFindString(papszTokens, "xllcenter")) >= 0 && (j = CSLFindString(papszTokens, "yllcenter")) >= 0 && i + 1 < nTokens && j + 1 < nTokens) { SetMetadataItem(GDALMD_AREA_OR_POINT, GDALMD_AOP_POINT); adfGeoTransform[0] = CPLAtofM(papszTokens[i + 1]) - 0.5 * dfCellDX; adfGeoTransform[1] = dfCellDX; adfGeoTransform[2] = 0.0; adfGeoTransform[3] = CPLAtofM(papszTokens[j + 1]) - 0.5 * dfCellDY + nRasterYSize * dfCellDY; adfGeoTransform[4] = 0.0; adfGeoTransform[5] = -dfCellDY; } else { adfGeoTransform[0] = 0.0; adfGeoTransform[1] = dfCellDX; adfGeoTransform[2] = 0.0; adfGeoTransform[3] = 0.0; adfGeoTransform[4] = 0.0; adfGeoTransform[5] = -dfCellDY; } if( (i = CSLFindString( papszTokens, "NODATA_value" )) >= 0 && i + 1 < nTokens) { const char *pszNoData = papszTokens[i + 1]; bNoDataSet = true; dfNoDataValue = CPLAtofM(pszNoData); if( pszDataType == nullptr && (strchr(pszNoData, '.') != nullptr || strchr(pszNoData, ',') != nullptr || std::numeric_limits<int>::min() > dfNoDataValue || dfNoDataValue > std::numeric_limits<int>::max()) ) { eDataType = GDT_Float32; if( !CPLIsInf(dfNoDataValue) && (fabs(dfNoDataValue) < std::numeric_limits<float>::min() || fabs(dfNoDataValue) > std::numeric_limits<float>::max()) ) { eDataType = GDT_Float64; } } if( eDataType == GDT_Float32 ) { dfNoDataValue = MapNoDataToFloat(dfNoDataValue); } } CSLDestroy(papszTokens); return TRUE; }
void BAGDataset::LoadMetadata() { /* -------------------------------------------------------------------- */ /* Load the metadata from the file. */ /* -------------------------------------------------------------------- */ hid_t hMDDS = H5Dopen( hHDF5, "/BAG_root/metadata" ); hid_t datatype = H5Dget_type( hMDDS ); hid_t dataspace = H5Dget_space( hMDDS ); hid_t native = H5Tget_native_type( datatype, H5T_DIR_ASCEND ); hsize_t dims[3], maxdims[3]; H5Sget_simple_extent_dims( dataspace, dims, maxdims ); pszXMLMetadata = (char *) CPLCalloc((int) (dims[0]+1),1); H5Dread( hMDDS, native, H5S_ALL, dataspace, H5P_DEFAULT, pszXMLMetadata ); H5Tclose( native ); H5Sclose( dataspace ); H5Tclose( datatype ); H5Dclose( hMDDS ); if( strlen(pszXMLMetadata) == 0 ) return; /* -------------------------------------------------------------------- */ /* Try to get the geotransform. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psRoot = CPLParseXMLString( pszXMLMetadata ); if( psRoot == NULL ) return; CPLStripXMLNamespace( psRoot, NULL, TRUE ); CPLXMLNode *psGeo = CPLSearchXMLNode( psRoot, "=MD_Georectified" ); if( psGeo != NULL ) { char **papszCornerTokens = CSLTokenizeStringComplex( CPLGetXMLValue( psGeo, "cornerPoints.Point.coordinates", "" ), " ,", FALSE, FALSE ); if( CSLCount(papszCornerTokens ) == 4 ) { double dfLLX = CPLAtof( papszCornerTokens[0] ); double dfLLY = CPLAtof( papszCornerTokens[1] ); double dfURX = CPLAtof( papszCornerTokens[2] ); double dfURY = CPLAtof( papszCornerTokens[3] ); adfGeoTransform[0] = dfLLX; adfGeoTransform[1] = (dfURX - dfLLX) / (GetRasterXSize()-1); adfGeoTransform[3] = dfURY; adfGeoTransform[5] = (dfLLY - dfURY) / (GetRasterYSize()-1); adfGeoTransform[0] -= adfGeoTransform[1] * 0.5; adfGeoTransform[3] -= adfGeoTransform[5] * 0.5; } CSLDestroy( papszCornerTokens ); } /* -------------------------------------------------------------------- */ /* Try to get the coordinate system. */ /* -------------------------------------------------------------------- */ OGRSpatialReference oSRS; if( OGR_SRS_ImportFromISO19115( &oSRS, pszXMLMetadata ) == OGRERR_NONE ) { oSRS.exportToWkt( &pszProjection ); } else { ParseWKTFromXML( pszXMLMetadata ); } /* -------------------------------------------------------------------- */ /* Fetch acquisition date. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psDateTime = CPLSearchXMLNode( psRoot, "=dateTime" ); if( psDateTime != NULL ) { const char *pszDateTimeValue = CPLGetXMLValue( psDateTime, NULL, "" ); if( pszDateTimeValue ) SetMetadataItem( "BAG_DATETIME", pszDateTimeValue ); } CPLDestroyXMLNode( psRoot ); }