OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
ossimGpkgTileRecord Class Reference

#include <ossimGpkgTileRecord.h>

Public Types

enum  ossimGpkgTileType { OSSIM_GPKG_UNKNOWN = 0, OSSIM_GPKG_JPEG = 1, OSSIM_GPKG_PNG = 2 }
 

Public Member Functions

 ossimGpkgTileRecord ()
 default constructor More...
 
 ossimGpkgTileRecord (const ossimGpkgTileRecord &obj)
 
const ossimGpkgTileRecordoperator= (const ossimGpkgTileRecord &obj)
 
 ~ossimGpkgTileRecord ()
 destructor More...
 
bool init (sqlite3_stmt *pStmt)
 Initialize from database. More...
 
void setCopyTileFlag (bool flag)
 
std::ostream & print (std::ostream &out) const
 Print method. More...
 
void getTileIndex (ossimIpt &index) const
 Get tile index. More...
 
ossimGpkgTileType getTileType () const
 
std::string getTileMediaType () const
 

Static Public Member Functions

static bool createTable (sqlite3 *db, const std::string &tableName)
 Creates table in database. More...
 

Public Attributes

ossim_int32 m_id
 
ossim_int32 m_zoom_level
 
ossim_int32 m_tile_column
 
ossim_int32 m_tile_row
 
std::vector< ossim_uint8m_tile_data
 
bool m_copy_tile_flag
 

Friends

std::ostream & operator<< (std::ostream &out, const ossimGpkgTileRecord &obj)
 Convenience operator << function. More...
 

Detailed Description

Definition at line 25 of file ossimGpkgTileRecord.h.

Member Enumeration Documentation

◆ ossimGpkgTileType

Enumerator
OSSIM_GPKG_UNKNOWN 
OSSIM_GPKG_JPEG 
OSSIM_GPKG_PNG 

Definition at line 29 of file ossimGpkgTileRecord.h.

Constructor & Destructor Documentation

◆ ossimGpkgTileRecord() [1/2]

ossimGpkgTileRecord::ossimGpkgTileRecord ( )

default constructor

Definition at line 23 of file ossimGpkgTileRecord.cpp.

24  :
25  m_id(0),
26  m_zoom_level(0),
27  m_tile_column(0),
28  m_tile_row(0),
29  m_tile_data(0),
30  m_copy_tile_flag(true)
31 {
32 }
std::vector< ossim_uint8 > m_tile_data

◆ ossimGpkgTileRecord() [2/2]

ossimGpkgTileRecord::ossimGpkgTileRecord ( const ossimGpkgTileRecord obj)

Definition at line 34 of file ossimGpkgTileRecord.cpp.

35  :
36  m_id(obj.m_id),
42 {
43 }
std::vector< ossim_uint8 > m_tile_data

◆ ~ossimGpkgTileRecord()

ossimGpkgTileRecord::~ossimGpkgTileRecord ( )

destructor

Definition at line 60 of file ossimGpkgTileRecord.cpp.

61 {
62 }

Member Function Documentation

◆ createTable()

bool ossimGpkgTileRecord::createTable ( sqlite3 *  db,
const std::string &  tableName 
)
static

Creates table in database.

Parameters
db
tableNamee.g. "tiles", "map_tiles"
Returns
true on success, false on error.

Definition at line 190 of file ossimGpkgTileRecord.cpp.

References ossim_sqlite::exec(), status, and ossim_sqlite::tableExists().

Referenced by ossimGpkgWriter::createTables().

