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

#include <ossimGpkgContentsRecord.h>

Inheritance diagram for ossimGpkgContentsRecord:
ossimGpkgDatabaseRecordBase ossimReferenced

Public Member Functions

 ossimGpkgContentsRecord ()
 default constructor More...
 
 ossimGpkgContentsRecord (const ossimGpkgContentsRecord &obj)
 
const ossimGpkgContentsRecordoperator= (const ossimGpkgContentsRecord &copy_this)
 
virtual ~ossimGpkgContentsRecord ()
 destructor More...
 
virtual bool init (sqlite3_stmt *pStmt)
 Initialize from database. More...
 
bool init (const std::string &tableName, ossim_int32 srs_id, const ossimDpt &minPt, const ossimDpt &maxPt)
 Initialize from projection. More...
 
bool insert (sqlite3 *db)
 Inserst this record into gpkg_spatial_ref_sys table. More...
 
virtual void saveState (ossimKeywordlist &kwl, const std::string &prefix) const
 Saves the state of object to keyword list. More...
 
- Public Member Functions inherited from ossimGpkgDatabaseRecordBase
 ossimGpkgDatabaseRecordBase ()
 default constructor More...
 
virtual ~ossimGpkgDatabaseRecordBase ()
 virtual destructor. More...
 
virtual std::ostream & print (std::ostream &out) const
 Print method. More...
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Static Public Member Functions

static const std::string & getTableName ()
 Get the table name "gpkg_contents". More...
 
static bool createTable (sqlite3 *db)
 Creates table in database. More...
 

Public Attributes

std::string m_table_name
 
std::string m_data_type
 
std::string m_identifier
 
std::string m_description
 
std::string m_last_change
 
ossim_float64 m_min_x
 
ossim_float64 m_min_y
 
ossim_float64 m_max_x
 
ossim_float64 m_max_y
 
ossim_int32 m_srs_id
 

Additional Inherited Members

- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Detailed Description

Definition at line 24 of file ossimGpkgContentsRecord.h.

Constructor & Destructor Documentation

◆ ossimGpkgContentsRecord() [1/2]

ossimGpkgContentsRecord::ossimGpkgContentsRecord ( )

default constructor

Definition at line 25 of file ossimGpkgContentsRecord.cpp.

26  :
28  m_table_name(),
29  m_data_type(),
30  m_identifier(),
31  m_description(),
32  m_last_change(),
37  m_srs_id(0)
38 {
39 }
ossimGpkgDatabaseRecordBase()
default constructor
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135

◆ ossimGpkgContentsRecord() [2/2]

ossimGpkgContentsRecord::ossimGpkgContentsRecord ( const ossimGpkgContentsRecord obj)

Definition at line 41 of file ossimGpkgContentsRecord.cpp.

42  :
49  m_min_x(obj.m_min_x),
50  m_min_y(obj.m_min_y),
51  m_max_x(obj.m_max_x),
52  m_max_y(obj.m_max_y),
53  m_srs_id(obj.m_srs_id)
54 {
55 }
ossimGpkgDatabaseRecordBase()
default constructor

◆ ~ossimGpkgContentsRecord()

ossimGpkgContentsRecord::~ossimGpkgContentsRecord ( )
virtual

destructor

Definition at line 76 of file ossimGpkgContentsRecord.cpp.

77 {
78 }

Member Function Documentation

◆ createTable()

bool ossimGpkgContentsRecord::createTable ( sqlite3 *  db)
static

Creates table in database.

Parameters
db
Returns
true on success, false on error.

Definition at line 219 of file ossimGpkgContentsRecord.cpp.

References status, and ossim_sqlite::tableExists().

Referenced by ossimGpkgWriter::createTables().

