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

#include <ossimShapeDatabase.h>

Inheritance diagram for ossimShapeDatabase:
ossimObject ossimReferenced

Public Member Functions

 ossimShapeDatabase ()
 
virtual ~ossimShapeDatabase ()
 
virtual bool open (const ossimFilename &file, const ossimString &flags=ossimString("rb"))
 
virtual void close ()
 
bool getRecord (ossimShapeDatabaseRecord &result)
 
bool getRecord (ossimShapeDatabaseRecord &result, int recordNumber)
 
bool getNextRecord (ossimShapeDatabaseRecord &result)
 
int getNumberOfRecords () const
 
bool isOpen () const
 
virtual DBFHandle getHandle ()
 
virtual const DBFHandle & getHandle () const
 
virtual std::ostream & print (std::ostream &out) const
 Generic print method. More...
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimObjectdup () const
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual ossimString getClassName () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
virtual void accept (ossimVisitor &visitor)
 
- 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
 

Protected Attributes

DBFHandle theHandle
 
ossimFilename theFilename
 
int theRecordNumber
 

Friends

std::ostream & operator<< (std::ostream &out, const ossimShapeDatabase &rhs)
 

Additional Inherited Members

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

Detailed Description

Definition at line 47 of file ossimShapeDatabase.h.

Constructor & Destructor Documentation

◆ ossimShapeDatabase()

ossimShapeDatabase::ossimShapeDatabase ( )

Definition at line 108 of file ossimShapeDatabase.cpp.

References theRecordNumber.

109  :theHandle(NULL),
110  theFilename("")
111 {
112  theRecordNumber = -1;
113 }
ossimFilename theFilename

◆ ~ossimShapeDatabase()

ossimShapeDatabase::~ossimShapeDatabase ( )
virtual

Definition at line 115 of file ossimShapeDatabase.cpp.

References close().

116 {
117  close();
118 }

Member Function Documentation

◆ close()

void ossimShapeDatabase::close ( )
virtual

Definition at line 135 of file ossimShapeDatabase.cpp.

References DBFClose(), isOpen(), theHandle, and theRecordNumber.

Referenced by open(), and ~ossimShapeDatabase().

136 {
137  if(isOpen())
138  {
140  theHandle = NULL;
141  theRecordNumber = -1;
142  }
143 }
void SHPAPI_CALL DBFClose(DBFHandle hDBF)

◆ getHandle() [1/2]

DBFHandle ossimShapeDatabase::getHandle ( )
virtual

Definition at line 253 of file ossimShapeDatabase.cpp.

References theHandle.

254 {
255  return theHandle;
256 }

◆ getHandle() [2/2]

const DBFHandle & ossimShapeDatabase::getHandle ( ) const
virtual

Definition at line 258 of file ossimShapeDatabase.cpp.

References theHandle.

259 {
260  return theHandle;
261 }

◆ getNextRecord()

bool ossimShapeDatabase::getNextRecord ( ossimShapeDatabaseRecord result)

Definition at line 237 of file ossimShapeDatabase.cpp.

References getNumberOfRecords(), getRecord(), isOpen(), and theRecordNumber.

238 {
239  if(isOpen() && ((theRecordNumber+1) < getNumberOfRecords()))
240  {
241  ++theRecordNumber;
242  return getRecord(result);
243  }
244 
245  return false;
246 }
bool getRecord(ossimShapeDatabaseRecord &result)

◆ getNumberOfRecords()

int ossimShapeDatabase::getNumberOfRecords ( ) const

Definition at line 144 of file ossimShapeDatabase.cpp.

References isOpen(), and theHandle.

Referenced by getNextRecord(), and getRecord().

145 {
146  if(isOpen())
147  {
148  return theHandle->nRecords;
149  }
150 
151  return 0;
152 }

◆ getRecord() [1/2]

bool ossimShapeDatabase::getRecord ( ossimShapeDatabaseRecord result)

Definition at line 154 of file ossimShapeDatabase.cpp.

References DBFGetFieldInfo(), DBFReadDoubleAttribute(), DBFReadIntegerAttribute(), DBFReadStringAttribute(), ossimShapeDatabaseRecord::getNumberOfFields(), isOpen(), ossimShapeDatabaseRecord::setField(), ossimShapeDatabaseRecord::setNumberOfFields(), ossimShapeDatabaseField::theDecimals, ossimShapeDatabaseField::theFieldType, theHandle, ossimShapeDatabaseField::theName, theRecordNumber, ossimShapeDatabaseField::theValue, ossimShapeDatabaseField::theWidth, and ossimString::toString().

