OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
TiffHandlerState.cpp
Go to the documentation of this file.
15 #include <xtiffio.h>
16 #include <geo_normalize.h>
17 #include <geotiff.h>
18 #include <geovalues.h>
19 #include <cstddef> //nullptr
20 #include <sstream>
21 static ossimTrace traceDebug("ossim::TiffHandlerState");
22 
23 static const ossimGeoTiffCoordTransformsLut COORD_TRANS_LUT;
24 static const ossimGeoTiffDatumLut DATUM_LUT;
25 
26 const ossimString ossim::TiffHandlerState::m_typeName = "ossim::TiffHandlerState";
27 
28 ossim::TiffHandlerState::TiffHandlerState()
29 {
30 
31 }
32 
33 ossim::TiffHandlerState::~TiffHandlerState()
34 {
35 
36 }
37 
38 const ossimString& ossim::TiffHandlerState::getTypeName()const
39 {
40  return m_typeName;
41 }
42 
43 const ossimString& ossim::TiffHandlerState::getStaticTypeName()
44 {
45  return m_typeName;
46 }
47 
48 void ossim::TiffHandlerState::addValue(const ossimString& key,
49  const ossimString& value)
50 {
51  m_tags.add(key.c_str(), value.c_str());
52 }
53 
54 bool ossim::TiffHandlerState::getValue(ossimString& value,
55  const ossim_uint32 directory,
56  const ossimString& key)const
57 {
58  return getValue(value,
59  "dir"+ossimString::toString(directory)+"."+key);
60 }
61 
62 bool ossim::TiffHandlerState::getValue(ossimString& value,
63  const ossimString& key)const
64 {
65  bool result = false;
66 
67  const char* v = m_tags.find(key.c_str());
68  if(v)
69  {
70  result = true;
71  value = v;
72  }
73 
74  return result;
75 }
76 
77 bool ossim::TiffHandlerState::exists(ossim_uint32 directory, const ossimString& key)const
78 {
79  return exists("dir"+
80  ossimString::toString(directory)+
81  "."+key);
82 
83 }
84 bool ossim::TiffHandlerState::exists(const ossimString& key)const
85 {
86  return (m_tags.find(key)!= 0);
87 
88 }
89 
90 bool ossim::TiffHandlerState::checkBool(ossim_uint32 directory, const ossimString& key)const
91 {
92  return checkBool("dir"+ossimString::toString(directory)+"."+key);
93 }
94 
95 bool ossim::TiffHandlerState::checkBool(const ossimString& key)const
96 {
97  bool result = false;
98  const char* value = m_tags.find(key);
99  if(value)
100  {
101  result = ossimString(value).toBool();
102  }
103  return result;
104 }
105 
106 bool ossim::TiffHandlerState::loadDefaults(const ossimFilename& file,
107  ossim_uint32 entry)
108 {
109  bool result = ImageHandlerState::loadDefaults(file, entry);
110 
111  if(result)
112  {
113  std::shared_ptr<std::istream> tiffStream = ossim::StreamFactoryRegistry::instance()->createIstream(file);
114  if(tiffStream)
115  {
116  std::shared_ptr<ossim::TiffIStreamAdaptor> streamAdaptor = std::make_shared<ossim::TiffIStreamAdaptor>(tiffStream,
117  file.c_str());
118  TIFF* tiffPtr = XTIFFClientOpen(file.c_str(), "rm",
119  (thandle_t)streamAdaptor.get(),
120  ossim::TiffIStreamAdaptor::tiffRead,
121  ossim::TiffIStreamAdaptor::tiffWrite,
122  ossim::TiffIStreamAdaptor::tiffSeek,
123  ossim::TiffIStreamAdaptor::tiffClose,
124  ossim::TiffIStreamAdaptor::tiffSize,
125  ossim::TiffIStreamAdaptor::tiffMap,
126  ossim::TiffIStreamAdaptor::tiffUnmap);
127 
128  if(tiffPtr)
129  {
130  loadDefaults(tiffPtr);
131  result = true;
132  XTIFFClose(tiffPtr);
133  tiffPtr = 0;
134  }
135  }
136  }
137 
138  return result;
139 }
140 
141 void ossim::TiffHandlerState::loadDefaults(TIFF* tiffPtr)
142 {
143  ossim_int64 currentDirectory = TIFFCurrentDirectory(tiffPtr);
144  TIFFSetDirectory(tiffPtr, 0);
145  ossim_int32 numberOfDirectories = TIFFNumberOfDirectories(tiffPtr);
146 
147  addValue("number_of_directories", ossimString::toString(numberOfDirectories));
148 
149  ossim_int32 idx=0;
150  for(;idx < numberOfDirectories;++idx)
151  {
152  if (!TIFFSetDirectory(tiffPtr, idx))
153  {
154  break;
155  }
156  else
157  {
158  loadDirectory(tiffPtr, idx);
159  }
160  }
161  TIFFSetDirectory(tiffPtr, currentDirectory);
162 }
163 
164 
165 void ossim::TiffHandlerState::loadCurrentDirectory(TIFF* tiffPtr)
166 {
167  if(tiffPtr)
168  {
169  loadDirectory(tiffPtr, TIFFCurrentDirectory(tiffPtr));
170  }
171 }
172 
173 void ossim::TiffHandlerState::loadDirectory(TIFF* tiffPtr,
174  ossim_uint32 directory)
175 {
176  ossim_uint32 imageWidth=0;
177  ossim_uint32 imageLength=0;
178  ossim_int32 readMethod=0;
179  ossim_uint16 planarConfig=0;
180  ossim_uint16 photometric=0;
181  ossim_uint32 rowsPerStrip=0;
182  ossim_uint32 imageTileWidth=0;
183  ossim_uint32 imageTileLength=0;
184  ossim_uint32 imageDirectoryList=0;
185  ossim_int32 compressionType=0;
186  ossim_uint32 subFileType=0;
187  ossim_uint16 bitsPerSample=0;
188  ossim_uint16 samplesPerPixel=0;
189  ossim_uint16 sampleFormatUnit=0;
190  ossim_float64 sampleValue=0;
191  ossim_uint16 sampleUintValue = 0;
192 
193  ossim_int32 numberOfDirectories = TIFFNumberOfDirectories(tiffPtr);
194 
195  addValue("number_of_directories", ossimString::toString(numberOfDirectories));
196 
197  if(TIFFCurrentDirectory(tiffPtr) != directory)
198  {
199  if(!TIFFSetDirectory(tiffPtr, directory))
200  {
201  return;
202  }
203  }
204  ossimString dirPrefix = "dir"+ossimString::toString(directory)+".";
205 
206  if(TIFFGetField(tiffPtr, TIFFTAG_COMPRESSION, &compressionType))
207  {
208  addValue(dirPrefix+"tifftag.compression", ossimString::toString(compressionType));
209  }
210 
211  if( TIFFGetField(tiffPtr, TIFFTAG_BITSPERSAMPLE, &bitsPerSample) )
212  {
213  addValue(dirPrefix+"tifftag.bits_per_sample", ossimString::toString(bitsPerSample));
214  }
215  if( TIFFGetField(tiffPtr,
216  TIFFTAG_SAMPLESPERPIXEL,
217  &samplesPerPixel ) )
218  {
219  addValue(dirPrefix+"tifftag.samples_per_pixel", ossimString::toString(samplesPerPixel));
220  }
221 
222  if ( TIFFGetField( tiffPtr,
223  TIFFTAG_SAMPLEFORMAT,
224  &sampleFormatUnit ) )
225  {
226  addValue(dirPrefix+"tifftag.sample_format", ossimString::toString(sampleFormatUnit));
227  }
228 
229  if (TIFFGetField(tiffPtr,
230  TIFFTAG_SMAXSAMPLEVALUE,
231  &sampleValue ) )
232  {
233  addValue(dirPrefix+"tifftag.max_sample_value", ossimString::toString(sampleValue));
234  }
235  else
236  {
237  if(TIFFGetField( tiffPtr,
238  TIFFTAG_MAXSAMPLEVALUE,
239  &sampleUintValue))
240  {
241  addValue(dirPrefix+"tifftag.max_sample_value", ossimString::toString(sampleUintValue));
242  }
243 
244  }
245 
246  if ( TIFFGetField( tiffPtr,
247  TIFFTAG_SMINSAMPLEVALUE,
248  &sampleValue ) )
249  {
250  addValue(dirPrefix+"tifftag.min_sample_value", ossimString::toString(sampleValue));
251  }
252  else
253  {
254  if(TIFFGetField( tiffPtr,
255  TIFFTAG_MINSAMPLEVALUE,
256  &sampleUintValue))
257  {
258  addValue(dirPrefix+"tifftag.min_sample_value", ossimString::toString(sampleUintValue));
259  }
260  }
261 
262 
263  // lines:
264  if ( TIFFGetField( tiffPtr,
265  TIFFTAG_IMAGELENGTH,
266  &imageLength ) )
267  {
268  addValue(dirPrefix+"tifftag.image_length",
269  ossimString::toString(imageLength));
270  }
271 
272  // samples:
273  if ( TIFFGetField( tiffPtr,
274  TIFFTAG_IMAGEWIDTH,
275  &imageWidth ) )
276  {
277  addValue(dirPrefix+"tifftag.image_width",
278  ossimString::toString(imageWidth));
279  }
280 
281  if (TIFFGetField(tiffPtr,
282  TIFFTAG_SUBFILETYPE ,
283  &subFileType ) )
284  {
285  addValue(dirPrefix+"tifftag.sub_file_type", ossimString::toString(subFileType));
286  }
287 
288  if( TIFFGetField( tiffPtr, TIFFTAG_PLANARCONFIG,
289  &planarConfig ) )
290  {
291  addValue(dirPrefix+"tifftag.planar_config",
292  ossimString::toString(planarConfig));
293  }
294 
295  if( TIFFGetField( tiffPtr, TIFFTAG_PHOTOMETRIC,
296  &photometric ) )
297  {
298  addValue(dirPrefix+"tifftag.photometric",
299  ossimString::toString(photometric));
300  }
301 
302  // Check for palette.
303  ossim_uint16* red;
304  ossim_uint16* green;
305  ossim_uint16* blue;
306  if(TIFFGetField(tiffPtr, TIFFTAG_COLORMAP, &red, &green, &blue))
307  {
308  if(bitsPerSample)
309  {
310  saveColorMap(dirPrefix, red, green, blue, 1<<bitsPerSample);
311  }
312  }
313 
314  if( TIFFIsTiled(tiffPtr))
315  {
316  addValue(dirPrefix+"is_tiled", "true");
317  if ( TIFFGetField( tiffPtr,
318  TIFFTAG_TILEWIDTH,
319  &imageTileWidth ) )
320  {
321  addValue(dirPrefix+"tifftag.tile_width",
322  ossimString::toString(imageTileWidth));
323  }
324  if ( TIFFGetField( tiffPtr,
325  TIFFTAG_TILELENGTH,
326  &imageTileLength ) )
327  {
328  addValue(dirPrefix+"tifftag.tile_length",
329  ossimString::toString(imageTileLength));
330  }
331  }
332  else
333  {
334  addValue(dirPrefix+"tiff_is_tiled", "false");
335  if( TIFFGetField( tiffPtr, TIFFTAG_ROWSPERSTRIP,
336  &rowsPerStrip ) )
337  {
338  addValue(dirPrefix+"tifftag.rows_per_strip",
339  ossimString::toString(rowsPerStrip));
340  }
341  }
342 
343  loadGeotiffTags(tiffPtr, dirPrefix);
344 }
345 
346 
347 void ossim::TiffHandlerState::saveColorMap(const ossimString& dirPrefix,
348  const ossim_uint16* red,
349  const ossim_uint16* green,
350  const ossim_uint16* blue,
351  ossim_uint32 numberOfEntries)
352 {
353  ossim_uint32 idx = 0;
354  std::ostringstream redStream;
355  std::ostringstream greenStream;
356  std::ostringstream blueStream;
357  redStream << "(";
358  greenStream << "(";
359  blueStream << "(";
360  for(;idx < (numberOfEntries-1);++idx,++red,++green,++blue)
361  {
362  redStream << *red << ",";
363  greenStream << *green << ",";
364  blueStream << *blue << ",";
365  if((idx%16)==0)
366  {
367  redStream << "\n";
368  greenStream << "\n";
369  blueStream << "\n";
370  }
371  }
372  redStream << *red << ")";
373  greenStream << *green << ")";
374  blueStream << *blue << ")";
375 
376  addValue(dirPrefix+"tifftag.colormap.red",
377  redStream.str());
378  addValue(dirPrefix+"tifftag.colormap.green",
379  greenStream.str());
380  addValue(dirPrefix+"tifftag.colormap.blue",
381  blueStream.str());
382 }
383 
384 void ossim::TiffHandlerState::loadGeotiffTags(TIFF* tiffPtr,
385  const ossimString& dirPrefix )
386 {
387  const int CITATION_STRING_SIZE = 512;
388  ossim_uint16 rasterType = 0;
389  ossim_uint16 pcsCode = 0;
390  ossim_uint16 coordTransGeoCode = 0;
391  ossim_uint32 idx = 0;
392  GTIF* gtif = GTIFNew(tiffPtr);
393  char citationStrPtr[CITATION_STRING_SIZE];
394  char* buf = 0;
395  ossim_uint16 doubleArraySize = 0;
396  double tempDouble=0.0;
397  double* doubleArray=0;
398  ossimString doubleArrayStr;
399  bool loadedGeotiff = false;
400  if(!gtif)
401  {
402  addValue(dirPrefix+"is_geotiff", "false");
403  return;
404  }
405 
406  // Note: For some reason I am having troubles using
407  // GTIFGetDefn so I have to query them directly. I was getting
408  // Core dumps in the JNI calls to the OSSIM core library.
409  // Until this is resolved I will use the direct method of getting
410  // the values I need.
411  //
412  ossim_uint16 tempUint16 = 0;
413  if(GTIFKeyGet(gtif, GTModelTypeGeoKey, &tempUint16, 0, 1))
414  {
415  loadedGeotiff = true;
416  addValue(dirPrefix+"tifftag.model_type",
417  ossimString::toString(tempUint16));
418  }
419  if(GTIFKeyGet(gtif, GeographicTypeGeoKey, &tempUint16, 0, 1))
420  {
421  loadedGeotiff = true;
422  addValue(dirPrefix+"tifftag.gcs_code",
423  ossimString::toString(tempUint16));
424  }
425  if(GTIFKeyGet(gtif, GeogGeodeticDatumGeoKey, &tempUint16, 0, 1))
426  {
427  loadedGeotiff = true;
428  addValue(dirPrefix+"tifftag.datum_code",
429  ossimString::toString(tempUint16));
430  }
431  if(GTIFKeyGet(gtif, GeogAngularUnitsGeoKey, &tempUint16, 0, 1))
432  {
433  loadedGeotiff = true;
434  addValue(dirPrefix+"tifftag.angular_units",
435  ossimString::toString(tempUint16));
436  }
437  if(GTIFKeyGet(gtif, GeogLinearUnitsGeoKey, &tempUint16, 0, 1))
438  {
439  loadedGeotiff = true;
440  addValue(dirPrefix+"tifftag.linear_units",
441  ossimString::toString(tempUint16));
442  }
443 
444  if(GTIFKeyGet(gtif, ProjStdParallel1GeoKey, &tempDouble, 0, 1))
445  {
446  loadedGeotiff = true;
447  addValue(dirPrefix+"tifftag.std_parallel_1",
448  ossimString::toString(tempDouble));
449  }
450  if(GTIFKeyGet(gtif, ProjStdParallel2GeoKey, &tempDouble, 0, 1))
451  {
452  loadedGeotiff = true;
453  addValue(dirPrefix+"tifftag.std_parallel_2",
454  ossimString::toString(tempDouble));
455  }
456  if(GTIFKeyGet(gtif, ProjNatOriginLongGeoKey, &tempDouble, 0, 1))
457  {
458  loadedGeotiff = true;
459  addValue(dirPrefix+"tifftag.origin_lon",
460  ossimString::toString(tempDouble));
461  }
462  else if(GTIFKeyGet(gtif, ProjOriginLongGeoKey, &tempDouble, 0, 1))
463  {
464  loadedGeotiff = true;
465  addValue(dirPrefix+"tifftag.origin_lon",
466  ossimString::toString(tempDouble));
467  }
468  if(GTIFKeyGet(gtif, ProjNatOriginLatGeoKey, &tempDouble, 0, 1))
469  {
470  loadedGeotiff = true;
471  addValue(dirPrefix+"tifftag.origin_lat",
472  ossimString::toString(tempDouble));
473  }
474  else if(GTIFKeyGet(gtif, ProjOriginLatGeoKey, &tempDouble, 0, 1))
475  {
476  loadedGeotiff = true;
477  addValue(dirPrefix+"tifftag.origin_lat",
478  ossimString::toString(tempDouble));
479  }
480  if(GTIFKeyGet(gtif, ProjFalseEastingGeoKey, &tempDouble, 0, 1))
481  {
482  loadedGeotiff = true;
483  addValue(dirPrefix+"tifftag.false_easting",
484  ossimString::toString(tempDouble));
485  }
486  if(GTIFKeyGet(gtif, ProjFalseNorthingGeoKey, &tempDouble, 0, 1))
487  {
488  loadedGeotiff = true;
489  addValue(dirPrefix+"tifftag.false_northing",
490  ossimString::toString(tempDouble));
491  }
492  if(GTIFKeyGet(gtif, ProjCenterLongGeoKey, &tempDouble, 0, 1))
493  {
494  loadedGeotiff = true;
495  addValue(dirPrefix+"tifftag.center_lon",
496  ossimString::toString(tempDouble));
497  }
498  if(GTIFKeyGet(gtif, ProjCenterLatGeoKey, &tempDouble, 0, 1))
499  {
500  loadedGeotiff = true;
501  addValue(dirPrefix+"tifftag.center_lat",
502  ossimString::toString(tempDouble));
503  }
504  if(GTIFKeyGet(gtif, ProjScaleAtNatOriginGeoKey, &tempDouble, 0, 1))
505  {
506  loadedGeotiff = true;
507  addValue(dirPrefix+"tifftag.scale_factor",
508  ossimString::toString(tempDouble));
509  }
510  if(GTIFKeyGet(gtif, GTRasterTypeGeoKey, &rasterType, 0, 1))
511  {
512  loadedGeotiff = true;
513  addValue(dirPrefix+"tifftag.raster_type",
514  ossimString::toString(rasterType));
515 
516  }
517  if (GTIFKeyGet(gtif, ProjectedCSTypeGeoKey, &pcsCode, 0, 1))
518  {
519  loadedGeotiff = true;
520  addValue(dirPrefix+"tifftag.pcs_code",
521  ossimString::toString(pcsCode));
522  }
523 
524  if ( GTIFKeyGet(gtif, GTCitationGeoKey, &citationStrPtr ,
525  0, CITATION_STRING_SIZE))
526  {
527  loadedGeotiff = true;
528  addValue(dirPrefix+"tifftag.citation",
529  ossimString(citationStrPtr));
530  }
531  if(GTIFKeyGet(gtif, PCSCitationGeoKey , &buf, 0, 1))
532  {
533  loadedGeotiff = true;
534  addValue(dirPrefix+"tifftag.pcs_citation",
535  buf);
536  }
537  if(GTIFKeyGet(gtif, ProjCoordTransGeoKey , &coordTransGeoCode, 0, 1))
538  {
539  loadedGeotiff = true;
540  addValue(dirPrefix+"tifftag.coord_trans_code",
541  ossimString::toString(coordTransGeoCode));
542  }
543 
544  if(TIFFGetField(tiffPtr, TIFFTAG_GEOPIXELSCALE, &doubleArraySize, &doubleArray))
545  {
546  loadedGeotiff = true;
547  convertArrayToStringList(doubleArrayStr, doubleArray, doubleArraySize);
548  if(!doubleArrayStr.empty())
549  {
550  addValue(dirPrefix+"tifftag.geo_pixel_scale", doubleArrayStr);
551  }
552  }
553  if(TIFFGetField(tiffPtr, TIFFTAG_GEOTIEPOINTS, &doubleArraySize, &doubleArray))
554  {
555  loadedGeotiff = true;
556  convertArrayToStringList(doubleArrayStr, doubleArray, doubleArraySize);
557  if(!doubleArrayStr.empty())
558  {
559  addValue(dirPrefix+"tifftag.geo_tie_points", doubleArrayStr);
560  }
561  }
562  if(TIFFGetField(tiffPtr, TIFFTAG_GEODOUBLEPARAMS, &doubleArraySize, &doubleArray))
563  {
564  loadedGeotiff = true;
565  convertArrayToStringList(doubleArrayStr, doubleArray, doubleArraySize);
566  if(!doubleArrayStr.empty())
567  {
568  addValue(dirPrefix+"tifftag.geo_double_params", doubleArrayStr);
569  }
570  }
571  if(TIFFGetField(tiffPtr, TIFFTAG_GEOTRANSMATRIX, &doubleArraySize, &doubleArray))
572  {
573  loadedGeotiff = true;
574  convertArrayToStringList(doubleArrayStr, doubleArray, doubleArraySize);
575  if(!doubleArrayStr.empty())
576  {
577  addValue(dirPrefix+"tifftag.geo_trans_matrix", doubleArrayStr);
578  }
579  }
580  if(TIFFGetField(tiffPtr, TIFFTAG_GEOASCIIPARAMS, &buf))
581  {
582  loadedGeotiff = true;
583  addValue(dirPrefix+"tifftag.geo_ascii_params", buf);
584  }
585  addValue(dirPrefix+"is_geotiff", ossimString::toString(loadedGeotiff));
586  GTIFFree(gtif);
587 }
588 
589 bool ossim::TiffHandlerState::isReduced(ossim_uint32 directory)const
590 {
591  return getInt32Value("tifftag.sub_file_type", directory)&FILETYPE_REDUCEDIMAGE;
592 }
593 
594 bool ossim::TiffHandlerState::isMask(ossim_uint32 directory)const
595 {
596  return getInt32Value("tifftag.sub_file_type", directory)&FILETYPE_MASK;
597 }
598 
599 bool ossim::TiffHandlerState::isPage(ossim_uint32 directory)const
600 {
601  return getInt32Value("tifftag.sub_file_type", directory)&FILETYPE_PAGE;
602 }
603 
604 bool ossim::TiffHandlerState::isTiled(ossim_uint32 directory)const
605 {
606  return checkBool(directory, "is_tiled");
607 }
608 
609 void ossim::TiffHandlerState::convertArrayToStringList(ossimString& result, double* doubleArray, ossim_int32 doubleArraySize)const
610 {
611  ossim_int32 idx = 0;
612  result = "";
613  if(doubleArray && (doubleArraySize > 0))
614  {
615  ossim_int32 precision = 20;
616  std::ostringstream doubleArrayStream;
617  doubleArrayStream << "(";
618  for(idx = 0; idx < doubleArraySize-1;++idx)
619  {
620  doubleArrayStream << ossimString::toString(doubleArray[idx],20) << ",";
621  }
622  doubleArrayStream << ossimString::toString(doubleArray[idx],20) << ")";
623  result = doubleArrayStream.str();
624  }
625 }
626 
627 ossim_int32 ossim::TiffHandlerState::getModelType(ossim_int32 directory)const
628 {
629  return getInt32Value("tifftag.model_type", directory);
630 }
631 
632 ossim_int32 ossim::TiffHandlerState::getAngularUnits(ossim_int32 directory)const
633 {
634  return getInt32Value("tifftag.angular_units", directory);
635 }
636 
637 ossim_int32 ossim::TiffHandlerState::getLinearUnits(ossim_int32 directory)const
638 {
639  return getInt32Value("tifftag.linear_units", directory);
640 }
641 
642 ossim_int32 ossim::TiffHandlerState::getRasterType(ossim_int32 directory)const
643 {
644  return getInt32Value("tifftag.raster_type", directory);
645 }
646 
647 ossim_int32 ossim::TiffHandlerState::getDatumCode(ossim_int32 directory)const
648 {
649  return getInt32Value("tifftag.datum_code", directory);
650 }
651 
652 ossim_int32 ossim::TiffHandlerState::getPcsCode(ossim_int32 directory)const
653 {
654  return getInt32Value("tifftag.pcs_code", directory);
655 }
656 
657 ossim_int32 ossim::TiffHandlerState::getGcsCode(ossim_int32 directory)const
658 {
659 
660  return getInt32Value("tifftag.gcs_code", directory);
661 }
662 
663 ossim_int32 ossim::TiffHandlerState::getInt32Value(const ossimString& key,
664  ossim_int32 directory)const
665 {
666  ossimString tempStr;
667 
668  if(getValue(tempStr, directory, key))
669  {
670  return tempStr.toDouble();
671  }
672 
673  return ossimGeoTiff::UNDEFINED;
674 }
675 
676 
677 ossim_float64 ossim::TiffHandlerState::getDoubleValue(const ossimString& key,
678  ossim_int32 directory)const
679 {
680  ossimString tempStr;
681 
682  if(getValue(tempStr, directory, key))
683  {
684  return tempStr.toDouble();
685  }
686 
687  return ossim::nan();
688 }
689 
690 ossim_float64 ossim::TiffHandlerState::getOriginLat(ossim_int32 directory)const
691 {
692  return getDoubleValue("tifftag.origin_lat", directory);
693 }
694 
695 ossim_float64 ossim::TiffHandlerState::getOriginLon(ossim_int32 directory)const
696 {
697  return getDoubleValue("tifftag.origin_lon", directory);
698 }
699 
700 ossim_float64 ossim::TiffHandlerState::getStandardParallel1(ossim_int32 directory)const
701 {
702  return getDoubleValue("tifftag.std_parallel_1", directory);
703 }
704 
705 ossim_float64 ossim::TiffHandlerState::getStandardParallel2(ossim_int32 directory)const
706 {
707  return getDoubleValue("tifftag.std_parallel_2", directory);
708 }
709 
710 ossim_float64 ossim::TiffHandlerState::getFalseEasting(ossim_int32 directory)const
711 {
712  return getDoubleValue("tifftag.false_easting", directory);
713 }
714 
715 ossim_float64 ossim::TiffHandlerState::getFalseNorthing(ossim_int32 directory)const
716 {
717  return getDoubleValue("tifftag.false_northing", directory);
718 
719 }
720 
721 ossim_float64 ossim::TiffHandlerState::getScaleFactor(ossim_int32 directory)const
722 {
723  return getDoubleValue("tifftag.scale_factor", directory);
724 }
725 
726 ossim_int64 ossim::TiffHandlerState::getImageLength(ossim_int32 directory)const
727 {
728  ossimString tempStr;
729 
730  if(getValue(tempStr, directory, "tifftag.image_length"))
731  {
732  return tempStr.toInt64();
733  }
734 
735  return 0;
736 }
737 
738 ossim_int64 ossim::TiffHandlerState::getImageWidth(ossim_int32 directory)const
739 {
740  ossimString tempStr;
741 
742  if(getValue(tempStr, directory, "tifftag.image_width"))
743  {
744  return tempStr.toInt64();
745  }
746 
747  return 0;
748 }
749 
750 bool ossim::TiffHandlerState::getDoubleArray(std::vector<ossim_float64>& result,
751  ossim_int32 directory,
752  const ossimString& key)const
753 {
754  ossimString tempStr;
755 
756  if(getValue(tempStr, directory, key))
757  {
758  if(!tempStr.empty())
759  {
760  if(!toSimpleVector(result, tempStr))
761  {
762  result.clear();
763  }
764  tempStr="";
765  }
766  }
767 
768  return !result.empty();
769 
770 }
771 
772 bool ossim::TiffHandlerState::getGeoDoubleParams(std::vector<ossim_float64>& result,
773  ossim_int32 directory)const
774 {
775  return getDoubleArray(result, directory, "tifftag.geo_double_params");
776 }
777 
778 bool ossim::TiffHandlerState::getGeoPixelScale(std::vector<ossim_float64>& result,
779  ossim_int32 directory)const
780 {
781  return getDoubleArray(result, directory, "tifftag.geo_pixel_scale");
782 }
783 
784 bool ossim::TiffHandlerState::getGeoTiePoints(std::vector<ossim_float64>& result,
785  ossim_int32 directory)const
786 {
787  return getDoubleArray(result, directory, "tifftag.geo_tie_points");
788 }
789 
790 bool ossim::TiffHandlerState::getGeoTransMatrix(std::vector<ossim_float64>& result,
791  ossim_int32 directory)const
792 {
793  return getDoubleArray(result, directory, "tifftag.geo_trans_matrix");
794 }
795 
796 bool ossim::TiffHandlerState::load(const ossimKeywordlist& kwl,
797  const ossimString& prefix)
798 {
799  bool result = ossim::ImageHandlerState::load(kwl, prefix);
800  m_tags.clear();
801 
802  kwl.extractKeysThatMatch(m_tags, "^("+prefix+"dir[0-9]+)");
803  if(!prefix.empty())
804  {
805  m_tags.stripPrefixFromAll("^("+prefix+")");
806  }
807  ossimString numberOfDirectories = kwl.find(prefix, "number_of_directories");
808 
809  if(!numberOfDirectories.empty()) m_tags.add("number_of_directories", numberOfDirectories, true);
810 
811  return result;
812 }
813 
814 bool ossim::TiffHandlerState::save(ossimKeywordlist& kwl,
815  const ossimString& prefix)const
816 {
817  bool result = ossim::ImageHandlerState::save(kwl, prefix);
818 
819  kwl.add(prefix.c_str(), m_tags);
820 
821  return result;
822 }
void clear()
Erases the entire container.
Definition: ossimString.h:432
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
Represents serializable keyword/value map.
const char * find(const char *key) const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
static ossimString toString(bool aValue)
Numeric to string methods.
static StreamFactoryRegistry * instance()
unsigned short ossim_uint16
bool toSimpleVector(std::vector< T > &result, const ossimString &stringOfPoints)
Definition: ossimCommon.h:537
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool toBool() const
String to numeric methods.
unsigned int ossim_uint32
double toDouble() const
void extractKeysThatMatch(ossimKeywordlist &kwl, const ossimString &regularExpression) const
struct tiff TIFF
long long ossim_int64
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
bool empty() const
Definition: ossimString.h:411
ossim_int64 toInt64() const
virtual std::shared_ptr< ossim::istream > createIstream(const std::string &connectionString, const ossimKeywordlist &options=ossimKeywordlist(), std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary) const
Will try to creates an istream interface to the connectionString passed in.
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
int ossim_int32