220 {
221  bool status = false;
222  if ( db )
223  {
224  status = ossim_sqlite::tableExists( db, TABLE_NAME );
225 
226  if ( !status )
227  {
228  std::ostringstream sql;
229  sql << "CREATE TABLE " << TABLE_NAME << " ( "
230  << "table_name TEXT NOT NULL PRIMARY KEY, "
231  << "data_type TEXT NOT NULL, "
232  << "identifier TEXT UNIQUE, "
233  << "description TEXT DEFAULT \"\", "
234 
235  //---
236  // Requirement 13:
237  // Note: Spec changed to %fZ. No %f on linux but sqlite library handles.
238  // << "last_change DATETIME NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ','now')), "
239  //---
240  << "last_change DATETIME NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')), "
241  << "min_x DOUBLE, "
242  << "min_y DOUBLE, "
243  << "max_x DOUBLE, "
244  << "max_y DOUBLE, "
245  << "srs_id INTEGER, "
246  << "CONSTRAINT fk_gc_r_srs_id FOREIGN KEY (srs_id) "
247  << "REFERENCES gpkg_spatial_ref_sys(srs_id)"
248  << ")";
249 
250  if ( ossim_sqlite::exec( db, sql.str() ) == SQLITE_DONE )
251  {
252  status = true;
253  }
254  }
255  }
256  return status;
257 }
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

◆ getTableName()

const std::string & ossimGpkgContentsRecord::getTableName ( )
static

Get the table name "gpkg_contents".

Returns
table name

Definition at line 80 of file ossimGpkgContentsRecord.cpp.

Referenced by ossim_gpkg::getNewTableRecord().

81 {
82  return TABLE_NAME;
83 }

◆ init() [1/2]

bool ossimGpkgContentsRecord::init ( sqlite3_stmt *  pStmt)
virtual

Initialize from database.

Parameters
pStmtSQL statement, i.e. result of sqlite3_prepare_v2(...) call.
Returns
true on success, false on error.

Implements ossimGpkgDatabaseRecordBase.

Definition at line 85 of file ossimGpkgContentsRecord.cpp.

References m_data_type, m_description, m_identifier, m_last_change, m_max_x, m_max_y, m_min_x, m_min_y, m_srs_id, m_table_name, ossimNotify(), ossimNotifyLevel_WARN, and status.

Referenced by ossimGpkgWriter::writeGpkgContentsTable().

86 {
87  static const char M[] = "ossimGpkgContentsRecord::init";
88 
89  bool status = false;
90 
91  if ( pStmt )
92  {
93  const ossim_int32 EXPECTED_COLUMNS = 10;
94  ossim_int32 nCol = sqlite3_column_count( pStmt );
95 
96  if ( nCol != EXPECTED_COLUMNS )
97  {
99  << M << " WARNING:\nUnexpected number of columns: " << nCol
100  << "Expected column count: " << EXPECTED_COLUMNS
101  << std::endl;
102  }
103 
104  if ( nCol >= EXPECTED_COLUMNS )
105  {
106  ossim_int32 columnsFound = 0;
107  std::string colName;
108  const char* c = 0; // To catch null so not to pass to string.
109 
110  for ( ossim_int32 i = 0; i < nCol; ++i )
111  {
112  colName = sqlite3_column_name(pStmt, i);
113  if ( colName.size() )
114  {
115  if ( colName == "table_name" )
116  {
117  c = (const char*)sqlite3_column_text(pStmt, i);
118  m_table_name = (c ? c : "");
119  ++columnsFound;
120  }
121  else if ( colName == "data_type" )
122  {
123  c = (const char*)sqlite3_column_text(pStmt, i);
124  m_data_type = (c ? c : "");
125  ++columnsFound;
126  }
127  else if ( colName == "identifier" )
128  {
129  c = (const char*)sqlite3_column_text(pStmt, i);
130  m_identifier = (c ? c : "");
131  ++columnsFound;
132  }
133  else if ( colName == "description" )
134  {
135  c = (const char*)sqlite3_column_text(pStmt, i);
136  m_description = (c ? c : "");
137  ++columnsFound;
138  }
139  else if ( colName == "last_change" )
140  {
141  c = (const char*)sqlite3_column_text(pStmt, i);
142  m_last_change = (c ? c : "");
143  ++columnsFound;
144  }
145  else if ( colName == "min_x" )
146  {
147  m_min_x = sqlite3_column_double(pStmt, i);
148  ++columnsFound;
149  }
150  else if ( colName == "min_y" )
151  {
152  m_min_y = sqlite3_column_double(pStmt, i);
153  ++columnsFound;
154  }
155  else if ( colName == "max_x" )
156  {
157  m_max_x = sqlite3_column_double(pStmt, i);
158  ++columnsFound;
159  }
160  else if ( colName == "max_y" )
161  {
162  m_max_y = sqlite3_column_double(pStmt, i);
163  ++columnsFound;
164  }
165  else if ( colName == "srs_id" )
166  {
167  m_srs_id = sqlite3_column_int(pStmt, i);
168  ++columnsFound;
169  }
170  else
171  {
173  << M << " Unhandled column name["
174  << i << "]: " << colName << std::endl;
175  }
176 
177  } // Matches: if ( colName.size() )
178 
179  if ( columnsFound == EXPECTED_COLUMNS )
180  {
181  status = true;
182  break;
183  }
184 
185  } // Matches: for ( ossim_int32 i = 0; i < nCol; ++i )
186  }
187 
188  } // Matches: if ( pStmt )
189 
190  return status;
191 
192 } // End: ossimGpkgContentsRecord::init( sqlite3_stmt* pStmt )
return status
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32