Referenced by getNextRecord(), and getRecord().

155 {
156  if(isOpen()&&( (theRecordNumber < theHandle->nRecords) ))
157  {
158  if(result.getNumberOfFields() != theHandle->nFields)
159  {
160  result.setNumberOfFields(theHandle->nFields);
161  }
162 
163  char name[1024] = {'\0'};
164  int width = 0;
165  int decimals = 0;
166  int iField = 0;
167  std::vector<int> fieldWidths;
168 
169  for(iField = 0; iField < theHandle->nFields; ++iField)
170  {
171  DBFFieldType fieldType = DBFGetFieldInfo(theHandle,
172  iField,
173  name,
174  &width,
175  &decimals);
177  field.theName = name;
178  field.theWidth = width;
179  field.theDecimals = decimals;
180  field.theFieldType = fieldType;
181 
182  ossimString key = "field";
183  key+=ossimString::toString(iField+1);
184  key+=(ossimString(".")+name+":");
185 
186  switch(fieldType)
187  {
188  case FTString:
189  {
191  break;
192  }
193  case FTInteger:
194  {
196  break;
197  }
198  case FTDouble:
199  {
201  break;
202  }
203  case FTLogical:
204  {
205  break;
206  }
207  case FTInvalid:
208  {
209  break;
210  }
211  }
212 
213  result.setField(field,
214  iField);
215  }
216  return true;
217  }
218 
219  return false;
220 }
DBFFieldType SHPAPI_CALL DBFGetFieldInfo(DBFHandle psDBF, int iField, char *pszFieldName, int *pnWidth, int *pnDecimals)
static ossimString toString(bool aValue)
Numeric to string methods.
double SHPAPI_CALL DBFReadDoubleAttribute(DBFHandle hDBF, int iShape, int iField)
int SHPAPI_CALL DBFReadIntegerAttribute(DBFHandle hDBF, int iShape, int iField)
bool setField(const ossimShapeDatabaseField &field, ossim_uint32 i)
const char SHPAPI_CALL1 * DBFReadStringAttribute(DBFHandle hDBF, int iShape, int iField);const char SHPAPI_CALL1(*) DBFReadLogicalAttribute(DBFHandle hDBF, int iShape, int iField

◆ getRecord() [2/2]

bool ossimShapeDatabase::getRecord ( ossimShapeDatabaseRecord result,
int  recordNumber 
)

Definition at line 222 of file ossimShapeDatabase.cpp.

References getNumberOfRecords(), getRecord(), isOpen(), and theRecordNumber.

224 {
225  if(isOpen())
226  {
227  if(recordNumber < getNumberOfRecords())
228  {
229  theRecordNumber = recordNumber;
230  return getRecord(result);
231  }
232  }
233 
234  return false;
235 }
bool getRecord(ossimShapeDatabaseRecord &result)

◆ isOpen()

bool ossimShapeDatabase::isOpen ( ) const

Definition at line 248 of file ossimShapeDatabase.cpp.

References theHandle.

Referenced by close(), getNextRecord(), getNumberOfRecords(), getRecord(), open(), and print().

249 {
250  return (theHandle!=NULL);
251 }

◆ open()

bool ossimShapeDatabase::open ( const ossimFilename file,
const ossimString flags = ossimString("rb") 
)
virtual

Definition at line 120 of file ossimShapeDatabase.cpp.

References ossimString::c_str(), close(), isOpen(), theFilename, theHandle, and theRecordNumber.

122 {
123  if(isOpen()) close();
124 
125  theHandle = DBFOpen(file.c_str(), flags.c_str());
126  if(theHandle)
127  {
128  theFilename = file;
129  theRecordNumber = -1;
130  }
131 
132  return (theHandle != NULL);
133 }
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
ossimFilename theFilename

◆ print()

std::ostream & ossimShapeDatabase::print ( std::ostream &  out) const
virtual

Generic print method.

Derived classes should re-implement as they see fit.

Returns
std::ostream&

Reimplemented from ossimObject.

Definition at line 263 of file ossimShapeDatabase.cpp.

References ossimString::c_str(), DBFGetFieldInfo(), DBFReadDoubleAttribute(), DBFReadIntegerAttribute(), DBFReadStringAttribute(), isOpen(), theFilename, theHandle, and ossimString::toString().

Referenced by operator<<().

264 {
265  if(isOpen())
266  {
267  out << std::setw(15)<<setiosflags(std::ios::left)
268  <<"DB filename:" << theFilename << std::endl
269  << std::setw(15)<<setiosflags(std::ios::left)
270  <<"records:" << theHandle->nRecords << std::endl
271  << std::setw(15)<<setiosflags(std::ios::left)
272  <<"fields:" << theHandle->nFields << std::endl;
273 
274  char name[1024] = {'\0'};
275  int width = 0;
276  int decimals = 0;
277  int iField = 0;
278  std::vector<int> fieldWidths;
279 
280 
281  for(iField = 0; iField < theHandle->nFields; ++iField)
282  {
283  DBFFieldType fieldType = DBFGetFieldInfo(theHandle,
284  iField,
285  name,
286  &width,
287  &decimals);
288  ossimString s = "field " + ossimString::toString(iField+1) + " name:";
289  switch(fieldType)
290  {
291  case FTString:
292  case FTInteger:
293  case FTDouble:
294  {
295  out << std::setw(15) << setiosflags(std::ios::left) << s.c_str() << name << std::endl;
296  break;
297  }
298  default:
299  {
300  out << std::setw(15) << setiosflags(std::ios::left) << s.c_str() << "INVALID"<<std::endl;
301  break;
302  }
303  }
304  }
305  for(int iShape = 0; iShape < theHandle->nRecords; ++iShape)
306  {
307  for(iField = 0; iField < theHandle->nFields; ++iField)
308  {
309  DBFFieldType fieldType = DBFGetFieldInfo(theHandle,
310  iField,
311  name,
312  &width,
313  &decimals);
314 
315  ossimString key = "field";
316  key+=ossimString::toString(iField+1);
317  key+=(ossimString(".")+name+":");
318 
319  switch(fieldType)
320  {
321  case FTString:
322  {
323 
324  out << std::setw(25) << setiosflags(std::ios::left) << key.c_str()
325  << DBFReadStringAttribute(theHandle, iShape, iField) <<std::endl;
326 
327  break;
328  }
329  case FTInteger:
330  {
331  out << std::setw(25) << setiosflags(std::ios::left) << key.c_str()
332  << DBFReadIntegerAttribute(theHandle, iShape, iField) << std::endl;
333 
334  break;
335  }
336  case FTDouble:
337  {
338  out << std::setw(25) << setiosflags(std::ios::left) << key.c_str()
339  << DBFReadDoubleAttribute(theHandle, iShape, iField) << std::endl;
340 
341  break;
342  }
343  case FTLogical:
344  {
345  break;
346  }
347  case FTInvalid:
348  {
349  break;
350  }
351  }
352  }
353  out << "_________________________________"<<std::endl;
354  }
355  }
356 
357  return out;
358 }
DBFFieldType SHPAPI_CALL DBFGetFieldInfo(DBFHandle psDBF, int iField, char *pszFieldName, int *pnWidth, int *pnDecimals)
static ossimString toString(bool aValue)
Numeric to string methods.
double SHPAPI_CALL DBFReadDoubleAttribute(DBFHandle hDBF, int iShape, int iField)
int SHPAPI_CALL DBFReadIntegerAttribute(DBFHandle hDBF, int iShape, int iField)
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
const char SHPAPI_CALL1 * DBFReadStringAttribute(DBFHandle hDBF, int iShape, int iField);const char SHPAPI_CALL1(*) DBFReadLogicalAttribute(DBFHandle hDBF, int iShape, int iField
ossimFilename theFilename

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const ossimShapeDatabase rhs 
)
friend

Definition at line 101 of file ossimShapeDatabase.cpp.

102 {
103  rhs.print(out);
104 
105  return out;
106 }
virtual std::ostream & print(std::ostream &out) const
Generic print method.

Member Data Documentation

◆ theFilename

ossimFilename ossimShapeDatabase::theFilename
protected

Definition at line 80 of file ossimShapeDatabase.h.

Referenced by open(), and print().

◆ theHandle

DBFHandle ossimShapeDatabase::theHandle
protected

Definition at line 79 of file ossimShapeDatabase.h.

Referenced by close(), getHandle(), getNumberOfRecords(), getRecord(), isOpen(), open(), and print().

◆ theRecordNumber

int ossimShapeDatabase::theRecordNumber
protected

Definition at line 82 of file ossimShapeDatabase.h.

Referenced by close(), getNextRecord(), getRecord(), open(), and ossimShapeDatabase().


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