OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVpfLibrary.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // License: See top level LICENSE.txt file.
3 //
4 // Author: Garrett Potts
5 //
6 // Description: This class extends the stl's string class.
7 //
8 //********************************************************************
9 // $Id: ossimVpfLibrary.cpp 15833 2009-10-29 01:41:53Z eshirschorn $
10 #include <algorithm>
11 
19 
21  :theDatabase(0),
22  theLibraryName(""),
23  theLibraryNameFullPath(""),
24  theNumberOfCoverages(0)
25 {
26 }
27 
29 {
30  theDatabase = 0;
31 }
32 
34  const ossimString& name,
35  const ossimFilename& libraryPath)
36 {
37  bool returnCode = true;
38 
40  theLibraryName = "";
42 
43 
44  theLibraryName = name;
45  theLibraryNameFullPath = libraryPath;
46  theDatabase = database;
47 
49  {
50  returnCode = false;
51  }
52  if(returnCode)
53  {
55 
56  ossimVpfTable table;
57 
59  returnCode = (theNumberOfCoverages> 0);
60  }
61 
62  return returnCode;
63 }
64 
65 bool ossimVpfLibrary::getCoverage(long coverageNumber,
66  ossimVpfCoverage& coverage)
67 {
68 
69  bool result = false;
70 
71  if((coverageNumber >=0) && (coverageNumber < (int)theCoverageNames.size()))
72  {
73  result = coverage.openCoverage(this,
74  theCoverageNames[coverageNumber],
76  }
77 
78  return result;
79 }
80 
82  ossimVpfCoverage& coverage)
83 {
84  for(int idx = 0; idx < (int)theCoverageNames.size(); ++idx)
85  {
86  if(theCoverageNames[idx] == name)
87  {
88  return getCoverage(idx,
89  coverage);
90  }
91  }
92 
93  return false;
94 }
95 
97 {
98  bool result = false;
99  ossimVpfTable tempTable;
100 
101 
102  // this code was basically cut paste from vhcl with just
103  // a couple modifications.
104 
105  /* Get library extent from Library Attribute Table (LAT) */
106 /* char* buf;*/
107 /* long int n;*/
108 /* double xmin,ymin,xmax,ymax;*/
109  int libraryNamePosition, xminPosition, yminPosition;
110  int xmaxPosition, ymaxPosition;
111  int i;
112  bool found;
113  row_type row;
114  extent_type libextent;
115 
116  if(!theDatabase)
117  {
118  return false;
119  }
121  if(!tempTable.openTable(file))
122  {
123  return result;
124  }
125  vpf_table_type *table = tempTable.getVpfTableData();
126 
127  libraryNamePosition = table_pos( "LIBRARY_NAME", *table );
128  found = false;
129  for (i=1;(i<=tempTable.getNumberOfRows())&&(!found);i++)
130  {
131  row = read_row( i, *table );
132  ossimString libraryName = tempTable.getColumnValueAsString(row, libraryNamePosition);
133  libraryName = libraryName.trim();
134  if (libraryName == theLibraryName)
135  {
136  xminPosition = table_pos( "XMIN", *table );
137  yminPosition = table_pos( "YMIN", *table );
138  xmaxPosition = table_pos( "XMAX", *table );
139  ymaxPosition = table_pos( "YMAX", *table );
140 
141  libextent.x1 = tempTable.getColumnValueAsString(row, xminPosition).toDouble();
142  libextent.y1 = tempTable.getColumnValueAsString(row, yminPosition).toDouble();
143  libextent.x2 = tempTable.getColumnValueAsString(row, xmaxPosition).toDouble();
144  libextent.y2 = tempTable.getColumnValueAsString(row, ymaxPosition).toDouble();
145  found = true;
146  }
147  else
148  {
149  result = false;
150  }
151  free_row( row, *table );
152  }
153 
154  extent = ossimVpfExtent(libextent);
155  return result;
156 }
157 
159 {
160  return theLibraryNameFullPath;
161 }
162 
164 {
165  return theLibraryName;
166 }
167 
168 
169 bool ossimVpfLibrary::getCoverageNames(std::vector<ossimString>& coverageNames)const
170 {
171  bool result = true;
172 
173  coverageNames = theCoverageNames;
174 
175  return result;
176 }
177 
179 {
180  return theNumberOfCoverages;
181 }
182 
183 bool ossimVpfLibrary::hasCoverage(const ossimString& coverageName)const
184 {
185  return (std::find(theCoverageNames.begin(),
186  theCoverageNames.end(),
187  coverageName)!=theCoverageNames.end());
188 }
189 
191 {
192  ossimString result;
193  if(theLibraryNameFullPath.dirCat("tileref").exists())
194  {
195  if(theTileNameMap.size() <1)
196  {
197  setTileNames();
198  }
199  std::map<ossim_int32, ossimString>::iterator tileNameIter = theTileNameMap.find(id);
200 
201  if(tileNameIter != theTileNameMap.end())
202  {
203  result = (*tileNameIter).second;
204  }
205  }
206 
207  return result;
208 }
209 
210 void ossimVpfLibrary::getTileNames(std::vector<ossimString>& tileNames)const
211 {
212  if(theLibraryNameFullPath.dirCat("tileref").exists())
213  {
214  if(theTileNameMap.size() <1)
215  {
216  setTileNames();
217  }
218  std::map<ossim_int32, ossimString>::iterator tileNameIter = theTileNameMap.begin();
219  while(tileNameIter != theTileNameMap.end())
220  {
221  tileNames.push_back((*tileNameIter).second);
222  ++tileNameIter;
223  }
224  }
225 }
226 
228 {
229  ossimVpfTable table;
230  theCoverageNames.clear();
231  // open up the coverage attribute table for this library
232  if(table.openTable(theLibraryNameFullPath.dirCat("cat")))
233  {
234  // we need to have a coverage attribute table validator before
235  // we proceed but for now assume that it is a good table.
236  //
237  theCoverageNames = table.getColumnValues("COVERAGE_NAME");
238  }
239 }
240 
242 {
243  ossimVpfTable table;
244  theTileNameMap.clear();
245  row_type row;
246  if(table.openTable(theLibraryNameFullPath.dirCat("tileref").dirCat("tileref.aft")))
247  {
248  table.reset();
249  const int ROWS = table.getNumberOfRows();
250  for (int rowIdx = 1; rowIdx <= ROWS; ++rowIdx)
251  {
252  // Note: read_row takes a "one based" index.
253  row = read_row( rowIdx, *(table.getVpfTableData()) );
254  ossim_int32 namePosition = table.getColumnPosition("TILE_NAME");
255  ossim_int32 tileIdPosition = table.getColumnPosition("ID");
256 
257  ossimString tileName = table.getColumnValueAsString(row,
258  namePosition);;
259  ossimString tileId = table.getColumnValueAsString(row,
260  tileIdPosition);
261  theTileNameMap.insert(make_pair(tileId.toInt32(), tileName.trim()));
262  free_row( row, *(table.getVpfTableData()) );
263  }
264  }
265 }
std::vector< ossimString > theCoverageNames
std::map< ossim_int32, ossimString > theTileNameMap
void free_row(row_type row, vpf_table_type table)
virtual ~ossimVpfLibrary()
int getNumberOfRows() const
ossimString getName() const
ossimVpfDatabase * theDatabase
ossimString getTileName(ossim_int32 id) const
bool openCoverage(ossimVpfLibrary *library, const ossimString &name, const ossimFilename &fileName)
bool getExtent(ossimVpfExtent &result) const
row_type read_row(ossim_int32 row_number, vpf_table_type table)
std::vector< ossimString > getColumnValues(const ossimString &columnName) const
ossim_int32 toInt32() const
void getTileNames(std::vector< ossimString > &tileNames) const
virtual bool openTable(const ossimFilename &tableName)
bool openLibrary(ossimVpfDatabase *database, const ossimString &name, const ossimFilename &libraryPath)
ossim_int32 getColumnPosition(const ossimString &columnName) const
ossim_int32 table_pos(const char *field_name, vpf_table_type table)
bool exists() const
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
int getNumberOfCoverages() const
bool getCoverageNames(std::vector< ossimString > &coverageNames) const
float x2
Definition: vpfview.h:56
float y2
Definition: vpfview.h:56
ossimFilename getLibraryAttributeTable() const
virtual void reset() const
ossimString getColumnValueAsString(row_type &row, long columnNumber) const
vpf_table_type * getVpfTableData()
Definition: ossimVpfTable.h:61
bool getCoverage(long coverageNumber, ossimVpfCoverage &coverage)
float x1
Definition: vpfview.h:56
bool hasCoverage(const ossimString &coverageName) const
float y1
Definition: vpfview.h:56
ossimFilename dirCat(const ossimFilename &file) const
ossimFilename theLibraryNameFullPath
ossim_uint32 theNumberOfCoverages
void setTileNames() const
ossimString theLibraryName
ossimFilename getPath() const
int ossim_int32