◆ init() [2/2]

bool ossimGpkgContentsRecord::init ( const std::string &  tableName,
ossim_int32  srs_id,
const ossimDpt minPt,
const ossimDpt maxPt 
)

Initialize from projection.

Parameters
tableNamee.g. "tiles"
srs_idID of gpkg_spatial_ref_sys record our projection is relative to.
minPtMinimum bounds in either Easting Northin or lat lon.
maxPtMaximum bounds in either Easting Northin or lat lon. *
Returns
true on success, false on error.

Definition at line 194 of file ossimGpkgContentsRecord.cpp.

References ossim_sqlite::getTime(), ossimDpt::hasNans(), m_data_type, m_description, m_identifier, m_last_change, m_max_x, m_max_y, m_min_x, m_min_y, m_srs_id, m_table_name, status, ossimDpt::x, and ossimDpt::y.

197 {
198  bool status = false;
199  if ( (minPt.hasNans() == false) && (maxPt.hasNans() == false) )
200  {
201  m_table_name = tableName;
202  m_data_type = "tiles";
203  m_identifier = "Raster Tiles for ";
204  m_identifier += tableName;
205  m_description = "Create by ossim gpkg writer.";
206 
208 
209  m_min_x = minPt.x;
210  m_min_y = minPt.y;
211  m_max_x = maxPt.x;
212  m_max_y = maxPt.y;
213  m_srs_id = srs_id;
214  status = true;
215  }
216  return status;
217 }
double y
Definition: ossimDpt.h:165
bool hasNans() const
Definition: ossimDpt.h:67
return status
void getTime(std::string &result)
Gets time in the form of "%Y-%m-%dT%H:%M:%S.000Z".
double x
Definition: ossimDpt.h:164

◆ insert()

bool ossimGpkgContentsRecord::insert ( sqlite3 *  db)

Inserst this record into gpkg_spatial_ref_sys table.

Parameters
db
Returns
true on success, false on error.

Definition at line 259 of file ossimGpkgContentsRecord.cpp.

References ossim_sqlite::exec(), m_data_type, m_description, m_identifier, m_last_change, m_max_x, m_max_y, m_min_x, m_min_y, m_srs_id, m_table_name, and status.

Referenced by ossimGpkgWriter::writeGpkgContentsTable().

260 {
261  bool status = false;
262  if ( db )
263  {
264  std::ostringstream sql;
265  sql << "INSERT INTO gpkg_contents VALUES ( "
266  << "'" << m_table_name << "', "
267  << "'" << m_data_type << "', "
268  << "'" << m_identifier << "', "
269  << "'" << m_description << "', "
270  << "'" << m_last_change << "', "
271  << std::setprecision(16)
272  << m_min_x << ", "
273  << m_min_y << ", "
274  << m_max_x << ", "
275  << m_max_y << ", "
276  << m_srs_id
277  << " )";
278 
279  if ( ossim_sqlite::exec( db, sql.str() ) == SQLITE_DONE )
280  {
281  status = true;
282  }
283  }
284  return status;
285 }
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.
return status