191 {
192  bool status = false;
193  if ( db )
194  {
195  status = ossim_sqlite::tableExists( db, tableName );
196  if ( !status )
197  {
198  std::ostringstream sql;
199  sql << "CREATE TABLE " << tableName << " ( "
200  << "id INTEGER PRIMARY KEY AUTOINCREMENT, "
201  << "zoom_level INTEGER NOT NULL, "
202  << "tile_column INTEGER NOT NULL, "
203  << "tile_row INTEGER NOT NULL, "
204  << "tile_data BLOB NOT NULL, "
205  << "UNIQUE (zoom_level, tile_column, tile_row) "
206  << ")";
207 
208  if ( ossim_sqlite::exec( db, sql.str() ) == SQLITE_DONE )
209  {
210  status = true;
211  }
212  }
213  }
214  return status;
215 }
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
int exec(sqlite3 *db, const std::string &sql)
Preforms sqlite3_prepare_v2, sqlite3_step and sqlite3_finalize.
bool tableExists(sqlite3 *db, const std::string &tableName)
Checks for existance of table.
return status

◆ getTileIndex()

void ossimGpkgTileRecord::getTileIndex ( ossimIpt index) const

Get tile index.

Parameters
sizeInitializes with tile_column and tile_row.

Definition at line 254 of file ossimGpkgTileRecord.cpp.

References m_tile_column, m_tile_row, ossimIpt::x, and ossimIpt::y.

255 {
256  index.x = m_tile_column;
257  index.y = m_tile_row;
258 }
ossim_int32 y
Definition: ossimIpt.h:142
ossim_int32 x
Definition: ossimIpt.h:141

◆ getTileMediaType()

std::string ossimGpkgTileRecord::getTileMediaType ( ) const
Returns
Tile media type from signature block. e.g. "image/png"

Definition at line 310 of file ossimGpkgTileRecord.cpp.

References getTileType(), OSSIM_GPKG_JPEG, and OSSIM_GPKG_PNG.

Referenced by print().

311 {
312  std::string result;
313  switch ( getTileType() )
314  {
316  {
317  result = "image/jpeg";
318  break;
319  }
321  {
322  result = "image/png";
323  break;
324  }
325  default:
326  {
327  result = "unknown";
328  break;
329  }
330  }
331  return result;
332 }
ossimGpkgTileType getTileType() const

◆ getTileType()

ossimGpkgTileRecord::ossimGpkgTileType ossimGpkgTileRecord::getTileType ( ) const
Returns
Tile type from signature block.

Definition at line 260 of file ossimGpkgTileRecord.cpp.

References m_tile_data, OSSIM_GPKG_JPEG, OSSIM_GPKG_PNG, and OSSIM_GPKG_UNKNOWN.

Referenced by getTileMediaType(), and init().

261 {
263 
264  if ( m_tile_data.size() > 7 )
265  {
266  if ( (m_tile_data[0] == 0xff) &&
267  (m_tile_data[1] == 0xd8) &&
268  (m_tile_data[2] == 0xff) )
269  {
270  if ( (m_tile_data[3] == 0xe0) || (m_tile_data[3] == 0xdb) )
271  {
273  }
274  }
275  else if ( ( m_tile_data[0] == 0x89 ) &&
276  ( m_tile_data[1] == 0x50 ) &&
277  ( m_tile_data[2] == 0x4e ) &&
278  ( m_tile_data[3] == 0x47 ) &&
279  ( m_tile_data[4] == 0x0d ) &&
280  ( m_tile_data[5] == 0x0a ) &&
281  ( m_tile_data[6] == 0x1a ) &&
282  ( m_tile_data[7] == 0x0a ) )
283  {
285  }
286 
287 #if 0 /* Please keep for debug. (drb) */
289  {
290  static bool traced = false;
291  if ( !traced )
292  {
294  {
295  for ( int i = 0; i < 8; ++i )
296  {
297  std::cout << std::hex << int(m_tile_data[i]) << " ";
298  }
299  std::cout << std::dec << "\n";
300  traced = true;
301  }
302  }
303  }
304 #endif
305  }
306 
307  return result;
308 }
std::vector< ossim_uint8 > m_tile_data

◆ init()

bool ossimGpkgTileRecord::init ( sqlite3_stmt *  pStmt)

Initialize from database.

Parameters
pStmtSQL statement, i.e. result of sqlite3_prepare_v2(...) call.

