90
98
nBlockYSize = nRasterYSize;
102
// -----------------------------------------------------------------------
103
// Load NoData values and value ranges for this band (layer)
104
// -----------------------------------------------------------------------
106
if( ( (GeoRasterDataset*) poDS)->bApplyNoDataArray )
108
CPLList* psList = NULL;
113
* Count the number of NoData values and value ranges
116
for( psList = poGeoRaster->psNoDataList; psList ; psList = psList->psNext )
118
hNoDataItem* phItem = (hNoDataItem*) psList->pData;
120
if( phItem->nBand == nBand )
125
if( phItem->nBand == 0 )
130
if( phItem->nBand > nBand )
137
* Join the object nodata values to layer NoData values
140
nNoDataArraySz = nLayerCount + nObjCount;
142
pahNoDataArray = (hNoDataItem*) VSIMalloc2( sizeof(hNoDataItem),
148
for( psList = poGeoRaster->psNoDataList ; psList && i < nNoDataArraySz;
149
psList = psList->psNext )
151
hNoDataItem* phItem = (hNoDataItem*) psList->pData;
153
if( phItem->nBand == nBand || phItem->nBand == 0 )
155
pahNoDataArray[i].nBand = nBand;
156
pahNoDataArray[i].dfLower = phItem->dfLower;
157
pahNoDataArray[i].dfUpper = phItem->dfUpper;
165
* Use the first value to assigned pixel values
166
* on method ApplyNoDataArray()
169
dfNoData = phItem->dfLower;
174
bHasNoDataArray = nNoDataArraySz > 0;
95
178
// ---------------------------------------------------------------------------
370
470
poDefaultRAT = poRAT->Clone();
372
472
// ----------------------------------------------------------
473
// Check if RAT is just colortable and/or histogram
474
// ----------------------------------------------------------
476
CPLString sColName = "";
478
int nColCount = poRAT->GetColumnCount();
480
for( iCol = 0; iCol < poRAT->GetColumnCount(); iCol++ )
482
sColName = poRAT->GetNameOfCol( iCol );
484
if( EQUAL( sColName, "histogram" ) ||
485
EQUAL( sColName, "red" ) ||
486
EQUAL( sColName, "green" ) ||
487
EQUAL( sColName, "blue" ) ||
488
EQUAL( sColName, "opacity" ) )
499
// ----------------------------------------------------------
373
500
// Format Table description
374
501
// ----------------------------------------------------------
376
503
char szName[OWTEXT];
377
504
char szDescription[OWTEXT];
380
506
strcpy( szDescription, "( ID NUMBER" );
460
581
int nEntryCount = poRAT->GetRowCount();
461
582
int nColunsCount = poRAT->GetColumnCount();
463
char szInsert[OWTEXT];
465
CPLString osInserts =
467
" GR1 SDO_GEORASTER := NULL;\n"
583
int nVATStrSize = MAXLEN_VATSTR * poGeoRaster->poConnection->GetCharSize();
585
// ---------------------------
586
// Allocate array of buffers
587
// ---------------------------
589
void** papWriteFields = (void**) VSIMalloc2(sizeof(void*), nColunsCount + 1);
592
(void*) VSIMalloc3(sizeof(int), sizeof(int), nEntryCount ); // ID field
594
for(iCol = 0; iCol < nColunsCount; iCol++)
596
if( poRAT->GetTypeOfCol( iCol ) == GFT_String )
598
papWriteFields[iCol + 1] =
599
(void*) VSIMalloc3(sizeof(char), nVATStrSize, nEntryCount );
601
if( poRAT->GetTypeOfCol( iCol ) == GFT_Integer )
603
papWriteFields[iCol + 1] =
604
(void*) VSIMalloc3(sizeof(int), sizeof(int), nEntryCount );
606
if( poRAT->GetTypeOfCol( iCol ) == GFT_Real )
608
papWriteFields[iCol + 1] =
609
(void*) VSIMalloc3(sizeof(double), sizeof(double), nEntryCount );
613
// ---------------------------
614
// Load data to buffers
615
// ---------------------------
470
617
for( iEntry = 0; iEntry < nEntryCount; iEntry++ )
474
strcat( szInsert, CPLSPrintf ( " INSERT INTO %s VALUES (%d",
475
pszVATName, iEntry ) );
477
for( iCol = 0; iCol < nColunsCount; iCol++ )
619
((int *)(papWriteFields[0]))[iEntry] = iEntry; // ID field
621
for(iCol = 0; iCol < nColunsCount; iCol++)
479
623
if( poRAT->GetTypeOfCol( iCol ) == GFT_String )
481
strcat( szInsert, CPLSPrintf ( ", '%s'",
482
poRAT->GetValueAsString( iEntry, iCol ) ) );
484
if( poRAT->GetTypeOfCol( iCol ) == GFT_Integer ||
485
poRAT->GetTypeOfCol( iCol ) == GFT_Real )
487
strcat( szInsert, CPLSPrintf ( ", %s",
488
poRAT->GetValueAsString( iEntry, iCol ) ) );
492
strcat( szInsert, ");\n" );
493
osInserts += szInsert;
496
osInserts += CPLSPrintf(
497
" SELECT %s INTO GR1 FROM %s T WHERE\n"
498
" T.%s.RasterDataTable = '%s' AND\n"
499
" T.%s.RasterId = %d FOR UPDATE;\n"
500
" SDO_GEOR.setVAT(GR1, %d, '%s');\n"
501
" UPDATE %s T SET %s = GR1 WHERE\n"
502
" T.%s.RasterDataTable = '%s' AND\n"
503
" T.%s.RasterId = %d;\n"
505
poGeoRaster->pszColumn, poGeoRaster->pszTable,
506
poGeoRaster->pszColumn, poGeoRaster->pszDataTable,
507
poGeoRaster->pszColumn, poGeoRaster->nRasterId,
509
poGeoRaster->pszTable, poGeoRaster->pszColumn,
510
poGeoRaster->pszColumn, poGeoRaster->pszDataTable,
511
poGeoRaster->pszColumn, poGeoRaster->nRasterId );
513
poStmt = poGeoRaster->poConnection->CreateStatement( osInserts.c_str() );
515
if( ! poStmt->Execute() )
517
CPLError( CE_Failure, CPLE_AppDefined, "Insert/registering VAT Error!" );
626
int nOffset = iEntry * nVATStrSize;
627
char* pszTarget = ((char*)papWriteFields[iCol + 1]) + nOffset;
628
const char *pszStrValue = poRAT->GetValueAsString(iEntry, iCol);
629
int nLen = strlen( pszStrValue );
630
nLen = nLen > ( nVATStrSize - 1 ) ? nVATStrSize : ( nVATStrSize - 1 );
631
strncpy( pszTarget, pszStrValue, nLen );
632
pszTarget[nLen] = '\0';
634
if( poRAT->GetTypeOfCol( iCol ) == GFT_Integer )
636
((int *)(papWriteFields[iCol + 1]))[iEntry] =
637
poRAT->GetValueAsInt(iEntry, iCol);
639
if( poRAT->GetTypeOfCol( iCol ) == GFT_Real )
641
((double *)(papWriteFields[iCol]))[iEntry + 1] =
642
poRAT->GetValueAsDouble(iEntry, iCol);
647
// ---------------------------
648
// Prepare insert statement
649
// ---------------------------
651
CPLString osInsert = CPLSPrintf( "INSERT INTO %s VALUES (", pszVATName );
653
for( iCol = 0; iCol < ( nColunsCount + 1); iCol++ )
657
osInsert.append(", ");
659
osInsert.append( CPLSPrintf(":%d", iCol + 1) );
661
osInsert.append(")");
663
poStmt = poGeoRaster->poConnection->CreateStatement( osInsert.c_str() );
665
// ---------------------------
666
// Bind buffers to columns
667
// ---------------------------
669
poStmt->Bind((int*) papWriteFields[0]); // ID field
671
for(iCol = 0; iCol < nColunsCount; iCol++)
673
if( poRAT->GetTypeOfCol( iCol ) == GFT_String )
675
poStmt->Bind( (char*) papWriteFields[iCol + 1], nVATStrSize );
677
if( poRAT->GetTypeOfCol( iCol ) == GFT_Integer )
679
poStmt->Bind( (int*) papWriteFields[iCol + 1]);
681
if( poRAT->GetTypeOfCol( iCol ) == GFT_Real )
683
poStmt->Bind( (double*) papWriteFields[iCol + 1]);
687
if( poStmt->Execute( iEntry ) )
689
poGDS->poGeoRaster->SetVAT( nBand, pszVATName );
693
CPLError( CE_Failure, CPLE_AppDefined, "Insert VAT Error!" );
696
// ---------------------------
698
// ---------------------------
700
for(iCol = 0; iCol < ( nColunsCount + 1); iCol++)
702
CPLFree( papWriteFields[iCol] );
705
CPLFree( papWriteFields );
523
poGDS->poGeoRaster->SetVAT( nBand, pszVATName );
741
925
return GMF_ALL_VALID;
928
// ---------------------------------------------------------------------------
930
// ---------------------------------------------------------------------------
932
void GeoRasterRasterBand::ApplyNoDataArry(void* pBuffer)
936
long n = nBlockXSize * nBlockYSize;
942
GByte* pbBuffer = (GByte*) pBuffer;
944
for( i = 0; i < n; i++ )
946
for( j = 0; j < nNoDataArraySz; j++ )
948
if( pbBuffer[i] == (GByte) pahNoDataArray[j].dfLower ||
949
( pbBuffer[i] > (GByte) pahNoDataArray[j].dfLower &&
950
pbBuffer[i] < (GByte) pahNoDataArray[j].dfUpper ) )
952
pbBuffer[i] = (GByte) dfNoData;
962
float* pfBuffer = (float*) pBuffer;
964
for( i = 0; i < n; i++ )
966
for( j = 0; j < nNoDataArraySz; j++ )
968
if( pfBuffer[i] == (float) pahNoDataArray[j].dfLower ||
969
( pfBuffer[i] > (float) pahNoDataArray[j].dfLower &&
970
pfBuffer[i] < (float) pahNoDataArray[j].dfUpper ) )
972
pfBuffer[i] = (float) dfNoData;
982
double* pdfBuffer = (double*) pBuffer;
984
for( i = 0; i < n; i++ )
986
for( j = 0; j < nNoDataArraySz; j++ )
988
if( pdfBuffer[i] == (double) pahNoDataArray[j].dfLower ||
989
( pdfBuffer[i] > (double) pahNoDataArray[j].dfLower &&
990
pdfBuffer[i] < (double) pahNoDataArray[j].dfUpper ) )
992
pdfBuffer[i] = (double) dfNoData;
1002
GInt16* pnBuffer = (GInt16*) pBuffer;
1004
for( i = 0; i < n; i++ )
1006
for( j = 0; j < nNoDataArraySz; j++ )
1008
if( pnBuffer[i] == (GInt16) pahNoDataArray[j].dfLower ||
1009
( pnBuffer[i] > (GInt16) pahNoDataArray[j].dfLower &&
1010
pnBuffer[i] < (GInt16) pahNoDataArray[j].dfUpper ) )
1012
pnBuffer[i] = (GInt16) dfNoData;
1022
GInt32* pnBuffer = (GInt32*) pBuffer;
1024
for( i = 0; i < n; i++ )
1026
for( j = 0; j < nNoDataArraySz; j++ )
1028
if( pnBuffer[i] == (GInt32) pahNoDataArray[j].dfLower ||
1029
( pnBuffer[i] > (GInt32) pahNoDataArray[j].dfLower &&
1030
pnBuffer[i] < (GInt32) pahNoDataArray[j].dfUpper ) )
1032
pnBuffer[i] = (GInt32) dfNoData;
1041
GUInt16* pnBuffer = (GUInt16*) pBuffer;
1043
for( i = 0; i < n; i++ )
1045
for( j = 0; j < nNoDataArraySz; j++ )
1047
if( pnBuffer[i] == (GUInt16) pahNoDataArray[j].dfLower ||
1048
( pnBuffer[i] > (GUInt16) pahNoDataArray[j].dfLower &&
1049
pnBuffer[i] < (GUInt16) pahNoDataArray[j].dfUpper ) )
1051
pnBuffer[i] = (GUInt16) dfNoData;
1060
GUInt32* pnBuffer = (GUInt32*) pBuffer;
1062
for( i = 0; i < n; i++ )
1064
for( j = 0; j < nNoDataArraySz; j++ )
1066
if( pnBuffer[i] == (GUInt32) pahNoDataArray[j].dfLower ||
1067
( pnBuffer[i] > (GUInt32) pahNoDataArray[j].dfLower &&
1068
pnBuffer[i] < (GUInt32) pahNoDataArray[j].dfUpper ) )
1070
pnBuffer[i] = (GUInt32) dfNoData;