OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGdalDataset.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file
4 //
5 // Author: David Burken
6 //
7 // Description: A gdal data set from an ossim image handler.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
12 #include <ossimGdalDataset.h>
13 #include <ossimGdalType.h>
15 #include <ossim/base/ossimNotify.h>
16 #include <ossim/base/ossimTrace.h>
19 #include <fstream>
20 
21 static GDALDriver *poOssimGdalDriver = 0;
22 
23 static const ossimTrace traceDebug(ossimString("ossimGdalDataset:debug"));
24 
25 
26 CPL_C_START
28 CPL_C_END
29 
30 #ifdef OSSIM_ID_ENABLED
31 static const char OSSIM_ID[] = "$Id: ossimGdalDataset.cpp 23003 2014-11-24 17:13:40Z dburken $";
32 #endif
33 
35  : theImageHandler(0)
36 {
37  if (!poOssimGdalDriver)
38  {
40  poDriver = poOssimGdalDriver;
41  }
42 
43  if (traceDebug())
44  {
46  << "ossimGdalDataset::ossimGdalDataset entered..."
47  << std::endl;
48 #ifdef OSSIM_ID_ENABLED
50  << "OSSIM_ID: "
51  << OSSIM_ID
52  << std::endl;
53 #endif
54  }
55 }
56 
58 
59 {
60  if (traceDebug())
61  {
63  << "ossimGdalDataset::~ossimGdalDataset "
64  << "\n"
65  << std::endl;
66  }
67 
68  if (theImageHandler.valid())
69  theImageHandler = 0;
70 }
71 
73 {
75 
76  if ( !theImageHandler.valid() )
77  {
78  if (traceDebug())
79  {
81  << "ossimGdalDataset::open DEBUG:"
82  << "\nCould not open: " << file.c_str() << std::endl;
83  }
84  return false;
85  }
86 
87  if (traceDebug())
88  {
90  << "ossimGdalDataset::open DEBUG:"
91  << "\nOpened: " << file.c_str() << std::endl;
92  }
93 
94  init();
95  return true;
96 }
97 
98 
99 GDALDataset* ossimGdalDataset::Open( GDALOpenInfo * poOpenInfo )
100 
101 {
102  if (traceDebug())
103  {
105  << "ossimGdalDataset::Open entered..."
106  << std::endl;
107  }
108 
109  ossimFilename f = poOpenInfo->pszFilename;
110  GDALDataset* ds = new ossimGdalDataset;
111  if ( ((ossimGdalDataset*)ds)->open(f) == true)
112  {
113  return ds;
114  }
115 
116  return 0;
117 }
118 
120 {
121  if (traceDebug())
122  {
124  << "ossimGdalDataset::setImageHandler entered..."
125  << std::endl;
126  }
127 
128  theImageHandler = ih;
129  init();
130 }
131 
133 {
134  return theImageHandler.get();
135 }
136 
138 {
139  return theImageHandler.get();
140 }
141 
143 {
145  sDescription = f.c_str();
146 
147  if (theImageHandler.valid())
148  {
149  oOvManager.Initialize( this, f.c_str() );
150  }
151 }
152 
154 {
155  nRasterXSize = theImageHandler->getImageRectangle(0).width();
156  nRasterYSize = theImageHandler->getImageRectangle(0).height();
158  eAccess = GA_ReadOnly;
159 
160  if (traceDebug())
161  {
163  << "ossimGdalDataset::init DEBUG:"
164  << "\nWidth: " << nRasterXSize
165  << "\nHeight: " << nRasterYSize
166  << "\nBands: " << nBands << std::endl;
167  }
168 
169  for( int iBand = 0; iBand < nBands; ++iBand )
170  {
172  new ossimGdalDatasetRasterBand( this,
173  iBand+1,
174  theImageHandler.get());
175  SetBand( iBand+1, rb );
176  }
177 }
178 
179 void ossimGdalDataset::setGdalAcces(GDALAccess access)
180 {
181  eAccess = access;
182 }
183 
185  int band,
186  ossimImageHandler* ih)
187  : GDALPamRasterBand(),
188  theImageHandler(ih)
189 
190 {
191  if (traceDebug())
192  {
194  << "ossimGdalDatasetRasterBand::ossimGdalDatasetRasterBand entered..."
195  << "band: " << band
196  << std::endl;
197  }
198  if (!ih)
199  {
200  return;
201  }
202 
203  poDS = ds;
204  nBand = band;
205 
206  nRasterXSize = theImageHandler->getImageRectangle(0).width();
207  nRasterYSize = theImageHandler->getImageRectangle(0).height();
208 
209  // eAccess = GA_ReadOnly;
210  eAccess = GA_Update;
211 
212  ossimGdalType gt;
213  eDataType = gt.toGdal(theImageHandler->getOutputScalarType());
214 
215  nBlockXSize = theImageHandler->getTileWidth();
216  nBlockYSize = theImageHandler->getTileHeight();
217 
218  // ESH 06/2009: Prevent divide by zero.
219  nBlockXSize = (nBlockXSize==0) ? 1 : nBlockXSize;
220  nBlockYSize = (nBlockYSize==0) ? 1 : nBlockYSize;
221 
222  nBlocksPerRow = nRasterXSize / nBlockXSize;
223  nBlocksPerColumn = nRasterYSize / nBlockYSize;
224  if (nRasterXSize % nBlockXSize) ++nBlocksPerRow;
225  if (nRasterYSize % nBlockYSize) ++nBlocksPerColumn;
226 
227  nBlockReads = 0;
228  bForceCachedIO = false;
229 }
230 
232 {
233 }
234 
236  int nBlockYOff,
237  void * pImage )
238 {
239  if ( !theImageHandler.valid() || !pImage)
240  {
241  return CE_Failure;
242  }
243 
244  ossimIpt startPt(nBlockXOff*nBlockXSize, nBlockYOff*nBlockYSize);
245 // ossimIpt endPt( min(startPt.x+nBlockXSize-1, nRasterXSize-1),
246 // min(startPt.y+nBlockYSize-1, nRasterYSize-1));
247  ossimIpt endPt( startPt.x+nBlockXSize-1,
248  startPt.y+nBlockYSize-1);
249  ossimIrect rect( startPt, endPt);
250 
252 
253  if (id.valid())
254  {
255  if( (id->getDataObjectStatus() == OSSIM_FULL) ||
257  {
258  id->unloadBand(pImage, rect, nBand-1);
259  return CE_None;
260  }
261  }
262 
263  memset(pImage, 0, nBlockXSize * nBlockYSize);
264 
265  return CE_None;
266 }
267 
268 double ossimGdalDatasetRasterBand::GetNoDataValue( int * /* pbSuccess */)
269 
270 {
271  if (traceDebug())
272  {
274  << "ossimGdalDatasetRasterBand::GetNoDataValue entered..."
275  << "\n"
276  << std::endl;
277  }
278 
279  return 0.0;
280 }
281 
283 
284 {
285  GDALDriver *poDriver;
286 
287  if( poOssimGdalDriver == 0 )
288  {
289  poDriver = new GDALDriver();
290  poOssimGdalDriver = poDriver;
291 
292  poDriver->SetDescription( "ossimGdalDataset" );
293  poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
294  "ossim data set" );
295  poDriver->pfnOpen = ossimGdalDataset::Open;
296  GetGDALDriverManager()->RegisterDriver( poDriver );
297  }
298 }
void initGdalOverviewManager()
Calls gdal&#39;s oOvManager.Initialize.
void init()
Initializes this object from the image handler.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool valid() const
Definition: ossimRefPtr.h:75
static GDALDataset * Open(GDALOpenInfo *)
Open for static gdal driver.
void setImageHandler(ossimImageHandler *ih)
Sets theImageHandler.
ossim_uint32 height() const
Definition: ossimIrect.h:487
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
virtual ossimDataObjectStatus getDataObjectStatus() const
const ossimImageHandler * getImageHandler() const
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
virtual void unloadBand(void *dest, ossim_uint32 src_band, ossim_uint32 dest_band, const ossimIrect &dest_rect, ossimInterleaveType il_type=OSSIM_BSQ, OverwriteBandRule ow_type=NULL_RULE) const
This routine is designed for overwriting a selected band of the destination buffer &#39;dest&#39; by an indep...
void setGdalAcces(GDALAccess access)
Set the access data member.
virtual const ossimFilename & getFilename() const
Returns the filename.
ossimGdalDatasetRasterBand(ossimGdalDataset *ds, int band, ossimImageHandler *ih)
Constructor that takes a ossimGdalDataset, band and image handler.
virtual ~ossimGdalDataset()
virtual destructor
virtual ~ossimGdalDatasetRasterBand()
virtual destructor
ossimGdalDataset This is a gdal data set that wraps an ossim image handler.
virtual ossimIrect getImageRectangle(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimRefPtr< ossimImageHandler > theImageHandler
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage)
Read block method.
ossimGdalDatasetRasterBand Represents a single band within the image.
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
This class defines an abstract Handler which all image handlers(loaders) should derive from...
CPL_C_START void GDALRegister_ossimGdalDataset(void)
ossimGdalDataset()
default constructor
ossim_int32 y
Definition: ossimIpt.h:142
virtual double GetNoDataValue(int *pbSuccess=0)
This returns 0 right now and should probably be implemented if anything serious is to be done with th...
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
static ossimImageHandlerRegistry * instance()
ossimRefPtr< ossimImageHandler > theImageHandler
ossim_int32 x
Definition: ossimIpt.h:141
bool open(const ossimFilename &file)
open method.
GDALDataType toGdal(ossimScalarType) const
friend class ossimGdalDatasetRasterBand
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)