Definition at line 64 of file ossimGpkgTileRecord.cpp.

References getTileType(), m_copy_tile_flag, m_id, m_tile_column, m_tile_data, m_tile_row, m_zoom_level, OSSIM_GPKG_JPEG, OSSIM_GPKG_PNG, ossimNotify(), ossimNotifyLevel_WARN, and status.

Referenced by ossim_gpkg::printTiles().

65 {
66  static const char M[] = "ossimGpkgTileRecord::init";
67 
68  bool status = false;
69 
70  if ( pStmt )
71  {
72  const ossim_int32 EXPECTED_COLUMNS = 5;
73  ossim_int32 nCol = sqlite3_column_count( pStmt );
74 
75  if ( nCol != EXPECTED_COLUMNS )
76  {
78  << M << " WARNING:\nUnexpected number of columns: " << nCol
79  << "Expected column count: " << EXPECTED_COLUMNS
80  << std::endl;
81  }
82 
83  if ( nCol >= EXPECTED_COLUMNS )
84  {
85  ossim_int32 columnsFound = 0;
86  ossim_int32 type = 0;
87  std::string colName;
88 
89  for ( ossim_int32 i = 0; i < nCol; ++i )
90  {
91  colName = sqlite3_column_name(pStmt, i);
92  type = sqlite3_column_type(pStmt, i);
93 
94  if ( colName.size() )
95  {
96  if ( ( colName == "id" ) && ( type == SQLITE_INTEGER ) )
97  {
98  m_id = sqlite3_column_int(pStmt, i);
99  ++columnsFound;
100  }
101  else if ( ( colName == "zoom_level" ) && ( type == SQLITE_INTEGER ) )
102  {
103  m_zoom_level = sqlite3_column_int(pStmt, i);
104  ++columnsFound;
105  }
106  else if ( ( colName == "tile_column" ) && ( type == SQLITE_INTEGER ) )
107  {
108  m_tile_column = sqlite3_column_int(pStmt, i);
109  ++columnsFound;
110  }
111  else if ( ( colName == "tile_row" ) && ( type == SQLITE_INTEGER ) )
112  {
113  m_tile_row = sqlite3_column_int(pStmt, i);
114  ++columnsFound;
115  }
116  else if ( ( colName == "tile_data" ) && ( type == SQLITE_BLOB ) )
117  {
118  ++columnsFound;
119 
120  if ( m_copy_tile_flag )
121  {
122  ossim_int32 bytes = sqlite3_column_bytes( pStmt, i );
123  if ( bytes )
124  {
125  //---
126  // Copy the tile data as it will go away on the next:
127  // sqlite3_step(), sqlite3_reset() or sqlite3_finalize()
128  //---
129  m_tile_data.resize( bytes );
130  std::memcpy( (void*)&m_tile_data.front(),
131  sqlite3_column_blob( pStmt, i ), bytes );
132  }
133  }
134  }
135  else
136  {
138  << M << " Unexpected column type[" << i << "]: " << type << std::endl;
139  break;
140  }
141  } // Matches: if ( colName.size() )
142 
143  if ( columnsFound == EXPECTED_COLUMNS )
144  {
145  status = true;
146  break;
147  }
148 
149  } // Matches: for ( int i = 0; i < nCol; ++i )
150  }
151 
152  } // Matches: if ( pStmt )
153 
154 #if 0 /* Please leave for debug. (drb) */
155  static bool tracedTile = false;
156  if ( status && !tracedTile )
157  {
158  tracedTile = true;
159  std::ofstream os;
160  std::string file = "debug-tile.";
161  swith( getTileType() )
162  {
163  case OSSIM_GPKG_PNG:
164  {
165  file += "png";
166  break;
167  }
168  case OSSIM_GPKG_JPEG:
169  {
170  file += "jpg";
171  break;
172  }
173  default:
174  break;
175  }
176 
177  os.open( file.c_str(), ios::out | ios::binary);
178  if ( os.good() )
179  {
180  os.write( (char*)&m_tile_data.front(), m_tile_data.size() );
181  }
182  os.close();
183  }
184 #endif
185 
186  return status;
187 
188 } // End: ossimGpkgTileRecord::init( pStmt )
std::vector< ossim_uint8 > m_tile_data
return status
ossimGpkgTileType getTileType() const
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32

