OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGpkgReader.cpp
Go to the documentation of this file.
1 //---
2 //
3 // File: ossimGpkgReader.cpp
4 //
5 // License: MIT
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 // Description: OSSIM GeoPackage reader (tile source).
10 //
11 //---
12 // $Id$
13 
14 #include "ossimGpkgReader.h"
16 #include "ossimGpkgTileRecord.h"
17 #include "ossimGpkgUtil.h"
18 
20 #include <ossim/base/ossimCommon.h>
22 #include <ossim/base/ossimDpt.h>
23 #include <ossim/base/ossimEndian.h>
24 #include <ossim/base/ossimGpt.h>
26 #include <ossim/base/ossimIpt.h>
27 #include <ossim/base/ossimIrect.h>
29 #include <ossim/base/ossimNotify.h>
32 #include <ossim/base/ossimTrace.h>
33 
39 
42 
43 #include <sqlite3.h>
44 
45 #include <cmath>
46 #include <sstream>
47 
48 RTTI_DEF1(ossimGpkgReader, "ossimGpkgReader", ossimImageHandler)
49 
50 #ifdef OSSIM_ID_ENABLED
51 static const char OSSIM_ID[] = "$Id$";
52 #endif
53 
54 static ossimTrace traceDebug("ossimGpkgReader:debug");
55 static ossimTrace traceValidate("ossimGpkgReader:validate");
56 
58  :
60  m_ih(0),
61  m_tile(0),
62  m_cacheTile(0),
63  m_db(0),
64  m_currentEntry(0),
65  m_bands(0),
66  m_scalar(OSSIM_SCALAR_UNKNOWN),
67  m_tileWidth(0),
68  m_tileHeight(0),
69  m_entries(0)
70 {
71  if (traceDebug())
72  {
74  << "ossimGpkgReader::ossimGpkgReader entered...\n";
75 #ifdef OSSIM_ID_ENABLED
77  << "OSSIM_ID: " << OSSIM_ID << "\n";
78 #endif
79  }
80 }
81 
83 {
84  if (isOpen())
85  {
86  close();
87  }
88 }
89 
91 {
93  m_tile->initialize();
94 }
95 
97  const ossimIrect& rect, ossim_uint32 resLevel)
98 {
99  if ( !m_tile )
100  {
101  allocate();
102  }
103 
104  if (m_tile.valid())
105  {
106  // Image rectangle must be set prior to calling getTile.
107  m_tile->setImageRectangle(rect);
108 
109  if ( getTile( m_tile.get(), resLevel ) == false )
110  {
112  {
113  m_tile->makeBlank();
114  }
115  }
116  }
117 
118  return m_tile;
119 }
120 
122  ossim_uint32 resLevel)
123 {
124  bool status = false;
125 
126  //---
127  // Not open, this tile source bypassed, or invalid res level,
128  // return a blank tile.
129  //---
130  if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel) &&
131  result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
132  {
133  result->ref(); // Increment ref count.
134 
135  if ( resLevel < getNumberOfZoomLevels() )
136  {
137  status = true;
138 
139  ossimIrect tileRect = result->getImageRectangle();
140  ossimIrect imageRect = getImageRectangle(resLevel);
141 
142  //---
143  // Format allows for missing tiles so alway make blank in case tile
144  // is not filled completely.
145  //---
146  m_tile->makeBlank();
147 
148  if ( imageRect.intersects(tileRect) )
149  {
150  // Make a clip rect.
151  ossimIrect clipRect = tileRect.clipToRect( imageRect );
152 
153  // This will validate the tile at the end.
154  fillTile(resLevel, tileRect, clipRect, result);
155  }
156  }
157  else
158  {
159  status = getOverviewTile(resLevel, result);
160  }
161 
162  result->unref(); // Decrement ref count.
163  }
164 
165  return status;
166 }
167 
169  const ossimIrect& tileRect,
170  const ossimIrect& clipRect,
171  ossimImageData* tile )
172 {
173  if ( tile )
174  {
175  // Get the tile indexes needed to fill the clipRect.
176  std::vector<ossimIpt> tileIndexes;
177  getTileIndexes( resLevel, clipRect, tileIndexes );
178 
179  std::vector<ossimIpt>::const_iterator i = tileIndexes.begin();
180  while ( i != tileIndexes.end() )
181  {
182  ossimRefPtr<ossimImageData> id = getTile( resLevel, (*i) );
183  if ( id.valid() )
184  {
185  ossimIrect tileClipRect = clipRect.clipToRect( id->getImageRectangle() );
186  id->unloadTile( tile->getBuf(), tileRect, tileClipRect, OSSIM_BSQ );
187  }
188  ++i;
189  }
190 
191  tile->validate();
192  }
193 }
194 
196  const ossimIrect& clipRect,
197  std::vector<ossimIpt>& tileIndexes ) const
198 {
199  ossimIpt tileSize;
200  getTileSize( resLevel, tileSize );
201 
202  if ( tileSize.x && tileSize.y )
203  {
204  ossimIrect expandedRect = clipRect;
205 
206  // Add the sub image offset if any:
207  ossimIpt subImageOffset(0,0);
208  if ( m_currentEntry < m_entries.size() )
209  {
210  m_entries[m_currentEntry].getSubImageOffset( resLevel, subImageOffset );
211  expandedRect += subImageOffset;
212  }
213 
214  expandedRect.stretchToTileBoundary( tileSize );
215 
216  ossim_int32 y = expandedRect.ul().y;
217  while ( y < expandedRect.lr().y )
218  {
219  ossim_int32 x = expandedRect.ul().x;
220  while ( x < expandedRect.lr().x )
221  {
222  ossimIpt index( x/tileSize.x, y/tileSize.y );
223  tileIndexes.push_back( index );
224  x += tileSize.x;
225  }
226  y += tileSize.y;
227  }
228  }
229 }
230 
231 void ossimGpkgReader::getTileSize( ossim_uint32 resLevel, ossimIpt& tileSize ) const
232 {
233  if ( m_currentEntry < (ossim_uint32)m_entries.size() )
234  {
235  if ( resLevel < (ossim_uint32)m_entries[m_currentEntry].getTileMatrix().size() )
236  {
237  tileSize.x =
238  (ossim_int32)m_entries[m_currentEntry].getTileMatrix()[resLevel].m_tile_width;
239  tileSize.y =
240  (ossim_int32)m_entries[m_currentEntry].getTileMatrix()[resLevel].m_tile_height;
241  }
242  }
243 }
244 
246 {
247  return ossimIrect(0,
248  0,
249  getNumberOfSamples(resLevel) - 1,
250  getNumberOfLines(resLevel) - 1);
251 }
252 
254  const char* prefix) const
255 {
256  return ossimImageHandler::saveState(kwl, prefix);
257 }
258 
260  const char* prefix)
261 {
262  bool result = false;
263  if (ossimImageHandler::loadState(kwl, prefix))
264  {
265  result = open();
266  }
267  return result;
268 }
269 
271 {
273 }
274 
276 {
278  prop = ossimImageHandler::getProperty(name);
279  return prop;
280 }
281 
282 void ossimGpkgReader::getPropertyNames(std::vector<ossimString>& propertyNames)const
283 {
285 }
286 
288 {
289  static const char M[] = "ossimGpkgReader::open";
290 
291  bool status = false;
292 
293  if (traceDebug())
294  {
296  << M << " entered..." << "\nFile: " << theImageFile.c_str() << "\n";
297  }
298 
299  // Start with a clean slate.
300  if (isOpen())
301  {
302  close();
303  }
304 
305  std::ifstream str;
306  str.open(theImageFile.c_str(), std::ios_base::in | std::ios_base::binary);
307 
308  if ( ossim_gpkg::checkSignature( str ) )
309  {
310  if ( ossim_gpkg::checkApplicationId( str ) == false )
311  {
312  // Just issue a warning at this point as this requirement is new...
313  if (traceDebug())
314  {
316  << M << " WARNING!"
317  << "File: " << theImageFile << " does not have required application_id!"
318  << "\nProceeding anyway...\n";
319  }
320  }
321 
322  int rc = sqlite3_open_v2( theImageFile.c_str(), &m_db, SQLITE_OPEN_READONLY, 0);
323  if ( rc == SQLITE_OK )
324  {
325  m_entries.clear();
327 
328  if ( m_entries.size() )
329  {
331 
332  if (traceDebug())
333  {
334  std::vector<ossimGpkgTileEntry>::const_iterator i = m_entries.begin();
335  while ( i != m_entries.end() )
336  {
337  ossimNotify(ossimNotifyLevel_DEBUG) << (*i) << "\n";
338  ++i;
339  }
340  }
341  if (traceValidate())
342  {
343  std::vector<ossimGpkgTileEntry>::const_iterator i = m_entries.begin();
344  while ( i != m_entries.end() )
345  {
346  (*i).printValidate( ossimNotify(ossimNotifyLevel_DEBUG) );
347  ++i;
348  }
349  }
350  }
351 
352  }
353  }
354 
355  if ( !status )
356  {
357  close();
358  }
359  else
360  {
361  completeOpen();
362  }
363  if (traceDebug())
364  {
366  << M << " exit status: " << (status?"true":"false") << "\n";
367  }
368 
369  return status;
370 }
371 
373 {
374  ossim_uint32 result = getImageTileWidth();
375  if (!result)
376  {
377  ossimIpt tileSize;
378  ossim::defaultTileSize(tileSize);
379  result = tileSize.x;
380  }
381  return result;
382 }
383 
385 {
386  ossim_uint32 result = getImageTileHeight();
387  if (!result)
388  {
389  ossimIpt tileSize;
390  ossim::defaultTileSize(tileSize);
391  result = tileSize.y;
392  }
393  return result;
394 }
395 
397 {
398  ossim_uint32 result = 0;
399  if ( m_currentEntry < m_entries.size() )
400  {
401  if ( resLevel < m_entries[m_currentEntry].getTileMatrix().size() )
402  {
403  result = m_entries[m_currentEntry].getNumberOfLines( resLevel );
404  }
405  else if ( theOverview.valid() )
406  {
407  result = theOverview->getNumberOfLines(resLevel);
408  }
409  }
410  return result;
411 }
412 
414 {
415  ossim_uint32 result = 0;
416  if ( m_currentEntry < m_entries.size() )
417  {
418  if ( resLevel < m_entries[m_currentEntry].getTileMatrix().size() )
419  {
420  result = m_entries[m_currentEntry].getNumberOfSamples( resLevel );
421  }
422  else if ( theOverview.valid() )
423  {
424  result = theOverview->getNumberOfSamples(resLevel);
425  }
426  }
427  return result;
428 }
430 {
431  return m_tileWidth;
432 }
433 
435 {
436  return m_tileHeight;
437 }
438 
440 {
441  return ossimString("ossim_gpkg_reader");
442 }
443 
445 {
446  return ossimString("ossim Geo Package reader");
447 }
448 
450 {
451  return ossimString("ossimGpkgReader");
452 }
453 
455 {
456  return m_bands;
457 }
458 
460 {
461  return m_bands;
462 }
463 
465 {
466  return m_scalar;
467 }
468 
470 {
471  return (m_db != 0 );
472 }
473 
475 {
476  if ( isOpen() )
477  {
479  }
480  if ( m_db )
481  {
482  sqlite3_close( m_db );
483  m_db = 0;
484  }
485  m_entries.clear();
486 }
487 
489 {
490  return (ossim_uint32)m_entries.size();
491 }
492 
494 {
495  return m_currentEntry;
496 }
497 
498 void ossimGpkgReader::getEntryList(std::vector<ossim_uint32>& entryList)const
499 {
500  for ( ossim_uint32 i = 0; i < m_entries.size(); ++i )
501  {
502  entryList.push_back(i);
503  }
504 }
505 
506 void ossimGpkgReader::getEntryNames(std::vector<ossimString>& entryNames) const
507 {
508  std::vector<ossimGpkgTileEntry>::const_iterator i = m_entries.begin();
509  while ( i != m_entries.end() )
510  {
511  entryNames.push_back( ossimString((*i).getTileMatrixSet().m_table_name) );
512  ++i;
513  }
514 }
515 
517 {
518  bool result = true;
519  if ( m_currentEntry != entryIdx )
520  {
521  if ( entryIdx < getNumberOfEntries() )
522  {
523  m_currentEntry = entryIdx;
524 
525  if ( isOpen() )
526  {
527  // Zero out the tile to force an allocate() call.
528  m_tile = 0;
529 
530  // Clear the geometry.
531  theGeometry = 0;
532 
533  // Must clear or openOverview will use last entries.
535 
536  // This intitializes bands, scalar, tile width, height...
537  initImageParams();
538 
539  if ( result )
540  {
541  completeOpen();
542  }
543  }
544  }
545  else
546  {
547  result = false; // Entry index out of range.
548  }
549  }
550  return result;
551 }
552 
554 {
555  // Internal overviews.
557 
558  if (theOverview.valid())
559  {
560  // Add external overviews.
562  }
563 
564  return result;
565 }
566 
568 {
569  ossim_uint32 result = 0;
570 
571  //---
572  // Index 0 is the highest zoom_level which is the best resolution or r0 in ossim terms.
573  // In GeoPackage zoom_level 0 is the lowest resolution.
574  //---
575  if ( m_currentEntry < (ossim_uint32)m_entries.size())
576  {
577  size_t matrixSize = m_entries[m_currentEntry].getTileMatrix().size();
578  if ( matrixSize )
579  {
580  result =
581  m_entries[m_currentEntry].getTileMatrix()[0].m_zoom_level -
582  m_entries[m_currentEntry].getTileMatrix()[ matrixSize-1 ].m_zoom_level + 1;
583  }
584  }
585 
586  return result;
587 }
588 
590 {
591  if ( !theGeometry )
592  {
593  //---
594  // Check for external geom - this is a file.geom not to be confused with
595  // geometries picked up from dot.xml, dot.prj, dot.j2w and so on. We
596  // will check for that later if the getInternalImageGeometry fails.
597  //---
599 
600  if ( !theGeometry )
601  {
602  // Check the internal geometry first to avoid a factory call.
604 
605  //---
606  // WARNING:
607  // Must create/set the geometry at this point or the next call to
608  // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
609  // as it does a recursive call back to ossimImageHandler::getImageGeometry().
610  //---
611  if ( !theGeometry )
612  {
614  }
615 
616  // Check for set projection.
617  if ( !theGeometry->getProjection() )
618  {
619  // Last try factories for projection.
621  }
622  }
623 
624  // Set image things the geometry object should know about.
626 
627  if (traceDebug())
628  {
630  << "ossimGpkgReader::getImageGeometry geometry:\n"
631  << *(theGeometry.get()) << "\n";
632  }
633 
634  }
635  return theGeometry;
636 
637 } // End: ossimGpkgReader::getImageGeometry()
638 
640 {
641  static const char M[] = "ossimGpkgReader::getInternalImageGeometry";
642 
644  if (traceDebug())
645  {
646  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
647  }
648 
649  if ( m_currentEntry < m_entries.size() )
650  {
651  ossimRefPtr<ossimMapProjection> mapProj = m_entries[m_currentEntry].getNewMapProjection();
652 
653  if ( mapProj.valid() )
654  {
655  ossimRefPtr<ossimProjection> proj = mapProj.get();
656  if ( proj.valid() )
657  {
658  // Create and assign projection to our ossimImageGeometry object.
659  geom = new ossimImageGeometry();
660  geom->setProjection( proj.get() );
661  if (traceDebug())
662  {
663  ossimNotify(ossimNotifyLevel_DEBUG) << "Created geometry...\n";
664  }
665  }
666  }
667  }
668 
669  if (traceDebug())
670  {
671  if ( geom.valid() )
672  {
673  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exited...\n";
674  }
675  }
676 
677  return geom;
678 
679 } // End: ossimGpkgReader::getInternalImageGeometry()
680 
682 {
683  static const char MODULE[] = "ossimGpkgReader::initImageParams";
684  if (traceDebug())
685  {
686  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
687  }
688 
689  bool result = false;
690  if ( m_db )
691  {
692  if ( m_currentEntry < m_entries.size() )
693  {
694  if ( m_entries[m_currentEntry].getTileMatrix().size() )
695  {
696  ossimIpt index(-1,-1);
697 
698  std::string tableName = m_entries[m_currentEntry].getTileMatrix()[0].m_table_name;
699  ossim_int32 zoomLevel = m_entries[m_currentEntry].getTileMatrix()[0].m_zoom_level;
700 
701  // Get the first tile for the highest res zoom level.
702 
703  const char *zLeftover; // Tail of unprocessed SQL
704  sqlite3_stmt *pStmt = 0; // The current SQL statement
705 
706  std::ostringstream sql;
707  sql << "SELECT min(id), tile_column, tile_row from "
708  << tableName << " WHERE zoom_level=" << zoomLevel;
709 
710  if (traceDebug())
711  {
713  << "sql:\n" << sql.str() << "\n";
714  }
715 
716  int rc = sqlite3_prepare_v2(m_db, // Database handle
717  sql.str().c_str(),// SQL statement, UTF-8 encoded
718  -1, // Maximum length of zSql in bytes.
719  &pStmt, // OUT: Statement handle
720  &zLeftover); // OUT: Pointer to unused portion of zSql
721  if ( rc == SQLITE_OK )
722  {
723  int nCol = sqlite3_column_count( pStmt );
724  if ( nCol == 3 )
725  {
726  // Read the row:
727  rc = sqlite3_step(pStmt);
728  if ( rc == SQLITE_ROW )
729  {
730  index.x = sqlite3_column_int(pStmt, 1);
731  index.y = sqlite3_column_int(pStmt, 2);
732  }
733  }
734  }
735 
736  sqlite3_finalize(pStmt);
737 
738  if ( (index.x > -1) && (index.y > -1) )
739  {
740  // Grab a tile:
741  ossimRefPtr<ossimImageData> tile = getTile( 0, index );
742  if ( tile.valid() )
743  {
744  // Set the bands:
745  m_bands = tile->getNumberOfBands();
746 
747  // Set the scalar type:
748  m_scalar = tile->getScalarType();
749 
750  // Set tile size:
751  m_tileWidth = tile->getWidth();
752  m_tileHeight = tile->getHeight();
753  result = true;
754  }
755  }
756 
757  if ( !result )
758  {
759  // Set to some default:
760  m_bands = 3;
762  m_tileWidth = 256;
763  m_tileHeight = 256;
764  result = true;
765  }
766  }
767  }
768  }
769 
770  if ( traceDebug() )
771  {
773  << MODULE << " exit status = " << (result?"true":"false") << "\n";
774  }
775 
776  return result;
777 }
778 
780  ossimIpt index)
781 {
782  static const char MODULE[] = "ossimGpkgReader::getTile(resLevel, index)";
783  if (traceDebug())
784  {
786  << MODULE << " entered..."
787  << "\nresLevel: " << resLevel << " index: " << index << "\n";
788  }
789 
790  ossimRefPtr<ossimImageData> result = 0;
791 
792  if ( m_db )
793  {
794  if ( m_currentEntry < m_entries.size() )
795  {
796  if ( resLevel < m_entries[m_currentEntry].getTileMatrix().size() )
797  {
798  std::string tableName =
799  m_entries[m_currentEntry].getTileMatrix()[resLevel].m_table_name;
800  ossim_int32 zoomLevel =
801  m_entries[m_currentEntry].getTileMatrix()[resLevel].m_zoom_level;
802  const char *zLeftover; // Tail of unprocessed SQL
803  sqlite3_stmt *pStmt = 0; // The current SQL statement
804  std::ostringstream sql;
805  sql << "SELECT id, zoom_level, tile_column, tile_row, tile_data from "
806  << tableName
807  << " WHERE zoom_level=" << zoomLevel
808  << " AND tile_column=" << index.x
809  << " AND tile_row=" << index.y;
810 
811  if (traceDebug())
812  {
814  << MODULE << " sql:\n" << sql.str() << "\n";
815  }
816 
817  int rc = sqlite3_prepare_v2(
818  m_db, // Database handle
819  sql.str().c_str(),// SQL statement, UTF-8 encoded
820  -1, // Maximum length of zSql in bytes.
821  &pStmt, // OUT: Statement handle
822  &zLeftover); // OUT: Pointer to unused portion of zSql
823  if ( rc == SQLITE_OK )
824  {
825  int nCol = sqlite3_column_count( pStmt );
826  if ( nCol )
827  {
828  // Read the row:
829  rc = sqlite3_step(pStmt);
830  if (rc == SQLITE_ROW) // || (rc == SQLITE_DONE) )
831  {
832  ossimGpkgTileRecord tile;
833  tile.setCopyTileFlag(true);
834  if (tile.init( pStmt ) )
835  {
836  ossimIpt tileSize;
837  m_entries[m_currentEntry].getTileMatrix()[resLevel].getTileSize(tileSize);
839  switch ( tile.getTileType() )
840  {
842  {
843  // we need to cache this instead of allocating a new codec every tile
844  // for now just getting it to compile with registry implementation
845  //
846  if( !m_jpegCodec.valid() )
847  {
849  createCodec(ossimString("jpeg"));
850  }
851 
852  codec = m_jpegCodec.get();
853  break;
854  }
856  {
857  if( !m_pngCodec.valid() )
858  {
860  createCodec(ossimString("png"));
861  }
862  codec = m_pngCodec.get();
863  break;
864  }
865  default:
866  {
867  if (traceDebug())
868  {
870  << "Unhandled type: " << tile.getTileType() << endl;;
871  }
872  result = 0;
873  break;
874  }
875  }
876 
877  if ( codec.valid() )
878  {
879  if ( codec->decode(tile.m_tile_data, m_cacheTile ) )
880  {
881  result = m_cacheTile;
882  }
883  else
884  {
886  << "WARNING: decode failed...\n";
887  }
888  }
889 
890  if ( result.valid() )
891  {
892  // Set the tile origin in image space.
893  ossimIpt origin( index.x*tileSize.x,
894  index.y*tileSize.y );
895 
896  // Subtract the sub image offset if any:
897  ossimIpt subImageOffset(0,0);
898  m_entries[m_currentEntry].getSubImageOffset( resLevel, subImageOffset );
899  origin -= subImageOffset;
900 
901  result->setOrigin( origin );
902  }
903  else if (traceDebug())
904  {
906  << MODULE << " WARNING: result is null!\n";
907  }
908  }
909  }
910 
911  } // Matches: if ( nCol )
912 
913  } // Matches: if ( rc == SQLITE_OK )
914 
915  sqlite3_finalize(pStmt);
916 
917  } // Matches: if(resLevel<m_entries[m_currentEntry].getTileMatrix().size())
918 
919  } // Matches: if ( m_currentEntry < m_entries.size() )
920 
921  } // Matches: if ( m_db )
922 
923  if (traceDebug())
924  {
926  << MODULE << " exit result is " << (result.valid()?"set.":"null.") << "\n";
927  }
928 
929  return result;
930 
931 } // End: ossimGpkgReader::getTile( resLevel, index )
932 
934  const ossimIpt& tileSize )
935 {
936  ossimRefPtr<ossimImageData> result = 0;
937 
938  //---
939  // This copies the data to a stringbuf. TODO, use tile data
940  // directly.
941  //---
942  if ( tile.m_tile_data.size() )
943  {
944  std::string data( (char*)&tile.m_tile_data.front(),
945  tile.m_tile_data.size() );
946 
947  // ossim::istringstream is(data);
948  std::shared_ptr<ossim::istream> is;
949 
950  std::shared_ptr<ossim::istringstream> testIs =
951  std::make_shared<ossim::istringstream>();
952  testIs->str( data );
953  is = testIs;
954  if ( m_ih.valid() )
955  {
956  // Have an image handler from previous open:
958  dynamic_cast<ossimStreamReaderInterface*>( m_ih.get() );
959  if ( sri )
960  {
961  // if ( sri->open( &is, 0, false ) == false )
962  if ( sri->open( is, std::string("gpkg_tile")) == false )
963  {
964  // Per the spec tile mime types can be mixed.
965  m_ih = 0;
966  }
967  }
968  else
969  {
970  m_ih = 0;
971  }
972  }
973 
974  if ( !m_ih )
975  {
976  // m_ih = ossimImageHandlerRegistry::instance()->open( &is, 0, false );
977  m_ih = ossimImageHandlerRegistry::instance()->open( is, std::string("gpkg_tile"), false );
978  }
979 
980  if ( m_ih.valid() )
981  {
982  // Get the raw rectangle:
983  ossimIrect rect( 0, 0, tileSize.x - 1, tileSize.y - 1 );
984 
985  // Get the tile from the image handler:
986  result = m_ih->getTile( rect, 0 );
987  }
988  }
989 
990  return result;
991 
992 } // ossimGpkgReader::uncompressPngTile
993 
995 {
996  if ( m_currentEntry < m_entries.size() )
997  {
998  m_entries[m_currentEntry].getGsd( 0, gsd );
999  }
1000 
1001  if (traceDebug())
1002  {
1004  << "ossimGpkgReader::computeGsd DEBUG:\ngsd: " << gsd << "\n";
1005  }
1006 
1007 } // End: ossimGpkgReader::computeGsd
static ossimCodecFactoryRegistry * instance()
void getTileIndexes(ossim_uint32 resLevel, const ossimIrect &clipRect, std::vector< ossimIpt > &tileIndexes) const
void clear()
Erases the entire container.
Definition: ossimString.h:432
virtual ossim_uint32 getWidth() const
ossim_uint32 m_tileWidth
ossim_uint32 x
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
static ossimImageGeometryRegistry * instance()
virtual ossim_uint32 getImageTileWidth() const
Returns the tile width of the image or 0 if the image is not tiled.
ossimRefPtr< ossimImageGeometry > theGeometry
ossim_uint32 m_tileHeight
ossimRefPtr< ossimImageHandler > m_ih
void setProjection(ossimProjection *projection)
Sets the projection to be used for local-to-world coordinate transformation.
ossimRefPtr< ossimImageData > uncompressPngTile(const ossimGpkgTileRecord &tile, const ossimIpt &tileSize)
Uncompresses png tile to m_cacheTile.
virtual ossimString getClassName() const
void getTileEntries(sqlite3 *db, std::vector< ossimGpkgTileEntry > &entries)
Gets all the tile entries.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual ossim_uint32 getNumberOfBands() const
bool checkApplicationId(std::istream &in)
Check application_id.
ossimFilename theImageFile
virtual void setImageRectangle(const ossimIrect &rect)
ossim_uint32 m_currentEntry
std::vector< ossim_uint8 > m_tile_data
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
Represents serializable keyword/value map.
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const
Returns the number of lines in the image.
ossim_uint32 y
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool open()
open method.
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
bool init(sqlite3_stmt *pStmt)
Initialize from database.
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
Get propterty method.
void allocate()
Allocates m_tile.
OSSIM_DLL void defaultTileSize(ossimIpt &tileSize)
const ossimIpt & ul() const
Definition: ossimIrect.h:274
void computeGsd(ossimDpt &gsd) const
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual ossim_uint32 getNumberOfDecimationLevels() const
Returns the number of decimation levels.
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimString getLongName() const
void fillTile(ossim_uint32 resLevel, const ossimIrect &tileRect, const ossimIrect &clipRect, ossimImageData *tile)
virtual bool extendGeometry(ossimImageHandler *handler) const
virtual void getEntryNames(std::vector< ossimString > &entryNames) const
Get the list of entry names.
void ref() const
increment the reference count by one, indicating that this object has another pointer which is refere...
virtual void initialize()
Initialize the data buffer.
virtual ossim_uint32 getImageTileHeight() const
Returns the tile width of the image or 0 if the image is not tiled.
virtual ossim_uint32 getNumberOfDecimationLevels() const
This returns the total number of decimation levels.
virtual bool isValidRLevel(ossim_uint32 resLevel) const
Determines if the passed in reslution level is valid.
virtual ossim_uint32 getTileWidth() const
Returns the width of the output tile.
virtual void close()
Close method.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool checkSignature(std::istream &in)
Check signature method.
ossimRefPtr< ossimCodecBase > m_jpegCodec
virtual bool getOverviewTile(ossim_uint32 resLevel, ossimImageData *result)
Method to get an overview tile.
static ossimImageDataFactory * instance()
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossim_uint32 getNumberOfZoomLevels() const
virtual ossimDataObjectStatus validate() const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
Returns a pointer to a tile given an origin representing the upper left corner of the tile to grab fr...
unsigned int ossim_uint32
virtual ossimScalarType getOutputScalarType() const
Returns the output pixel type of the tile source.
virtual bool decode(const std::vector< ossim_uint8 > &in, ossimRefPtr< ossimImageData > &out) const =0
Decode method.
virtual void getEntryList(std::vector< ossim_uint32 > &entryList) const
Gets the entry list.
virtual ossimIrect getImageRectangle() const
std::vector< ossimGpkgTileEntry > m_entries
ossimRefPtr< ossimImageData > m_tile
virtual ossim_uint32 getCurrentEntry() const
const ossimIpt & lr() const
Definition: ossimIrect.h:276
virtual void close()
Deletes the overview and clears the valid image vertices.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
virtual ~ossimGpkgReader()
virtual destructor
virtual ossim_uint32 getTileHeight() const
Returns the height of the output tile.
void initImageParameters(ossimImageGeometry *geom) const
Convenience method to set things needed in the image geometry from the image handler.
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
virtual ossimIrect getImageRectangle(ossim_uint32 resLevel=0) const
Returns the zero based image rectangle for the reduced resolution data set (rrds) passed in...
virtual ossim_uint32 getNumberOfEntries() const
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
ossimScalarType
void unref() const
decrement the reference count by one, indicating that a pointer to this object is referencing it...
virtual void setOrigin(const ossimIpt &origin)
virtual ossimString getShortName() const
virtual ossimRefPtr< ossimImageGeometry > getExternalImageGeometry() const
Returns the image geometry object associated with this tile source or NULL if non defined...
return status
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
virtual void completeOpen()
Will complete the opening process.
virtual bool setCurrentEntry(ossim_uint32 entryIdx)
ossimRefPtr< ossimImageHandler > theOverview
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Get propterty names.
bool isOpen() const
Derived classes must implement this method to be concrete.
This class defines an abstract Handler which all image handlers(loaders) should derive from...
virtual ossimRefPtr< ossimImageGeometry > getInternalImageGeometry()
ossim_int32 y
Definition: ossimIpt.h:142
virtual const void * getBuf() const
virtual bool open(std::shared_ptr< ossim::istream > &str, const std::string &connectionString)=0
Pure virtual open method that takes a stream.
ossimRefPtr< ossimImageData > m_cacheTile
ossimGpkgTileType getTileType() const
ossimRefPtr< ossimCodecBase > m_pngCodec
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
void stretchToTileBoundary(const ossimIpt &tileWidthHeight)
Definition: ossimIrect.cpp:212
ossimFilename theOverviewFile
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
static ossimImageHandlerRegistry * instance()
ossim_int32 x
Definition: ossimIpt.h:141
ossimGpkgReader()
default constructor
8 bit unsigned integer
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
void setCopyTileFlag(bool flag)
void getTileSize(ossim_uint32 resLevel, ossimIpt &tileSize) const
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const
Returns the number of samples in the image.
virtual ossim_uint32 getNumberOfInputBands() const
Returns the number of bands in the image.
ossimScalarType m_scalar
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Set propterty method.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
ossim_uint32 m_bands