◆ operator=()

const ossimGpkgContentsRecord & ossimGpkgContentsRecord::operator= ( const ossimGpkgContentsRecord copy_this)

Definition at line 57 of file ossimGpkgContentsRecord.cpp.

References m_data_type, m_description, m_identifier, m_last_change, m_max_x, m_max_y, m_min_x, m_min_y, m_srs_id, and m_table_name.

59 {
60  if ( this != &copy_this )
61  {
62  m_table_name = copy_this.m_table_name;
63  m_data_type = copy_this.m_data_type;
64  m_identifier = copy_this.m_identifier;
65  m_description = copy_this.m_description;
66  m_last_change = copy_this.m_last_change;
67  m_min_x = copy_this.m_min_x;
68  m_min_y = copy_this.m_min_y;
69  m_max_x = copy_this.m_max_x;
70  m_max_y = copy_this.m_max_y;
71  m_srs_id = copy_this.m_srs_id;
72  }
73  return *this;
74 }

◆ saveState()

void ossimGpkgContentsRecord::saveState ( ossimKeywordlist kwl,
const std::string &  prefix 
) const
virtual

Saves the state of object to keyword list.

Parameters
kwlInitialized by this.
prefixe.g. "image0.". Can be empty.

Implements ossimGpkgDatabaseRecordBase.

Definition at line 287 of file ossimGpkgContentsRecord.cpp.

References ossimKeywordlist::addPair(), m_data_type, m_description, m_identifier, m_last_change, m_max_x, m_max_y, m_min_x, m_min_y, m_srs_id, m_table_name, ossimString::string(), and ossimString::toString().

289 {
290  std::string myPref = prefix.size() ? prefix : std::string("gpkg_contents.");
291  std::string value;
292 
293  std::string key = "table_name";
294  kwl.addPair(myPref, key, m_table_name, true);
295 
296  key = "data_type";
297  kwl.addPair(myPref, key, m_data_type, true);
298 
299  key = "identifier";
300  kwl.addPair(myPref, key, m_identifier, true);
301 
302  key = "description";
303  kwl.addPair(myPref, key, m_description, true);
304 
305  key = "last_change";
306  kwl.addPair(myPref, key, m_last_change, true);
307 
308  key = "min_x";
309  value = ossimString::toString(m_min_x, 15).string();
310  kwl.addPair(myPref, key, value, true);
311 
312  key = "min_y";
313  value = ossimString::toString(m_min_y, 15).string();
314  kwl.addPair(myPref, key, value, true);
315 
316  key = "max_x";
317  value = ossimString::toString(m_max_x, 15).string();
318  kwl.addPair(myPref, key, value, true);
319 
320  key = "max_y";
321  value = ossimString::toString(m_max_y, 15).string();
322  kwl.addPair(myPref, key, value, true);
323 
324  key = "srs_id";
326  kwl.addPair(myPref, key, value, true);
327 }
static ossimString toString(bool aValue)
Numeric to string methods.
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
const std::string & string() const
Definition: ossimString.h:414

Member Data Documentation

◆ m_data_type

std::string ossimGpkgContentsRecord::m_data_type

Definition at line 89 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_description

std::string ossimGpkgContentsRecord::m_description

Definition at line 91 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_identifier

std::string ossimGpkgContentsRecord::m_identifier

Definition at line 90 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_last_change

std::string ossimGpkgContentsRecord::m_last_change

Definition at line 92 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_max_x

ossim_float64 ossimGpkgContentsRecord::m_max_x

Definition at line 95 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_max_y

ossim_float64 ossimGpkgContentsRecord::m_max_y

Definition at line 96 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_min_x

ossim_float64 ossimGpkgContentsRecord::m_min_x

Definition at line 93 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_min_y

ossim_float64 ossimGpkgContentsRecord::m_min_y

Definition at line 94 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_srs_id

ossim_int32 ossimGpkgContentsRecord::m_srs_id

Definition at line 97 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().

◆ m_table_name

std::string ossimGpkgContentsRecord::m_table_name

Definition at line 88 of file ossimGpkgContentsRecord.h.

Referenced by init(), insert(), operator=(), and saveState().


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