◆ operator=()

const ossimGpkgTileRecord & ossimGpkgTileRecord::operator= ( const ossimGpkgTileRecord obj)

Definition at line 45 of file ossimGpkgTileRecord.cpp.

References m_copy_tile_flag, m_id, m_tile_column, m_tile_data, m_tile_row, and m_zoom_level.

47 {
48  if ( this != &obj )
49  {
50  m_id = obj.m_id;
53  m_tile_row = obj.m_tile_row;
56  }
57  return *this;
58 }
std::vector< ossim_uint8 > m_tile_data

◆ print()

std::ostream & ossimGpkgTileRecord::print ( std::ostream &  out) const

Print method.

Does not print the image blob.

Parameters
outStream to print to.
Returns
Stream reference.

Definition at line 222 of file ossimGpkgTileRecord.cpp.

References getTileMediaType(), m_id, m_tile_column, m_tile_data, m_tile_row, and m_zoom_level.

Referenced by operator<<().

223 {
224  out << "id: " << m_id
225  << "\nzoom_level: " << m_zoom_level
226  << "\nm_tile_column: " << m_tile_column
227  << "\nm_tile_row: " << m_tile_row
228  << "\nsignature_block: ";
229 
230  // Signature block:
231  if ( m_tile_data.size() > 7 )
232  {
233  for ( int i = 0; i < 8; ++i )
234  {
235  out << std::hex << int(m_tile_data[i]) << " ";
236  }
237  out << std::dec;
238  }
239  else
240  {
241  out << "null";
242  }
243  out << "\nmedia_type: " << getTileMediaType() << std::endl;
244 
245  return out;
246 }
std::vector< ossim_uint8 > m_tile_data
std::string getTileMediaType() const

◆ setCopyTileFlag()

void ossimGpkgTileRecord::setCopyTileFlag ( bool  flag)

Definition at line 217 of file ossimGpkgTileRecord.cpp.

References m_copy_tile_flag.

Referenced by ossim_gpkg::printTiles().

218 {
219  m_copy_tile_flag = flag;
220 }

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const ossimGpkgTileRecord obj 
)
friend

Convenience operator << function.

Parameters
outStream to print to.
objObject to print.

Definition at line 248 of file ossimGpkgTileRecord.cpp.

250 {
251  return obj.print( out );
252 }
std::ostream & print(std::ostream &out) const
Print method.

Member Data Documentation

◆ m_copy_tile_flag

bool ossimGpkgTileRecord::m_copy_tile_flag

Definition at line 100 of file ossimGpkgTileRecord.h.

Referenced by init(), operator=(), and setCopyTileFlag().

◆ m_id

ossim_int32 ossimGpkgTileRecord::m_id

Definition at line 95 of file ossimGpkgTileRecord.h.

Referenced by init(), operator=(), and print().

◆ m_tile_column

ossim_int32 ossimGpkgTileRecord::m_tile_column

Definition at line 97 of file ossimGpkgTileRecord.h.

Referenced by getTileIndex(), init(), operator=(), and print().

◆ m_tile_data

std::vector<ossim_uint8> ossimGpkgTileRecord::m_tile_data

◆ m_tile_row

ossim_int32 ossimGpkgTileRecord::m_tile_row

Definition at line 98 of file ossimGpkgTileRecord.h.

Referenced by getTileIndex(), init(), operator=(), and print().

◆ m_zoom_level

ossim_int32 ossimGpkgTileRecord::m_zoom_level

Definition at line 96 of file ossimGpkgTileRecord.h.

Referenced by init(), operator=(), and print().


The documentation for this class was generated from the following files: