source: trunk/thirds/otb2zcfg/otb2zcfg.cxx

Last change on this file was 984, checked in by djay, 3 years ago

Take into account building ZOO-Project on ubuntu focal (cf. https://trac.osgeo.org/osgeolive/ticket/2282). Add the OTB and SAGA support to the Dockerfile to make the corresponding demos using docker WPS server. Add OGC API - Processes demo to the demos list.

  • Property svn:keywords set to Id
File size: 15.8 KB
Line 
1#include "otbWrapperApplicationRegistry.h"
2#include "otbWrapperApplication.h"
3#include "otbImage.h"
4#include <iostream> 
5
6using namespace otb::Wrapper;
7
8std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
9    size_t start_pos = 0;
10    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
11        str.replace(start_pos, from.length(), to);
12        start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
13    }
14    return str;
15}
16
17void printDefaultOutput(){
18  std::cout << "  [Result]" << std::endl;
19  std::cout << "   Title = the result message" << std::endl;
20  std::cout << "   Abstract = the result message" << std::endl;
21  std::cout << "   <LiteralData>" << std::endl;
22  std::cout << "    dataType = string" << std::endl;
23  std::cout << "    <Default />" << std::endl;
24  std::cout << "   </LiteralData>" << std::endl;
25}
26
27void printAscii(){
28  std::cout << "    <Default>" << std::endl;
29  std::cout << "     mimeType = text/plain" << std::endl;
30  std::cout << "     encoding = ascii" << std::endl;
31  std::cout << "    </Default>" << std::endl;
32}
33
34void printXml(){
35  std::cout << "    <Default>" << std::endl;
36  std::cout << "     mimeType = text/xml" << std::endl;
37  std::cout << "     encoding = utf-8" << std::endl;
38  std::cout << "    </Default>" << std::endl;
39}
40
41void printGeoid(){
42  std::cout << "    <Default>" << std::endl;
43  std::cout << "     mimeType = application/octet-stream" << std::endl;
44  std::cout << "    </Default>" << std::endl;
45}
46
47void printCSV(){
48  std::cout << "    <Default>" << std::endl;
49  std::cout << "     mimeType = text/csv" << std::endl;
50  std::cout << "     encoding = utf-8" << std::endl;
51  std::cout << "    </Default>" << std::endl;
52}
53
54void printUnknown(){
55  std::cout << "    <Default>" << std::endl;
56  std::cout << "     mimeType = text/xml" << std::endl;
57  std::cout << "     encoding = utf-8" << std::endl;
58  std::cout << "    </Default>" << std::endl;
59  std::cout << "    <Supported>" << std::endl;
60  std::cout << "     mimeType = text/plain" << std::endl;
61  std::cout << "     encoding = utf-8" << std::endl;
62  std::cout << "    </Supported>" << std::endl;
63}
64
65void printImages(){
66  std::cout << "    <Default>" << std::endl;
67  std::cout << "     mimeType = image/tiff" << std::endl;
68  std::cout << "    </Default>" << std::endl;
69#if defined(OTB_USE_JPEG2000)
70  std::cout << "    <Supported>" << std::endl;
71  std::cout << "     mimeType = image/jp2" << std::endl;
72  std::cout << "    </Supported>" << std::endl;
73#endif
74  std::cout << "    <Supported>" << std::endl;
75  std::cout << "     mimeType = image/jpeg" << std::endl;
76  std::cout << "    </Supported>" << std::endl;
77  std::cout << "    <Supported>" << std::endl;
78  std::cout << "     mimeType = image/png" << std::endl;
79  std::cout << "    </Supported>" << std::endl;
80}
81
82void printKmz(){
83  std::cout << "    <Default>" << std::endl;
84  std::cout << "     mimeType = application/vnd.google-earth.kmz" << std::endl;
85  std::cout << "     extension = kmz" << std::endl;
86  std::cout << "    </Default>" << std::endl;
87}
88
89void printVector(){
90  std::cout << "    <Default>" << std::endl;
91  std::cout << "     mimeType = text/xml" << std::endl;
92  std::cout << "     encoding = utf-8" << std::endl;
93  std::cout << "    </Default>" << std::endl;
94  std::cout << "    <Supported>" << std::endl;
95  std::cout << "     mimeType = application/vnd.google-earth.kml+xml" << std::endl;
96  std::cout << "     encoding = utf-8" << std::endl;
97  std::cout << "    </Supported>" << std::endl;
98  std::cout << "    <Supported>" << std::endl;
99  std::cout << "     mimeType = application/json" << std::endl;
100  std::cout << "     encoding = utf-8" << std::endl;
101  std::cout << "    </Supported>" << std::endl;
102  std::cout << "    <Supported>" << std::endl;
103  std::cout << "     mimeType = application/zip" << std::endl;
104  std::cout << "    </Supported>" << std::endl;
105}
106
107void printOutputImage(ImagePixelType pt){
108  std::cout << "   <LiteralData>" << std::endl;
109  std::cout << "    dataType = string" << std::endl;
110  std::cout << "    <Default>" << std::endl;
111  // Check for the default pixel type
112  switch(pt){
113  case ImagePixelType_uint8:
114    std::cout << "     value = uint8" << std::endl;
115    break;
116  case ImagePixelType_int16:
117    std::cout << "     value = int16" << std::endl;
118    break;
119  case ImagePixelType_uint16:
120    std::cout << "     value = uint16" << std::endl;
121    break;
122  case ImagePixelType_int32:
123    std::cout << "     value = int32" << std::endl;
124    break;
125  case ImagePixelType_uint32:
126    std::cout << "     value = uint8" << std::endl;
127    break;
128  case ImagePixelType_double:
129    std::cout << "     value = uint8" << std::endl;
130    break;
131  default:
132    std::cout << "     value = float" << std::endl;
133    break;
134  }
135  std::cout << "     AllowedValues = uint8,uint16,int16,int32,int32,float,double" << std::endl;
136  std::cout << "    </Default>" << std::endl;
137  std::cout << "   </LiteralData>" << std::endl;
138}
139
140void printOutputComplexImage(ComplexImagePixelType pt){
141  std::cout << "   <LiteralData>" << std::endl;
142  std::cout << "    dataType = string" << std::endl;
143  std::cout << "    <Default>" << std::endl;
144  // Check for the default pixel type
145  switch(pt){
146  case ComplexImagePixelType_double:
147    std::cout << "     value = cdouble" << std::endl;
148    break;
149  default:
150    std::cout << "     value = cfloat" << std::endl;
151    break;
152  }
153  std::cout << "     AllowedValues = cfloat,cdouble" << std::endl;
154  std::cout << "    </Default>" << std::endl;
155  std::cout << "   </LiteralData>" << std::endl;
156}
157
158int main(int itkNotUsed(argc), char * itkNotUsed(argv)[]) 
159{ 
160  typedef otb::Image<unsigned short, 2> ImageType; 
161 
162  ImageType::Pointer image = ImageType::New(); 
163 
164  const char * ITK_AUTOLOAD_PATH = itksys::SystemTools::GetEnv("ITK_AUTOLOAD_PATH");
165  std::cerr << "INFO: Module search path: " << (ITK_AUTOLOAD_PATH ? ITK_AUTOLOAD_PATH : "none (check ITK_AUTOLOAD_PATH)") << std::endl;
166
167  std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications();
168  if (list.size() == 0)
169    std::cerr << "ERROR: no module found." << std::endl;
170  else{
171    std::cerr << "INFO: Available modules :" << std::endl;
172    for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it){
173      std::string filename= *it + ".zcfg";
174      std::ofstream out(filename.c_str(),std::ofstream::out);
175      std::streambuf *coutbuf = std::cout.rdbuf();
176      std::cout.rdbuf(out.rdbuf());
177
178      std::cerr << *it << std::endl;
179      std::cout << "[" << *it << "]" << std::endl;
180      Application::Pointer m_Application=ApplicationRegistry::CreateApplication(*it);
181      std::string s0 = m_Application->GetDescription();
182      s0=ReplaceAll(ReplaceAll(s0,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
183      std::cout << " Title = " << s0 << std::endl;
184      s0 = m_Application->GetDocLongDescription();
185      s0=ReplaceAll(ReplaceAll(s0,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
186      std::cout << " Abstract = " << s0 << std::endl;
187      const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
188      std::cout << " storeSupported = true"<< std::endl;
189      std::cout << " statusSupported = true" << std::endl;
190      std::cout << " serviceProvider = " << *it << std::endl;
191      std::cout << " serviceType = OTB" << std::endl;
192      std::cout << " <DataInputs>" << std::endl;
193      for (unsigned int i = 0; i < appKeyList.size(); i++){
194        const std::string paramKey(appKeyList[i]);
195        Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
196        ParameterType type = m_Application->GetParameterType(paramKey);
197        Role role = m_Application->GetParameterRole(paramKey);
198     
199        if(paramKey!="inxml" && paramKey!="outxml" && role==0 && type!=17 
200           && type!=ParameterType_OutputFilename && type!=ParameterType_OutputVectorData){
201          std::vector<std::string> values;
202          std::string s = m_Application->GetParameterDescription(paramKey);
203          s=ReplaceAll(ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string("")),std::string("<"),std::string("&lt;"));
204          std::cout << "  [" << paramKey << "]" << std::endl;
205          if(s.length()>0){
206            std::cout << "   Title = " << s << std::endl;
207            std::cout << "   Abstract = " << s << std::endl;
208          }else{
209            std::cout << "   Title = " << paramKey << std::endl;
210            std::cout << "   Abstract = " << paramKey << std::endl;
211          }
212          std::cout << "   minOccurs = " << m_Application->IsMandatory(paramKey) << std::endl;
213          /* Bounded and unbounded parameters */
214          if(type == ParameterType_StringList || type == ParameterType_InputImageList
215             || type == ParameterType_InputVectorDataList || type == ParameterType_InputFilenameList
216             || type == ParameterType_ListView)
217            std::cout << "   maxOccurs = 1024" << std::endl;
218          else
219            std::cout << "   maxOccurs = 1" << std::endl;
220          std::replace( s.begin(), s.end(), '\n', ' ');
221         
222          if(type == ParameterType_StringList || type == ParameterType_String || type == ParameterType_Float
223             || type == ParameterType_Int || type == ParameterType_Choice || type == ParameterType_ListView
224             || type == ParameterType_RAM || type == ParameterType_Directory){
225            std::cout << "   <LiteralData>" << std::endl;
226            std::string lt;
227            if(type == ParameterType_Int || type == ParameterType_RAM)
228              lt="integer";
229            if(type == ParameterType_Float)
230              lt="float";
231            if(type == ParameterType_String || type == ParameterType_StringList
232               || type == ParameterType_Choice || type == ParameterType_Directory
233               || type == ParameterType_ListView)
234              lt="string";
235            std::cout << "    dataType = " << lt << std::endl;
236            if(type == ParameterType_Choice || type == ParameterType_ListView){
237              const std::vector<std::string> nList = m_Application->GetChoiceNames(paramKey);
238              const std::vector<std::string> keysList = m_Application->GetChoiceKeys(paramKey);
239              if(keysList.size()==0){
240                std::cout << "    <Default />" << std::endl;
241              }
242              for (unsigned int j = 0; j < keysList.size(); j++){
243                const std::string key(keysList[j]);
244                if(j==0){
245                  std::cout << "    <Default>" << std::endl;
246                  if(m_Application->HasValue(paramKey))
247                    std::cout << "    value = " << m_Application->GetParameterAsString(paramKey) << std::endl;
248                  else
249                    std::cout << "    value = " << key << std::endl;
250                }
251                else{
252                  if(j==1){
253                    std::cout << "    AllowedValues = "+keysList[0]+",";
254                  }
255                  std::cout << keysList[j];
256                  if(j+1>=keysList.size()){
257                    std::cout << std::endl;
258                    std::cout << "    </Default>" << std::endl;
259                  }
260                  else
261                    std::cout << ",";
262                }
263              }
264            }
265            else{
266              if(type!=17 && m_Application->HasValue(paramKey)){
267                std::cout << "    <Default>" << std::endl;
268                std::cout << "     value = " << m_Application->GetParameterAsString(paramKey) << std::endl;
269                std::cout << "    </Default>" << std::endl;
270              }
271              else
272                std::cout << "    <Default />" << std::endl;
273            }
274            std::cout << "   </LiteralData>" << std::endl;
275          }
276          else{
277            if(type == ParameterType_OutputImage){
278              printOutputImage(m_Application->GetParameterOutputImagePixelType(paramKey));
279            }
280            else{
281              {
282                std::cout << "   <ComplexData>" << std::endl;
283                if(type == ParameterType_InputImage || type == ParameterType_InputImageList){
284                  printImages();
285                }
286                else
287                  if(type == ParameterType_InputVectorData || type == ParameterType_InputVectorDataList){
288                    printVector();
289                  }
290                  else
291                    if(type == ParameterType_InputFilename || type == ParameterType_OutputFilename){
292                     
293                      std::string geoid("geoid");
294                      if(paramKey.find(geoid)!= std::string::npos)
295                        printGeoid();
296                      else{
297                        std::string dtype("vector");
298                        std::string descr(m_Application->GetParameterDescription(paramKey));
299                        if(descr.find(dtype)!= std::string::npos)
300                          printVector();
301                        else{
302                          std::string dtype1("ASCII");
303                          if(descr.find(dtype1)!= std::string::npos)
304                            printAscii();
305                          else{
306                            std::string dtype2("XML");
307                            std::string dtype3("xml");
308                            if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos)
309                              printXml();
310                            else
311                              printImages();
312                          }
313                        }
314                      }
315                    }
316                std::cout << "   </ComplexData>" << std::endl;
317              }
318            }
319          }
320
321
322        }
323      }
324      std::cout << " </DataInputs>" << std::endl;
325      std::cout << " <DataOutputs>" << std::endl;
326      int hasOutput=-1;
327      for (unsigned int i = 0; i < appKeyList.size(); i++){
328        const std::string paramKey(appKeyList[i]);
329        std::vector<std::string> values;
330        Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
331        ParameterType type = m_Application->GetParameterType(paramKey);
332        Role role = m_Application->GetParameterRole(paramKey);
333       
334        if(paramKey!="inxml" && paramKey!="outxml" &&
335           ((type == ParameterType_OutputVectorData || type == ParameterType_OutputImage
336             || type == ParameterType_OutputImage
337             || type == ParameterType_OutputFilename) || role==1) && type != ParameterType_Group){
338          hasOutput=1;
339          std::vector<std::string> values;
340          Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
341          ParameterType type = m_Application->GetParameterType(paramKey);
342          Role role = m_Application->GetParameterRole(paramKey);
343          std::cout << "  [" << paramKey << "]" << std::endl;
344          std::string s=m_Application->GetParameterDescription(paramKey);
345          if(s.length()>0){
346            s=ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
347            std::cout << "   Title = " << s << std::endl;
348            std::cout << "   Abstract = " << s << std::endl;
349          }else{
350            std::cout << "   Title = " << paramKey << std::endl;
351            std::cout << "   Abstract = " << paramKey << std::endl;
352          }
353
354          if(type == ParameterType_OutputImage){
355            std::cout << "   <ComplexData>" << std::endl;
356            printImages();
357            std::cout << "   </ComplexData>" << std::endl;
358          }
359          else
360            if(type == ParameterType_OutputVectorData || type == ParameterType_OutputImage){
361              std::cout << "   <ComplexData>" << std::endl;
362              if(type == ParameterType_OutputImage)
363                printImages();
364              else
365                printVector();
366              std::cout << "   </ComplexData>" << std::endl;
367            }
368            else
369              if(type == ParameterType_String || type == ParameterType_StringList
370                 || type == ParameterType_Float || type == ParameterType_Int){
371                std::cout << "   <LiteralData>" << std::endl;
372                std::string lt;
373                if(type == ParameterType_Int)
374                  lt="integer";
375                if(type == ParameterType_Float)
376                  lt="float";
377                if(type == ParameterType_String || type == ParameterType_StringList)
378                  lt="string";
379                std::cout << "    dataType = " << lt << std::endl;
380                std::cout << "    <Default />" << std::endl;
381                std::cout << "   </LiteralData>" << std::endl;
382              }
383              else
384                if(type == ParameterType_OutputFilename){
385                  std::cout << "   <ComplexData>" << std::endl;
386                  std::string descr(m_Application->GetParameterDescription(paramKey));
387                  std::string dtype("csv");
388                  std::string dtype1("CSV");
389                  if(descr.find(dtype)!= std::string::npos || descr.find(dtype1)!= std::string::npos)
390                    printCSV();
391                  else{
392                    std::string dtype2("text file");
393                    if(descr.find(dtype2)!= std::string::npos)
394                      printAscii();
395                    else{
396                      std::string dtype2("XML");
397                      std::string dtype3("xml");
398                      if(descr.find(dtype2)!= std::string::npos || descr.find(dtype3)!= std::string::npos)
399                        printXml();
400                      else{
401                        std::string dtype4("vector");
402                        std::string dtype5("Vector");
403                        if(descr.find(dtype4)!= std::string::npos || descr.find(dtype5)!= std::string::npos)
404                          printVector();
405                        else{
406                          std::string dtype6("kmz");
407                          std::string dtype7("Kmz");
408                          if(descr.find(dtype6)!= std::string::npos || descr.find(dtype6)!= std::string::npos)
409                            printKmz();
410                          else
411                            printUnknown();
412                        }
413                      }
414                    }
415                  }
416                  std::cout << "   </ComplexData>" << std::endl;
417                }
418        }
419      }
420      if(hasOutput<0)
421        printDefaultOutput();
422      std::cout << " </DataOutputs>" << std::endl;
423      std::cout.rdbuf(coutbuf);
424    }
425  }
426 
427  return EXIT_SUCCESS; 
428}
429
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png