src/terralib/ws/core/Utils.cpp
Go to the documentation of this file.
1 #include "Utils.h"
2 
3 #include "../../common/StringUtils.h"
4 #include "../../core/translator/Translator.h"
5 #include "Exception.h"
6 
7 //BOOST
8 #include <boost/algorithm/string.hpp>
9 #include <boost/lexical_cast.hpp>
10 
11 #include <sys/stat.h>
12 
14 {
16 
17  std::vector<std::string> formatSplit = te::common::SplitString(format, '/');
18 
19  if(formatSplit.size() != 2)
20  {
21  throw te::ws::core::Exception() << te::ErrorDescription(TE_TR("Format conversion failed. Image format not supported."));
22  }
23 
24  std::string posfix = formatSplit[1];
25 
26  if(boost::iequals(posfix, "png"))
27  {
28  imageType = te::map::ImageType::PNG;
29  }
30  else if(boost::iequals(posfix, "tiff"))
31  {
32  imageType = te::map::ImageType::TIFF;
33  }
34  else if(boost::iequals(posfix, "bmp"))
35  {
36  imageType = te::map::ImageType::BMP;
37  }
38  else if(boost::iequals(posfix, "jpeg") || boost::iequals(posfix, "jpg"))
39  {
40  imageType = te::map::ImageType::JPEG;
41  }
42 
43  return imageType;
44 }
45 
46 bool te::ws::core::IsInvertedEPSG(const std::string &epsg)
47 {
48  std::vector<std::string> epsgSplit = te::common::SplitString(epsg, ':');
49 
50  if(epsgSplit.size() != 2)
51  {
52  throw te::ws::core::Exception() << te::ErrorDescription(TE_TR("EPSG could not be read."));
53  }
54 
55  std::string codeStr = epsgSplit[1];
56 
57  int code = boost::lexical_cast<int>(codeStr);
58 
59  if(code < 4000 || code > 5000)
60  {
61  return false;
62  }
63 
64  return true;
65 }
66 
67 long te::ws::core::GetFileSize(const std::string &filename)
68 {
69  struct stat stat_buf;
70  int rc = stat(filename.c_str(), &stat_buf);
71  return rc == 0 ? stat_buf.st_size : -1;
72 }
ImageType
This enum specifies the possible input and output image formats supported by the canvas API...
Utils of WS Core Runtime Library.
TECOMMONEXPORT std::vector< std::string > SplitString(const std::string &str, const char &delimiter)
Definition: StringUtils.cpp:32
TEWSCOREEXPORT bool IsInvertedEPSG(const std::string &epsg)
This function gets true for EPSGs that has inverted axis-order. Otherwise false. This implementation ...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
TEWSCOREEXPORT long GetFileSize(const std::string &filename)
This function gets the size of a file, using C runtime stat struct that works on Windows, Mac and Linux.
TEWSCOREEXPORT te::map::ImageType FormatToImageType(const std::string &format)
This function gets an ImageType Enum according to an image format string (e.g. image/png).
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
Base exception class for WS Core Runtime Library.
Exception classes for the WS Core Runtime Library.