OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGdalWriter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 //*******************************************************************
10 // $Id: ossimGdalWriter.cpp 21634 2012-09-06 18:15:26Z dburken $
11 
12 #include "ossimGdalWriter.h"
13 #include "ossimOgcWktTranslator.h"
14 #include "ossimGdalTiledDataset.h"
18 #include <ossim/base/ossimNotify.h>
20 #include <ossim/base/ossimRefPtr.h>
22 #include <ossim/base/ossimTrace.h>
31 #include <ossim/vpfutil/set.h>
32 #include <cmath>
33 #include <iterator>
34 #include <sstream>
35 using namespace std;
36 
37 static int CPL_STDCALL gdalProgressFunc(double percentComplete,
38  const char* msg,
39  void* data)
40 {
41  ossimGdalWriter* writer = (ossimGdalWriter*)data;
42 
43  ossimProcessProgressEvent event(writer,
44  percentComplete*100.0,
45  msg,
46  false);
47 
48  writer->fireEvent(event);
49 
50  return !writer->needsAborting();
51 }
52 
53 static ossimTrace traceDebug(ossimString("ossimGdalWriter:debug"));
54 
56 
57 static ossimOgcWktTranslator translator;
58 
61  theDriverName(""),
62  theDriver((GDALDriverH)0),
63  theDataset((GDALDatasetH)0),
64  theJpeg2000TileSize(),
65  theDriverOptionValues(),
66  theGdalDriverOptions(0),
67  theGdalOverviewType(ossimGdalOverviewType_NONE),
68  theColorLutFlag(false),
69  theColorLut(0),
70  theLutFilename(),
71  theNBandToIndexFilter(0)
72 {
73 }
74 
76 {
78  close();
79  theDataset = 0;
80  theDriverName = "";
81 }
82 
84 {
85  return (theDriver != 0);
86 }
87 
89 {
91  theDriver = GDALGetDriverByName(theDriverName.c_str());
92 
93  if(theDriver)
94  {
95  return true;
96  }
97 
98  return false;
99 }
100 
102 {
103  if(theDataset)
104  {
105  GDALClose(theDataset);
106  theDataset = 0;
107  }
108 }
109 
111 {
114 }
115 
117 {
118  theColorLutFlag = true;
120 }
121 
126  const char* prefix)const
127 {
128 
129  if (traceDebug())
130  {
132  << "ossimGdalWriter::saveState entered ..."
133  << "\nprefix: " << prefix << std::endl;
134  }
135 
136  ossimString rrdOption = CPLGetConfigOption("HFA_USE_RRD","");
137  if(rrdOption != "")
138  {
139  kwl.add(prefix,
140  "HFA_USE_RRD",
141  rrdOption,
142  true);
143  }
144  kwl.add(prefix,
145  "gdal_overview_type",
147  true);
148  kwl.add(prefix, theDriverOptionValues);
149 
150  kwl.add(prefix,
151  "color_lut_flag",
153  true);
154 
155  if(theColorLutFlag)
156  {
157  if(theLutFilename != "")
158  {
159  kwl.add(prefix,
160  "lut_filename",
162  true);
163  }
164  else
165  {
166  if ( theColorLut.valid() )
167  {
168  ossimString newPrefix = ossimString(prefix) + "lut.";
169  theColorLut->saveState(kwl, newPrefix.c_str());
170  }
171  }
172  }
173 
174  return ossimImageFileWriter::saveState(kwl, prefix);
175 }
176 
182  const char* prefix)
183 {
184  ossimImageFileWriter::loadState(kwl, prefix);
185 
186  ossimString regExpression = (ossimString("^") +
187  ossimString(prefix) +
188  "property[0-9]+");
189  const char* hfa_use_rrd = kwl.find(prefix, "HFA_USE_RRD");
190 
191  if(hfa_use_rrd)
192  {
193  CPLSetConfigOption("HFA_USE_RRD", hfa_use_rrd);
194  }
195  if (traceDebug())
196  {
198  << "ossimGdalWriter::loadState entered ..."
199  << "\nprefix: " << (prefix?prefix:"null")
200  << "\nregExpression: " << regExpression
201  << "\nkwl:" << kwl << std::endl;
202  }
203  const char* overviewType = kwl.find(prefix, "gdal_overview_type");
204 
205  if(overviewType)
206  {
208  }
209 
210  ossimString newPrefix = ossimString(prefix) + "lut.";
211 
212  const char* colorLutFlag = kwl.find(prefix, "color_lut_flag");
213  if(colorLutFlag)
214  {
215  theColorLutFlag = ossimString(colorLutFlag).toBool();
216  }
217  else
218  {
219  theColorLutFlag = false;
220  }
221 
222  theLutFilename = ossimFilename(kwl.find(prefix, "lut_filename"));
224  if ( theColorLut.valid() == false ) theColorLut = new ossimNBandLutDataObject();
225  if(theLutFilename != "")
226  {
228  }
229  else
230  {
231  theColorLut->loadState(kwl, newPrefix.c_str());
232  }
233 
234  vector<ossimString> keys = kwl.getSubstringKeyList( regExpression );
236 
238 
240  regExpression);
241 
242  if(prefix)
243  {
245  }
246 
247  if (traceDebug())
248  {
250  << "ossimGdalWriter::loadState exiting..." << std::endl;
251  }
252  return true;
253 }
254 
255 void ossimGdalWriter::getSupportedWriters(vector<ossimString>& /* writers */)
256 {
257 }
258 
260 {
261  return (theColorLutFlag);
262 }
263 
265 {
266  bool needColorLut = false;
267  bool needLoop = true;
270  if (imageInputs.size() > 0)
271  {
272  for (ossim_uint32 i = 0; i < imageInputs.size(); i++)
273  {
274  if (needLoop == false)
275  {
276  break;
277  }
278  ossimImageChain* source = PTR_CAST(ossimImageChain, imageInputs[i].get());
279  if (source)
280  {
282  for (ossim_uint32 j = 0; j < imageChains.size(); j++)
283  {
284  if (needLoop == false)
285  {
286  break;
287  }
288  ossimImageChain* imageChain = PTR_CAST(ossimImageChain, imageChains[j].get());
289  if (imageChain)
290  {
293 
294  for (ossim_uint32 h= 0; h < imageHandlers.size(); h++)
295  {
296  ossimImageHandler* handler =
297  PTR_CAST(ossimImageHandler, imageHandlers[h].get());
298  if (handler)
299  {
300  if (handler->hasLut() != 0) //
301  {
302  colorLut = handler->getLut();
303  needColorLut = true;
304  }
305  else //if not all handlers have color luts, ignore the color lut.
306  {
307  needColorLut = false;
308  needLoop = false;
309  break;
310  }
311  }
312  }
313  }
314  }
315  }
316  }
317  }
318 
319  if (needColorLut && colorLut )
320  {
321  setLut(*colorLut.get());
322  }
323 }
324 
326 {
327  bool result = true; // On failure set to false.
328 
329  const char *MODULE = "ossimGdalWriter::writeFile()";
330 
331  if(traceDebug())
332  {
333  CLOG << "entered..." << std::endl;
334  }
335 
336  if(theDataset)
337  {
338  close();
339  }
340 
341  checkColorLut();
342 
343  //---
344  // If isInputDataIndexed is true the data fed to writer is already in palette index form so
345  // the addition of the ossimNBandToIndexFilter is not needed.
346  //---
347  if( isLutEnabled() && !isInputDataIndexed() )
348  {
356  }
357  else
358  {
360  }
361 
362  //---
363  // setup gdal driver options
364  //---
365  ossimRefPtr<ossimProperty> blockSize =
366  getProperty(theDriverName+ossimString("_BLOCKSIZE"));
367  if(blockSize.valid())
368  {
369  ossim_uint32 size = blockSize->valueToString().toUInt32();
370  ossimIpt tileSize;
371  if(size > 0)
372  {
373  tileSize = ossimIpt(size, size);
374  theInputConnection->setTileSize(tileSize);
375  }
376  else
377  {
378  ossimIpt defaultSize = theInputConnection->getTileSize();
379  if(defaultSize.y != defaultSize.x)
380  {
381  defaultSize.y = defaultSize.x;
382  theInputConnection->setTileSize(defaultSize);
383  }
384  blockSize->setValue(ossimString::toString(defaultSize.x));
385  setProperty(blockSize);
386  theInputConnection->setTileSize(defaultSize);
387  }
388  }
390 
391  if(!theInputConnection->isMaster()) // MPI slave process...
392  {
395  {
398  }
399  result = true;
400  }
401  else // MPI master process.
402  {
403  open();
404 
405  if(isOpen())
406  {
407  GDALDataType gdalType = getGdalDataType(theInputConnection->
408  getOutputScalarType());
410 
411  theDataset = GDALCreate( theDriver ,
412  theFilename.c_str(),
413  (int)theAreaOfInterest.width(),
414  (int)theAreaOfInterest.height(),
415  (int)bandCount,
416  gdalType,
418 
419  // ESH 09/2009 -- If no raster bands do block write.
420  int nRasterBands = GDALGetRasterCount( theDataset );
421 
422  if(theDataset && nRasterBands>0)
423  {
425 
426  if (theColorLutFlag)
427  {
428  writeColorMap(nRasterBands);
429  }
430 
432  ossimRefPtr<ossimImageData> currentTile =
434  ossimRefPtr<ossimImageData> outputTile =
435  (ossimImageData*)currentTile->dup();
436  outputTile->initialize();
437 
438  //---
439  // DRB 20081017
440  // Trac #404: Setting no data value for imagine (hfa) and j2k
441  // causing view issues with ArcMap and Erdas Imagine when null
442  // values are present in
443  // valid image data.
444  //---
445  if (theDriver)
446  {
447  ossimString driverName = GDALGetDriverShortName(theDriver);
448  if ( (driverName != "HFA") && (driverName != "JP2MrSID") &&
449  (driverName != "JP2KAK") && (driverName != "JPEG2000") )
450  {
451  for(ossim_uint32 band = 0;
452  band < currentTile->getNumberOfBands();
453  ++band)
454  {
455  GDALRasterBandH aBand =
456  GDALGetRasterBand(theDataset, band+1);
457  if(aBand)
458  {
459  GDALSetRasterNoDataValue(
460  aBand, theInputConnection->getNullPixelValue(band));
461  }
462  }
463  if(traceDebug())
464  {
466  << "GDALSetRasterNoDataValue called for driver: "
467  << driverName << std::endl;
468  }
469  }
470  else
471  {
472  if(traceDebug())
473  {
475  << "GDALSetRasterNoDataValue not called for driver: "
476  << driverName << std::endl;
477  }
478  }
479 
480  // ESH 05/2009: Add min/max to gdal metadata
481  ossim_uint32 numberOfBands = currentTile->getNumberOfBands();
482  for( ossim_uint32 idx = 0; idx < numberOfBands; ++idx )
483  {
484  GDALRasterBandH aBand =
485  GDALGetRasterBand(theDataset, idx+1);
486  if(aBand)
487  {
488  // GDAL always assumes "area".
489  GDALSetMetadataItem( aBand, "AREA_OR_POINT", "Area", 0 );
490 
491  double minPix = (double)currentTile->getMinPix( idx );
492  double maxPix = (double)currentTile->getMaxPix( idx );
493 
494  // Only set the metadata if the values makes some sense.
495  if ( maxPix > 0.0 && minPix < maxPix )
496  {
497  char szValue[128];
498  sprintf( szValue, "%.14g", minPix );
499  GDALSetMetadataItem( aBand, "STATISTICS_MINIMUM", szValue, 0 );
500 
501  sprintf( szValue, "%.14g", maxPix );
502  GDALSetMetadataItem( aBand, "STATISTICS_MAXIMUM", szValue, 0 );
503  }
504  }
505  }
506  }
507 
508  ossim_uint32 numberOfTiles =
511 
513  while(currentTile.valid()&&(!needsAborting()))
514  {
515  ossimIrect clipRect =
517  outputTile->setImageRectangle(clipRect);
518  outputTile->loadTile(currentTile.get());
519  //ossimIpt offset = currentTile->getOrigin() -
520  //theAreaOfInterest.ul();
521  ossimIpt offset = clipRect.ul() - theAreaOfInterest.ul();
522 
523  for(ossim_uint32 band = 0;
524  ((band < (currentTile->getNumberOfBands()))&&
525  (!needsAborting()));
526  ++band)
527  {
528  GDALRasterBandH aBand=0;
529  aBand = GDALGetRasterBand(theDataset, band+1);
530 
531  if(aBand)
532  {
533  GDALRasterIO( aBand,
534  GF_Write,
535  offset.x,
536  offset.y,
537  clipRect.width(),
538  clipRect.height(),
539  outputTile->getBuf(band),
540  outputTile->getWidth(),
541  outputTile->getHeight(),
542  gdalType,
543  0,
544  0);
545  }
546 
547  ++tileNumber;
548  ossimProcessProgressEvent event(this,
549  ((double)tileNumber/
550  (double)numberOfTiles)*100.0,
551  "",
552  false);
553 
554  fireEvent(event);
555  }
556  currentTile = theInputConnection->getNextTile();
557 
558  }
559 
560  if(theDataset)
561  {
562  close();
564  (!needsAborting()))
565  {
566  theDataset= GDALOpen( theFilename.c_str(), GA_Update );
567 
568  if( theDataset == 0 )
569  {
570  theDataset = GDALOpen( theFilename.c_str(), GA_ReadOnly );
571  }
573  close();
574  }
575  }
576  else
577  {
579  << "ossimGdalWriter::writeFile unable to create dataset"
580  << std::endl;
581  result = false;
582  }
583 
584  } // End of "if (theDataset)"
585  else
586  {
587  result = writeBlockFile();
588  }
589 
590  }
591  else // open failed...
592  {
593  result = false;
594  if(traceDebug())
595  {
596  CLOG << "Unable to open file for writing. Exiting ..."
597  << std::endl;
598  }
599  }
600 
601  if (result)
602  {
603  // Clean up files...
605  }
606 
607  } // End of "else // MPI master process."
608 
610  {
613  }
614 
615  return result;
616 
617 } // End of: ossimGdalWriter::writeFile
618 
620 {
623 
624  MEMTiledDataset* tiledDataset = new MEMTiledDataset(theInputConnection.get());
625 
626  //---
627  // DRB 20081017
628  // Trac #404: Setting no data value for imagine (hfa) and j2k causing view
629  // issues with ArcMap and Erdas Imagine when null values are present in
630  // valid image data.
631  //---
632  if (theDriver)
633  {
634  ossimString driverName = GDALGetDriverShortName(theDriver);
635  if ( (driverName == "HFA") || (driverName == "JP2MrSID") ||
636  (driverName == "JP2KAK") || (driverName == "JPEG2000") )
637  {
638  tiledDataset->setNoDataValueFlag(false);
639  }
640  }
641 
642  ossimString driverName="null";
643  if (theDriver)
644  {
645  driverName = GDALGetDriverShortName(theDriver);
646  }
647 
648  writeProjectionInfo(tiledDataset);
649  theDataset = GDALCreateCopy( theDriver,
650  theFilename.c_str(),
651  tiledDataset ,
652  true,
654  (GDALProgressFunc)&gdalProgressFunc,
655  this);
656 
657  if(theDataset&&!needsAborting())
658  {
660  {
662  }
663  close();
664  }
665  else
666  {
667  if(traceDebug())
668  {
669  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimGdalWriter::writeBlockFile(): Unable to create dataset for file " << theFilename << std::endl;
670  }
671  return false;
672  }
673  // Trac #299: Ingest tasks are failing when generating png thumbnails
674  // ESH 08/2008: Added in a NULL check on theDataset, since GDALGetDriverShortName
675  // crashes the app if given a NULL pointer.
676  if( theDataset && ossimString(GDALGetDriverShortName(theDataset)) == ossimString("PNG") )
677  {
679  }
680 
681  return true;
682 }
683 
685 {
686  if ( theDataset && theColorLut.valid() )
687  {
688  bool hasAlpha = (theColorLut->getNumberOfBands() == 4);
689 
690  for (int band = 0; band < bands; band++)
691  {
692  GDALRasterBandH aBand=0;
693  aBand = GDALGetRasterBand(theDataset, band+1);
694  if(aBand)
695  {
696  bool hasEntryLabel = false;
698  std::vector<ossimString> entryLabels = theColorLut->getEntryLabels(band);
699  if (entryLabels.size() == entryNum)
700  {
701  hasEntryLabel = true;
702  }
703 
704  GDALColorTable* gdalColorTable = new GDALColorTable();
705  for(ossim_uint32 entryIndex = 0; entryIndex < entryNum; entryIndex++)
706  {
707  GDALColorEntry colorEntry;
708  colorEntry.c1 = (*theColorLut)[entryIndex][0];
709  colorEntry.c2 = (*theColorLut)[entryIndex][1];
710  colorEntry.c3 = (*theColorLut)[entryIndex][2];
711  colorEntry.c4 = hasAlpha ? (*theColorLut)[entryIndex][3] : 255;
712 #if 0
713  if (hasEntryLabel)
714  {
715  char* labelName = const_cast<char*>(entryLabels[entryIndex].c_str());
716  colorEntry.poLabel = labelName;
717  }
718  else
719  {
720  colorEntry.poLabel = NULL;
721  }
722 #endif
723 
724  gdalColorTable->SetColorEntry(entryIndex, &colorEntry);
725  }
726 
727  GDALSetRasterColorTable(aBand, gdalColorTable);
728  delete gdalColorTable;
729  }
730  }
731  }
732 }
733 
734 void ossimGdalWriter::writeProjectionInfo(GDALDatasetH dataset)
735 {
736  // Get current input geometry
738  if(geom.valid())
739  {
740  const ossimMapProjection* mapProj =
742 
743  if (mapProj)
744  {
745  ossim_uint32 pcs_code = mapProj->getPcsCode();
746  if (pcs_code == 0)
747  pcs_code = 32767;
748 
749  double geoTransform[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
750 
751  ossimDpt tiePoint;
752  ossimDpt scale;
753  if (mapProj->isGeographic())
754  {
755  // Get the ground tie point.
756  ossimGpt gpt;
757  mapProj->lineSampleToWorld(theAreaOfInterest.ul(), gpt);
758  tiePoint = gpt;
759 
760  // Get the scale.
761  scale.x = mapProj->getDecimalDegreesPerPixel().x;
762  scale.y = -mapProj->getDecimalDegreesPerPixel().y;
763  }
764  else
765  {
766  // Get the easting northing tie point.
768  tiePoint);
769 
770  // Get the scale.
771  scale.x = mapProj->getMetersPerPixel().x;
772  scale.y = -mapProj->getMetersPerPixel().y;
773  }
774 
775  geoTransform[1] = scale.x;
776  geoTransform[5] = scale.y;
777  geoTransform[0] = tiePoint.x;
778  geoTransform[3] = tiePoint.y;
779 
780  //---
781  // Since OSSIM is pixel_is_point, shift the tie point by
782  // half a pixel since GDAL output is pixel_is_area.
783  //---
784  geoTransform[0] -= fabs(scale.x) / 2.0;
785  geoTransform[3] += fabs(scale.y) / 2.0;
786 
787  // Translate projection information to GDAL settable WKT
788  ossimString wktString = "";
789  if( mapProj->getProjectionName() == ossimString("ossimBngProjection") )
790  {
791  wktString = "PROJCS[\"OSGB 1936 / British National Grid\",GEOGCS[\"OSGB 1936\","
792  "DATUM[\"OSGB_1936\",SPHEROID[\"Airy 1830\",6377563.396,299.3249646]],PRIMEM[\""
793  "Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],"
794  "PARAMETER[\"latitude_of_origin\",49],PARAMETER[\"central_meridian\",-2],PARAMETER[\""
795  "scale_factor\",0.999601272],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_"
796  "northing\",-100000],UNIT[\"meter\",1]]";
797  }
798  else if (mapProj->getProjectionName() == ossimString("ossimAlbersProjection") )
799  {
800  wktString = "PROJCS[\"Albers Conical Equal Area\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\","
801  "SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],"
802  "TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,"
803  "AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],"
804  "AUTHORITY[\"EPSG\",\"4269\"]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"standard_parallel_1\",29.5],"
805  "PARAMETER[\"standard_parallel_2\",45.5],PARAMETER[\"latitude_of_center\",23],PARAMETER[\"longitude_of_center\",-96],"
806  "PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"meters\",1]]";
807  }
808  else
809  {
810  ossimKeywordlist kwl;
811  mapProj->saveState(kwl);
812  wktString = translator.fromOssimKwl(kwl);
813  }
814 
815  // Set GDAL projection and corner coordinates.
816  GDALSetProjection(dataset, wktString.c_str());
817  GDALSetGeoTransform(dataset, geoTransform);
818 
819  } // matches: if (mapProj)
820 
821  } // matches: if(geom.valid())
822 }
823 
825  const char* prefix)
826 {
827  ossimString regExpression = ossimString("^(") +
828  ossimString(prefix) +
829  "option[0-9]+.)";
830 
831 // while(numberOfMatches < static_cast<unsigned long>(numberOfSources))
832 // {
833 // ossimString newPrefix = prefix;
834 // newPrefix += ossimString("option");
835 // newPrefix += ossimString::toString(i);
836 // newPrefix += ossimString(".");
837 
838 // const char* name = kwl.find(newPrefix.c_str(), "name");
839 // const char* value = kwl.find(newPrefix.c_str(), "value");
840 
841 // if(ossimString(name) == "tilewidth")
842 // {
843 // theJpeg2000TileSize.x = ossimString(value).toInt();
844 // }
845 // else if(ossimString(name) == "tileheight")
846 // {
847 // theJpeg2000TileSize.y = ossimString(value).toInt();
848 // }
849 // }
850 
851 }
852 
853 
855 {
856  GDALDataType dataType = GDT_Unknown;
857 
858  switch(scalar)
859  {
860  case OSSIM_UCHAR:
861  {
862  dataType = GDT_Byte;
863  break;
864  }
865  case OSSIM_USHORT11:
866  case OSSIM_USHORT16:
867  {
868  dataType = GDT_UInt16;
869  break;
870  }
871  case OSSIM_SSHORT16:
872  {
873  dataType = GDT_Int16;
874  break;
875  }
876  case OSSIM_FLOAT:
878  {
879  dataType = GDT_Float32;
880  break;
881  }
882  case OSSIM_DOUBLE:
884  {
885  dataType = GDT_Float64;
886  break;
887  }
888  default:
889  break;
890  }
891 
892  return dataType;
893 }
894 
896 {
898  ossimString regExpression = (ossimString("^")+
899  "property[0-9]+");
900  vector<ossimString> keys = theDriverOptionValues.getSubstringKeyList( regExpression );
901 
902  if(keys.size())
903  {
904  ossim_uint32 i = 0;
905  theGdalDriverOptions = new char*[keys.size()+1];
906  for(i = 0 ; i < keys.size(); ++i)
907  {
908  ossimString name = theDriverOptionValues.find(keys[i] +".name");
909  ossimString value = theDriverOptionValues.find(keys[i] +".value");
910 
911  //---
912  // Special hack...
913  //
914  // Lossless compression for non 8 bit data not supported for kakadu.
915  //---
916  if (theInputConnection.valid() && (GDALGetDriverByName("JP2KAK")) && (name == "QUALITY"))
917  {
919  {
920  double d = value.toDouble();
921  if (d >= 99.5)
922  {
923  if (traceDebug())
924  {
926  << "DEBUG:"
927  << "\nLossless quality not valid for non 8 bit data"
928  << "\nResetting to 99.0"
929  << std::endl;
930  }
931 
932  value = "99.0";
933  }
934  }
935  }
936 
937  // ESH 01/2009 -- For HFA handling of SRS's that come from pcs codes:
938  // use new option in HFA driver (gdal-1.6.0). This option forces the
939  // coordinate system tags to be more compatible with ArcGIS. We might
940  // have to add in a check for the pcs code here if that is possible.
941  //---
942  // Special hack...
943  //---
944  if ( (GDALGetDriverByName("HFA")) &&
945  (name == "FORCETOPESTRING") )
946  {
947  value = "TRUE";
948  }
949 
950  ossimString combine = name + "=" + value;
951 
952  theGdalDriverOptions[i] = new char[combine.size() + 1];
953  strcpy(theGdalDriverOptions[i], combine.c_str());
954 
955  if (traceDebug())
956  {
958  << "\nkey: " << keys[i]
959  << "\nname: " << name
960  << "\nvalue: " << value
961  << "\ngdal option: " << combine
962  << std::endl;
963  }
964  }
965  theGdalDriverOptions[keys.size()] = 0;
966  }
967 }
968 
970  const ossimString& value,
971  bool replaceFlag)
972 {
973  ossimString regExpression = (ossimString("^")+
974  "property[0-9]+");
975  vector<ossimString> keys = theDriverOptionValues.getSubstringKeyList( regExpression );
976  if(keys.size())
977  {
978  ossim_uint32 i = 0;
979  for(i = 0 ; i < keys.size(); ++i)
980  {
981  ossimString tempName = theDriverOptionValues.find(keys[i] +".name");
982  if(tempName == name)
983  {
984  if(replaceFlag)
985  {
986  theDriverOptionValues.add(keys[i]+".value",
987  value,
988  true);
989  }
990 
991  return;
992  }
993  }
994  }
995  ossimString prefix = "property" + ossimString::toString((ossim_uint32)keys.size()) + ".";
996 
997  theDriverOptionValues.add(prefix,
998  "name",
999  name,
1000  true);
1001  theDriverOptionValues.add(prefix,
1002  "value",
1003  value,
1004  true);
1005 }
1006 
1008 {
1009  int i = 0;
1010 
1012  {
1013  char* currentOption = theGdalDriverOptions[i];
1014 
1015  while(currentOption)
1016  {
1017  ++i;
1018  delete [] currentOption;
1019  currentOption = theGdalDriverOptions[i];
1020  }
1021  delete [] theGdalDriverOptions;
1023  }
1024 }
1025 
1027 {
1028  ossimString strippedName = imageTypeName;
1029  strippedName = strippedName.substitute("gdal_", "");
1030  if(GDALGetDriverByName(strippedName.c_str()))
1031  {
1032  return strippedName;
1033  }
1034 
1035  // check for mime types
1036  //
1037  if(imageTypeName == "image/jp2")
1038  {
1039  if(GDALGetDriverByName("JP2KAK"))
1040  {
1041  return "JP2KAK";
1042  }
1043  else if(GDALGetDriverByName("JPEG2000"))
1044  {
1045  return "JPEG2000";
1046  }
1047  else if(GDALGetDriverByName("JP2MrSID"))
1048  {
1049  return "JP2MrSID";
1050  }
1051  }
1052  if(imageTypeName == "image/png")
1053  {
1054  return "PNG";
1055  }
1056  if(imageTypeName == "image/wbmp")
1057  {
1058  return "BMP";
1059  }
1060  if(imageTypeName == "image/bmp")
1061  {
1062  return "BMP";
1063  }
1064  if(imageTypeName == "image/jpeg")
1065  {
1066  return "JPEG";
1067  }
1068  if(imageTypeName == "image/gif")
1069  {
1070  return "GIF";
1071  }
1072 
1073 
1074  // keep these for backward compatibility
1075  //
1076  if( imageTypeName == "gdal_imagine_hfa")
1077  {
1078  return "HFA";
1079  }
1080  if(imageTypeName == "gdal_nitf_rgb_band_separate")
1081  {
1082  return "NITF";
1083  }
1084  if(imageTypeName == "gdal_jpeg2000")
1085  {
1086  if(GDALGetDriverByName("JP2KAK"))
1087  {
1088  return "JP2KAK";
1089  }
1090  else if(GDALGetDriverByName("JPEG2000"))
1091  {
1092  return "JPEG2000";
1093  }
1094  else if(GDALGetDriverByName("JP2MrSID"))
1095  {
1096  return "JP2MrSID";
1097  }
1098  }
1099  if(imageTypeName == "gdal_arc_info_aig")
1100  {
1101  return "AIG";
1102  }
1103  if(imageTypeName == "gdal_arc_info_gio")
1104  {
1105  return "GIO";
1106  }
1107  if(imageTypeName == "gdal_arc_info_ascii_grid")
1108  {
1109  return "AAIGrid";
1110  }
1111  if(imageTypeName == "gdal_mrsid")
1112  {
1113  return "MrSID";
1114  }
1115  if(imageTypeName == "gdal_jp2mrsid")
1116  {
1117  return "JP2MrSID";
1118  }
1119  if(imageTypeName == "gdal_png")
1120  {
1121  return "PNG";
1122  }
1123  if(imageTypeName == "gdal_jpeg")
1124  {
1125  return "JPEG";
1126  }
1127 
1128  if(imageTypeName == "gdal_gif")
1129  {
1130  return "GIF";
1131  }
1132  if(imageTypeName == "gdal_dted")
1133  {
1134  return "DTED";
1135  }
1136  if(imageTypeName == "gdal_usgsdem")
1137  {
1138  return "USGSDEM";
1139  }
1140  if(imageTypeName == "gdal_bmp")
1141  {
1142  return "BMP";
1143  }
1144  if(imageTypeName == "gdal_raw_envi")
1145  {
1146  return "ENVI";
1147  }
1148  if(imageTypeName == "gdal_raw_esri")
1149  {
1150  return "EHdr";
1151  }
1152  if(imageTypeName == "gdal_raw_pci")
1153  {
1154  return "PAux";
1155  }
1156  if(imageTypeName == "gdal_pcidsk")
1157  {
1158  return "PCIDSK";
1159  }
1160  if(imageTypeName == "gdal_sdts")
1161  {
1162  return "SDTS";
1163  }
1164  if(imageTypeName == "gdal_jp2ecw")
1165  {
1166  return "JP2ECW";
1167  }
1168  if(imageTypeName == "gdal_ecw")
1169  {
1170  return "ECW";
1171  }
1172  return imageTypeName;
1173 }
1174 
1175 void ossimGdalWriter::getImageTypeList(std::vector<ossimString>& imageTypeList)const
1176 {
1177  int driverCount = GDALGetDriverCount();
1178  int idx = 0;
1179 
1180  for(idx = 0; idx < driverCount; ++idx)
1181  {
1182  GDALDriverH driver = GDALGetDriver(idx);
1183 
1184 
1185  if(driver)
1186  {
1187  const char* metaData = GDALGetMetadataItem(driver, GDAL_DCAP_CREATE, 0);
1188  if(metaData)
1189  {
1190  imageTypeList.push_back("gdal_" + ossimString(GDALGetDriverShortName(driver)));
1191  }
1192  else
1193  {
1194  metaData = GDALGetMetadataItem(driver, GDAL_DCAP_CREATECOPY, 0);
1195  if(metaData)
1196  {
1197  imageTypeList.push_back("gdal_" + ossimString(GDALGetDriverShortName(driver)));
1198  }
1199  }
1200  }
1201  }
1202 }
1203 
1204 bool ossimGdalWriter::hasImageType(const ossimString& imageType) const
1205 {
1206  // check for non standard image types found in the
1207  // getImageTypeList
1208  //
1209  if((imageType == "gdal_imagine_hfa") ||
1210  (imageType == "gdal_nitf_rgb_band_separate") ||
1211  (imageType == "gdal_jpeg2000") ||
1212  (imageType == "gdal_jp2ecw") ||
1213  (imageType == "gdal_arc_info_aig") ||
1214  (imageType == "gdal_arc_info_gio") ||
1215  (imageType == "gdal_arc_info_ascii_grid") ||
1216  (imageType == "gdal_mrsid") ||
1217  (imageType == "image/mrsid") ||
1218  (imageType == "gdal_jp2mrsid") ||
1219  (imageType == "image/jp2mrsid") ||
1220  (imageType == "gdal_png") ||
1221  (imageType == "image/png") ||
1222  (imageType == "image/bmp") ||
1223  (imageType == "image/wbmp") ||
1224  (imageType == "gdal_jpeg") ||
1225  (imageType == "image/jpeg") ||
1226  (imageType == "gdal_gif") ||
1227  (imageType == "image/gif") ||
1228  (imageType == "gdal_dted") ||
1229  (imageType == "image/dted") ||
1230  (imageType == "gdal_bmp") ||
1231  (imageType == "gdal_xpm") ||
1232  (imageType == "image/x-xpixmap") ||
1233  (imageType == "gdal_raw_envi") ||
1234  (imageType == "gdal_raw_esri") ||
1235  (imageType == "gdal_raw_esri") ||
1236  (imageType == "gdal_pcidsk") ||
1237  (imageType == "gdal_sdts"))
1238  {
1239  return true;
1240  }
1241 
1242  return ossimImageFileWriter::hasImageType(imageType);
1243 }
1244 
1246 {
1247  ossimString result;
1248 
1250  GDALDriverH driver = GDALGetDriverByName(driverName.c_str());
1251 
1252  if(driver)
1253  {
1254  result = ossimString(GDALGetMetadataItem(driver, GDAL_DMD_EXTENSION, 0));
1255  std::vector<ossimString> splitString;
1256  result.split(splitString, "/");
1257  if(!splitString.empty()) result = splitString[0];
1258  }
1259  return result;
1260 
1261  // we now use the metadata interface to get access to a drivers default file extension
1262 #if 0
1263  ossimString imgTypeStr(theOutputImageType);
1264  imgTypeStr.downcase();
1265 
1266  // mime types
1267  if(imgTypeStr == "image/jp2")
1268  {
1269  return ossimString("jp2");
1270  }
1271  if(imgTypeStr == "image/png")
1272  {
1273  return ossimString("png");
1274  }
1275  if(imgTypeStr == "image/wbmp")
1276  {
1277  return ossimString("bmp");
1278  }
1279  if(imgTypeStr == "image/bmp")
1280  {
1281  return ossimString("bmp");
1282  }
1283  if(imgTypeStr == "image/jpeg")
1284  {
1285  return ossimString("jpg");
1286  }
1287  if(imgTypeStr == "image/gif")
1288  {
1289  return ossimString("gif");
1290  }
1291 
1292 
1293  // keep these for backward compatibility
1294  //
1295  if( imgTypeStr == "gdal_imagine_hfa")
1296  {
1297  return ossimString("hfa");
1298  }
1299  if(imgTypeStr == "gdal_nitf_rgb_band_separate")
1300  {
1301  return ossimString("ntf");
1302  }
1303  if(imgTypeStr == "gdal_jpeg2000")
1304  {
1305  return ossimString("jp2");
1306  }
1307  if(imgTypeStr == "gdal_arc_info_aig")
1308  {
1309  return ossimString("aig");
1310  }
1311  if(imgTypeStr == "gdal_arc_info_gio")
1312  {
1313  return ossimString("gio");
1314  }
1315  if(imgTypeStr == "gdal_arc_info_ascii_grid")
1316  {
1317  return ossimString("aig");
1318  }
1319  if(imgTypeStr == "gdal_mrsid")
1320  {
1321  return ossimString("sid");
1322  }
1323  if(imgTypeStr == "gdal_jp2mrsid")
1324  {
1325  return ossimString("jp2");
1326  }
1327  if(imgTypeStr == "gdal_png")
1328  {
1329  return ossimString("png");
1330  }
1331  if(imgTypeStr == "gdal_jpeg")
1332  {
1333  return ossimString("jpg");
1334  }
1335 
1336  if(imgTypeStr == "gdal_gif")
1337  {
1338  return ossimString("gif");
1339  }
1340  if(imgTypeStr == "gdal_dted")
1341  {
1342  return ossimString("dte");
1343  }
1344  if(imgTypeStr == "gdal_usgsdem")
1345  {
1346  return ossimString("dem");
1347  }
1348  if(imgTypeStr == "gdal_bmp")
1349  {
1350  return ossimString("bmp");
1351  }
1352  if(imgTypeStr == "gdal_raw_envi")
1353  {
1354  return ossimString("raw");
1355  }
1356  if(imgTypeStr == "gdal_raw_esri")
1357  {
1358  return ossimString("raw");
1359  }
1360  if(imgTypeStr == "gdal_raw_pci")
1361  {
1362  return ossimString("raw");
1363  }
1364  if(imgTypeStr == "gdal_pcidsk")
1365  {
1366  return ossimString("pix");
1367  }
1368  if(imgTypeStr == "gdal_sdts")
1369  {
1370  return ossimString("sdt");
1371  }
1372  if(imgTypeStr == "gdal_jp2ecw")
1373  {
1374  return ossimString("jp2");
1375  }
1376  if(imgTypeStr == "gdal_ecw")
1377  {
1378  return ossimString("ecw");
1379  }
1380  return ossimString("ext");
1381 #endif
1382 }
1383 
1385 {
1386  if(!property.valid()) return;
1387  ossimString propName = property->getName();
1388  if(!validProperty(property->getName()))
1389  {
1390  if(property->getName() == "image_type")
1391  {
1393  }
1395  return;
1396  }
1397 
1399  ossimString name = property->getName();
1400 
1401  if(name == "HFA_USE_RRD")
1402  {
1403  bool value = property->valueToString().toBool();
1404  CPLSetConfigOption("HFA_USE_RRD", value?"YES":"NO");
1405  }
1406  else if(name == "gdal_overview_type")
1407  {
1409  }
1410  else if (name == "format")
1411  {
1412  storeProperty(name,
1413  property->valueToString());
1414  }
1415  else if(name == "lut_file")
1416  {
1419  }
1420  else if(name == "color_lut_flag")
1421  {
1422  theColorLutFlag = property->valueToString().toBool();
1423  }
1424  else
1425  {
1426  name = name.substitute(driverName+"_","");
1427  storeProperty(name,
1428  property->valueToString());
1429  }
1430 }
1431 
1433 {
1434 
1435  if(traceDebug())
1436  {
1437  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimGdalWriter::getProperty: entered..." << std::endl;
1438  }
1439 
1440  if(!validProperty(name))
1441  {
1442  return ossimImageFileWriter::getProperty(name);
1443  }
1444 
1445  if(name == "HFA_USE_RRD")
1446  {
1447  return new ossimBooleanProperty(name, ossimString(CPLGetConfigOption(name.c_str(),"NO")).toBool());
1448  }
1449  else if(name == "gdal_overview_type")
1450  {
1452 
1453  prop->addConstraint("none");
1454  prop->addConstraint("nearest");
1455  prop->addConstraint("average");
1456 
1457  return prop;
1458  }
1461  GDALDriverH driver = GDALGetDriverByName(driverName.c_str());
1462  if(traceDebug())
1463  {
1464  ossimNotify(ossimNotifyLevel_DEBUG) << "Driver name = " << driverName << "\n"
1465  << "name = " << name << std::endl;
1466  }
1467 
1468  bool storedValueFlag=false;
1469  ossimString storedValue;
1470 
1471  if(node.valid()&&driver&&name.contains(driverName))
1472  {
1473  ossimString storedName = name;
1474  storedName = storedName.substitute(driverName+"_","");
1475  storedValueFlag = getStoredPropertyValue(storedName,
1476  storedValue);
1477  vector<ossimRefPtr<ossimXmlNode> > nodelist;
1478  node->findChildNodes("Option", nodelist);
1479  ossim_uint32 idx = 0;
1480  for(idx = 0; idx < nodelist.size(); ++idx)
1481  {
1482  ossimRefPtr<ossimXmlAttribute> nameAttribute = nodelist[idx]->findAttribute("name");
1483  if(nameAttribute.valid())
1484  {
1485  if((driverName+"_"+nameAttribute->getValue())== name)
1486  {
1487  ossimRefPtr<ossimXmlAttribute> type = nodelist[idx]->findAttribute("type");
1488 
1489  vector<ossimRefPtr<ossimXmlNode> > valuelist;
1490 
1491  if(type.valid())
1492  {
1493  ossimRefPtr<ossimXmlAttribute> descriptionAttribute = nodelist[idx]->findAttribute("description");
1494  nodelist[idx]->findChildNodes("Value",
1495  valuelist);
1496  ossimString description;
1497  ossimString typeValue = type->getValue();
1498  typeValue = typeValue.downcase();
1499 
1500  if(descriptionAttribute.valid())
1501  {
1502  description = descriptionAttribute->getValue();
1503  }
1504  if((typeValue == "int")||
1505  (typeValue == "integer"))
1506  {
1507  ossimNumericProperty* prop = new ossimNumericProperty(name,
1508  storedValue);
1510  prop->setDescription(description);
1511  return prop;
1512  }
1513  else if(typeValue == "unsigned int")
1514  {
1515  ossimNumericProperty* prop = new ossimNumericProperty(name,
1516  storedValue);
1518  prop->setDescription(description);
1519  return prop;
1520  }
1521  else if(typeValue == "float")
1522  {
1523  ossimNumericProperty* prop = new ossimNumericProperty(name,
1524  storedValue);
1526  prop->setDescription(description);
1527  return prop;
1528  }
1529  else if(typeValue == "boolean")
1530  {
1531  ossimBooleanProperty* prop = new ossimBooleanProperty(name,
1532  storedValue.toBool());
1533 
1534  prop->setDescription(description);
1535  return prop;
1536  }
1537  else if((typeValue == "string-select")||
1538  (typeValue == "string"))
1539  {
1540  ossim_uint32 idx2 = 0;
1541  ossimString defaultValue = "";
1542 
1543  if(storedValueFlag)
1544  {
1545  defaultValue = storedValue;
1546  }
1547  else if(valuelist.size())
1548  {
1549  defaultValue = valuelist[0]->getText();
1550  }
1551  ossimStringProperty* prop = new ossimStringProperty(name,
1552  defaultValue,
1553  false);
1554  for(idx2 = 0; idx2 < valuelist.size();++idx2)
1555  {
1556  prop->addConstraint(valuelist[idx2]->getText());
1557  }
1558  prop->setDescription(description);
1559  return prop;
1560  }
1561  else
1562  {
1563  if(traceDebug())
1564  {
1565  ossimNotify(ossimNotifyLevel_INFO) << "************************TYPE VALUE = " << typeValue << " NOT HANDLED************"<< std::endl;
1566  ossimNotify(ossimNotifyLevel_INFO) << "************************DEFAULTING TO TEXT ************" << std::endl;
1567  }
1568  ossim_uint32 idx2 = 0;
1569  ossimString defaultValue = "";
1570 
1571  if(storedValueFlag)
1572  {
1573  defaultValue = storedValue;
1574  }
1575  else if(valuelist.size())
1576  {
1577  defaultValue = valuelist[0]->getText();
1578  }
1579  ossimStringProperty* prop = new ossimStringProperty(name,
1580  defaultValue,
1581  false);
1582  for(idx2 = 0; idx2 < valuelist.size();++idx2)
1583  {
1584  prop->addConstraint(valuelist[idx2]->getText());
1585  }
1586  prop->setDescription(description);
1587  return prop;
1588  }
1589  }
1590  }
1591  }
1592  }
1593  }
1594 
1595  if(traceDebug())
1596  {
1597  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimGdalWriter::getProperty: entered..." << std::endl;
1598  }
1599  return 0;
1600 }
1601 
1602 void ossimGdalWriter::getPropertyNames(std::vector<ossimString>& propertyNames)const
1603 {
1604  if(traceDebug())
1605  {
1606  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimGdalWriter::getPropertyNames: entered......." << std::endl;
1607  }
1609  propertyNames.push_back("gdal_overview_type");
1610  propertyNames.push_back("HFA_USE_RRD");
1611  getGdalPropertyNames(propertyNames);
1612 }
1613 
1614 void ossimGdalWriter::getGdalPropertyNames(std::vector<ossimString>& propertyNames)const
1615 {
1617  GDALDriverH driver = GDALGetDriverByName(driverName.c_str());
1618 
1619  if(driver)
1620  {
1622 
1623  if(node.valid())
1624  {
1625  vector<ossimRefPtr<ossimXmlNode> > nodelist;
1626  node->findChildNodes("Option", nodelist);
1627 
1628  if(traceDebug())
1629  {
1630  ossimNotify(ossimNotifyLevel_DEBUG) << "GDAL XML PROPERTY LIST" << std::endl
1631  << node.get() << std::endl;
1632  }
1633  ossim_uint32 idx = 0;
1634  for(idx= 0; idx < nodelist.size(); ++idx)
1635  {
1636  ossimRefPtr<ossimXmlAttribute> name = nodelist[idx]->findAttribute("name");
1637  if(name.valid())
1638  {
1639  if(traceDebug())
1640  {
1641  ossimNotify(ossimNotifyLevel_DEBUG) << "Adding property = " << name->getValue() << std::endl;
1642  }
1643  propertyNames.push_back(driverName + "_" + name->getValue());
1644  }
1645  }
1646  }
1647  }
1648  if(traceDebug())
1649  {
1650  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimGdalWriter::getPropertyNames: leaving......." << std::endl;
1651  }
1652 
1653 }
1654 
1656 {
1658  GDALDriverH driver = GDALGetDriverByName(driverName.c_str());
1659 
1660  if(driver)
1661  {
1662  const char* metaData = GDALGetMetadataItem(driver, GDAL_DMD_CREATIONOPTIONLIST, 0);
1663  if(metaData)
1664  {
1665  istringstream in(metaData);
1666  ossimRefPtr<ossimXmlNode> node = new ossimXmlNode(in);
1667  vector<ossimRefPtr<ossimXmlNode> > nodelist;
1668  node->findChildNodes("Option", nodelist);
1669  if(nodelist.size())
1670  {
1671  return node;
1672  }
1673  }
1674  }
1675  return 0;
1676 }
1677 
1679  const ossimString& value)
1680 {
1681  ossimString regExpression = (ossimString("^") +
1682  "property[0-9]+");
1683 
1684  vector<ossimString> keys = theDriverOptionValues.getSubstringKeyList( regExpression );
1685  ossim_uint32 idx = 0;
1686  for(idx = 0; idx < keys.size(); ++idx)
1687  {
1688  ossimString storedName = theDriverOptionValues.find(keys[idx] +".name");
1689 
1690  if(storedName == name)
1691  {
1692  theDriverOptionValues.add(keys[idx] +".value",
1693  value,
1694  true);
1695  return;
1696  }
1697  }
1698  ossimString prefix = (ossimString("property") +
1700  ".");
1701  theDriverOptionValues.add(prefix.c_str(),
1702  "name",
1703  name,
1704  true);
1705  theDriverOptionValues.add(prefix.c_str(),
1706  "value",
1707  value,
1708  true);
1709 }
1710 
1712  ossimString& value)const
1713 {
1714  ossimString regExpression = (ossimString("^") +
1715  "property[0-9]+");
1716 
1717  vector<ossimString> keys = theDriverOptionValues.getSubstringKeyList( regExpression );
1718  ossim_uint32 idx = 0;
1719  for(idx = 0; idx < keys.size(); ++idx)
1720  {
1721  ossimString storedName = theDriverOptionValues.find(keys[idx] +".name");
1722  if(storedName == name)
1723  {
1724  value = ossimString(theDriverOptionValues.find(keys[idx] +".value"));
1725  return true;
1726  }
1727  }
1728 
1729  return false;
1730 }
1731 
1733 {
1734  std::vector<ossimString> propertyNames;
1735 
1736  if((name == "gdal_overview_type")||
1737  (name == "HFA_USE_RRD") || name == "format")
1738  {
1739  return true;
1740  }
1741  getGdalPropertyNames(propertyNames);
1742 
1743  ossim_uint32 idx = 0;
1744  for(idx = 0; idx < propertyNames.size(); ++idx)
1745  {
1746  if(name == propertyNames[idx])
1747  {
1748  return true;
1749  }
1750  }
1751 
1752  return false;
1753 }
1754 
1756 {
1757  switch(theGdalOverviewType)
1758  {
1760  {
1761  return "none";
1762  }
1764  {
1765  return "nearest";
1766  }
1768  {
1769  return "average";
1770  }
1771  }
1772 
1773  return "none";
1774 }
1775 
1777 {
1778  ossimString tempType = typeString;
1779  tempType = tempType.downcase();
1780  tempType = tempType.trim();
1781 
1782  if(tempType == "nearest")
1783  {
1785  }
1786  else if(tempType == "average")
1787  {
1789  }
1790 
1792 }
1793 
1795 {
1796 
1797  if(!theDataset)
1798  {
1799  return;
1800  }
1802 
1803  ossim_uint32 minValue = ossim::min((ossim_uint32)bounds.width(),
1804  (ossim_uint32)bounds.height());
1805 
1806  int nLevels = static_cast<int>(std::log((double)minValue)/std::log(2.0));
1807  int idx = 0;
1808  if(nLevels)
1809  {
1810  ossim_int32* levelsPtr = new ossim_int32[nLevels];
1811  *levelsPtr = 2;
1812  for(idx = 1; idx < nLevels;++idx)
1813  {
1814  levelsPtr[idx] = levelsPtr[idx-1]*2;
1815  }
1816  if(GDALBuildOverviews(theDataset,
1817  gdalOverviewTypeToString().c_str(),
1818  nLevels,
1819  levelsPtr,
1820  0,
1821  0,
1822  GDALTermProgress,
1823  0)!=CE_None)
1824  {
1825  ossimNotify(ossimNotifyLevel_WARN) << "ossimGdalWriter::buildGdalOverviews(): Overview building failed"
1826  << std::endl;
1827  }
1828  delete [] levelsPtr;
1829  }
1830 }
1831 
1833 {
1834  //---
1835  // DRB 20081029
1836  // Trac #419:
1837  //
1838  // The file.aux.xml file contains nodata value keys which is causing view
1839  // issues with ArcMap and Erdas Imagine when null values are present in
1840  // valid image data.
1841  //---
1842  if (theDriver)
1843  {
1844  ossimString driverName = GDALGetDriverShortName(theDriver);
1845  if ( (driverName == "JP2MrSID") || (driverName != "JP2KAK") ||
1846  (driverName == "JPEG2000") )
1847  {
1848  ossimFilename auxXmlFile = theFilename;
1849  auxXmlFile += ".aux.xml";
1850  if ( auxXmlFile.exists() )
1851  {
1852  if ( auxXmlFile.remove() )
1853  {
1855  << "ossimGdalWriter::postProcessOutput NOTICE:"
1856  << "\nFile removed: " << auxXmlFile << std::endl;
1857  }
1858  }
1859  }
1860  }
1861 }
1862 
1864 {
1865  bool result = false;
1866  if ( theInputConnection.valid() )
1867  {
1868  result = theInputConnection->isIndexedData();
1869  }
1870  return result;
1871 }
void setLut(ossimNBandLutDataObject &lut)
virtual void valueToString(ossimString &valueResult) const =0
virtual ossim_uint32 getWidth() const
virtual const ossimDpt & getDecimalDegreesPerPixel() const
Returns decimal degrees per pixel as an ossimDpt with "x" representing longitude and "y" representing...
virtual void setOutputImageType(ossim_int32 type)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
bool getStoredPropertyValue(const ossimString &name, ossimString &value) const
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
virtual bool isIndexedData() const
void stripPrefixFromAll(const ossimString &regularExpression)
ossimRefPtr< ossimNBandToIndexFilter > theNBandToIndexFilter
std::vector< ossimString > getEntryLabels(ossim_uint32 band)
virtual const ossim_float64 * getMaxPix() const
static bool remove(const ossimFilename &pathname)
Removes pathname from filesystem if supported by platform.
RTTI_DEF1(ossimGdalWriter, "ossimGdalWriter", ossimImageFileWriter)
virtual ossim_uint32 getNumberOfBands() const
virtual ossimRefPtr< ossimNBandLutDataObject > getLut() const
#define CLOG
Definition: ossimTrace.h:23
ossim_uint32 getNumberOfBands() const
virtual void setImageRectangle(const ossimIrect &rect)
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void disconnect(ossimConnectableObject *object=0)
Will disconnect the object passed in.
ossim_uint32 tileNumber
void findChildNodes(const ossimString &rel_xpath, ossimXmlNode::ChildListType &nodelist) const
Represents serializable keyword/value map.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual bool writeFile()
Write out the file.
virtual ossim_uint32 getPcsCode() const
Returns the EPSG PCS code or 32767 if the projection is a custom (non-EPSG) projection.
ossimString fromOssimKwl(const ossimKeywordlist &kwl, const char *prefix=NULL) const
void setLut(const ossimNBandLutDataObject &lut)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
void combine(const std::string &left, const std::string &right, char separator, std::string &result)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
double y
Definition: ossimDpt.h:165
ossim_uint32 height() const
Definition: ossimIrect.h:487
bool contains(char aChar) const
Definition: ossimString.h:58
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimIrect theAreaOfInterest
virtual ossimConnectableObject::ConnectableObjectList findAllObjectsOfType(const RTTItypeid &typeInfo, bool recurse=true)=0
virtual void setOutputImageType(const ossimString &type)
static ossimString toString(bool aValue)
Numeric to string methods.
virtual bool isGeographic() const
void getGdalPropertyNames(std::vector< ossimString > &propertyNames) const
const ossimIpt & ul() const
Definition: ossimIrect.h:274
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
virtual bool isOpen() const
virtual ~ossimGdalWriter()
virtual ossim_uint32 getHeight() const
GDALDriverH theDriver
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
virtual void setOptions(ossimKeywordlist &kwl, const char *prefix=NULL)
void addConstraint(const ossimString &value)
Pure virtual base class for image file writers.
const ossimString & getValue() const
void setNoDataValueFlag(bool flag)
DRB - 20081020 If true (default) the no data value will be set to null pixel value.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
ossimString convertToDriverName(const ossimString &imageTypeName) const
virtual void fireEvent(ossimEvent &event)
virtual void initialize()
Initialize the data buffer.
ossimFilename theLutFilename
virtual ossimObject * dup() const
void storeProperty(const ossimString &name, const ossimString &value)
ossimKeywordlist theDriverOptionValues
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
virtual void writeColorMap(int bands)
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
const ConnectableObjectList & getInputList() const
virtual bool hasImageType(const ossimString &imageType) const
bool hasImageType(const ossimString& imageType) const
std::vector< ossimRefPtr< ossimConnectableObject > > ConnectableObjectList
virtual ossimGpt lineSampleToWorld(const ossimDpt &projectedPoint) const
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual bool open()
virtual void setNumericType(ossimNumericPropertyType type)
yy_size_t size
bool exists() const
virtual void lineSampleToEastingNorthing(const ossimDpt &liineSample, ossimDpt &eastingNorthing) const
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
const ossimRefPtr< ossimXmlNode > getGdalOptions() const
bool toBool() const
String to numeric methods.
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual ossimString getProjectionName() const
Returns the projection name.
ossim_uint32 getNumberOfEntries() const
ossimString gdalOverviewTypeToString() const
unsigned int ossim_uint32
32 bit normalized floating point
ossimGdalOverviewType theGdalOverviewType
bool isInputDataIndexed()
Check input to see if it&#39;s indexed.
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
#define STATIC_TYPE_INFO(T)
Definition: ossimRtti.h:319
virtual bool writeBlockFile()
double toDouble() const
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
bool open(const ossimFilename &lutFile)
Reads in an external lut file.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void extractKeysThatMatch(ossimKeywordlist &kwl, const ossimString &regularExpression) const
void appendGdalOption(const ossimString &name, const ossimString &value, bool replaceFlag=true)
virtual ossimIrect getImageRectangle() const
ossimRefPtr< ossimNBandLutDataObject > theColorLut
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
T min(T a, T b)
Definition: ossimCommon.h:203
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
virtual bool hasImageType(const ossimString &imageType) const
bool hasImageType(const ossimString& imageType) const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
ossimString theDriverName
ossimScalarType
virtual const ossim_float64 * getMinPix() const
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
GDALDataType getGdalDataType(ossimScalarType scalar)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
bool isLutEnabled() const
64 bit normalized floating point
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
16 bit unsigned integer (11 bits used)
virtual void writeProjectionInfo(GDALDatasetH dataset)
This class defines an abstract Handler which all image handlers(loaders) should derive from...
virtual void setProperty(ossimRefPtr< ossimProperty > property)
void setDescription(const ossimString &description)
ossim_int32 y
Definition: ossimIpt.h:142
virtual void setWriteExternalGeometryFlag(bool flag)
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
void getImageTypeList(std::vector<ossimString>& imageTypeList)const
virtual const void * getBuf() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
double x
Definition: ossimDpt.h:164
ossim_uint32 getSize() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
class ossimNBandLutDataObject
static void getSupportedWriters(vector< ossimString > &writers)
virtual ossimIpt getTileSize() const
ossim_int32 x
Definition: ossimIpt.h:141
ossimGdalOverviewType gdalOverviewTypeFromString(const ossimString &typeString) const
char ** theGdalDriverOptions
8 bit unsigned integer
GDALDatasetH theDataset
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
virtual ossimDpt getMetersPerPixel() const
virtual void setTileSize(const ossimIpt &tileSize)
32 bit floating point
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Loads the state of the object by reading in the keywords listed in the save state.
16 bit unsigned iteger
64 bit floating point
16 bit signed integer
void postProcessOutput() const
Method called after good writeFile to clean up any unwanted files.
virtual bool setValue(const ossimString &value)=0
void allocateGdalDriverOptions()
bool validProperty(const ossimString &name) const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual void close()
8 bit unsigned iteger
const ossimString & getName() const
int ossim_int32
virtual bool hasLut() const