File: otbVectorDataReprojection.cxx

package info (click to toggle)
otb 5.8.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,496 kB
  • ctags: 40,282
  • sloc: cpp: 306,573; ansic: 3,575; python: 450; sh: 214; perl: 74; java: 72; makefile: 70
file content (201 lines) | stat: -rw-r--r-- 7,026 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*=========================================================================

 Program:   ORFEO Toolbox
 Language:  C++
 Date:      $Date$
 Version:   $Revision$


 Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
 See OTBCopyright.txt for details.


 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.

 =========================================================================*/
#include "otbWrapperApplicationFactory.h"
#include "otbWrapperNumericalParameter.h"
#include "otbGeometriesProjectionFilter.h"
#include "otbGeometriesSet.h"


// MapProjection handler
#include "otbWrapperMapProjectionParametersHandler.h"

// Elevation handler
#include "otbWrapperElevationParametersHandler.h"

namespace otb
{


namespace Wrapper
{

class VectorDataReprojection : public Application
{
public:
  /** Standard class typedefs. */
  typedef VectorDataReprojection Self;
  typedef Application Superclass;
  typedef itk::SmartPointer<Self> Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;

  /** filter typedef  **/
  typedef otb::GeometriesProjectionFilter ProjectionFilterType;

  typedef otb::GeometriesSet InputGeometriesType;
  typedef otb::GeometriesSet OutputGeometriesType;

  /** Standard macro */
  itkNewMacro(Self)
;

  itkTypeMacro(VectorDataReprojection, otb::Application)
;

private:
  void DoInit() ITK_OVERRIDE
  {
    SetName("VectorDataReprojection");
    std::ostringstream oss;
    oss << "Reproject a vector data using support image projection reference"
        ", or a user specified map projection" << std::endl;
    SetDescription(oss.str());
    // Documentation
    SetDocName("Vector Data reprojection");
    oss.str("");
    oss <<" This application allows reprojecting a vector data using support image projection reference"
        ", or a user given map projection." << std::endl;
    oss <<" If given, image keywordlist can be added to reprojected vectordata.";
    SetDocLongDescription(oss.str());
    SetDocLimitations(" ");
    SetDocAuthors("OTB-Team");
    SetDocSeeAlso(" ");

    AddDocTag(Tags::Geometry);
    AddDocTag(Tags::Vector);
    AddDocTag(Tags::Coordinates);

    // Set the parameters

    AddParameter(ParameterType_Group, "in", "Input data");
    AddParameter(ParameterType_InputFilename, "in.vd", "Input vector data");
    SetParameterDescription("in.vd", "The input vector data to reproject");
    AddParameter(ParameterType_InputImage, "in.kwl", "Use image keywords list");
    SetParameterDescription("in.kwl", "Optional input image to fill vector data with image kwl.");
    MandatoryOff("in.kwl");
    DisableParameter("in.kwl");

    AddParameter(ParameterType_Group, "out", "Output data");
    AddParameter(ParameterType_OutputFilename, "out.vd", "Output vector data");
    SetParameterDescription("out.vd", "The reprojected vector data");

    // output projection choice
    AddParameter(ParameterType_Choice, "out.proj", "Output Projection choice");
    AddChoice("out.proj.image", "Use image projection ref");
    SetParameterDescription("out.proj.image", "Vector data will be reprojected in image projection ref.");
    AddParameter(ParameterType_InputImage, "out.proj.image.in", "Image used to get projection map");
    SetParameterDescription("out.proj.image.in", "Projection map will be found using image metadata");
    AddChoice("out.proj.user", "User defined projection");
    MapProjectionParametersHandler::AddMapProjectionParameters(this, "out.proj.user.map");

    // Elevation
    ElevationParametersHandler::AddElevationParameters(this, "elev");

    // Doc example parameter settings
    SetDocExampleParameterValue("in.vd", "VectorData_QB1.shp");
    SetDocExampleParameterValue("out.proj", "image");
    SetDocExampleParameterValue("out.proj.image.in", "ROI_QB_MUL_1.tif");
    SetDocExampleParameterValue("out.vd","reprojected_vd.shp");
  }

  void DoUpdateParameters() ITK_OVERRIDE
  {

  }

  void DoExecute() ITK_OVERRIDE
  {
    GetLogger()->Debug("Entering DoExecute\n");

    // Setup the DEM Handler
    otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev");

    // Get the input image

    otb::ogr::DataSource::Pointer OGRDSin = otb::ogr::DataSource::New(GetParameterString("in.vd"),
                                                                      otb::ogr::DataSource::Modes::Read);

    m_InputGeomSet = InputGeometriesType::New(OGRDSin);

    // Filter instantiation
    m_GeometriesProjFilter = ProjectionFilterType::New();
    m_GeometriesProjFilter->SetInput(m_InputGeomSet);

    if (HasValue("in.kwl"))
      {
      FloatVectorImageType::Pointer inImage = GetParameterFloatVectorImage("in.kwl");
      m_GeometriesProjFilter->SetInputOrigin(inImage->GetOrigin()); // nec qd capteur
      m_GeometriesProjFilter->SetInputSpacing(inImage->GetSpacing()); // nec qd capteur
      m_GeometriesProjFilter->SetInputKeywordList(inImage->GetImageKeywordlist());
      //otbAppLogINFO(<<"kwl."<<std::endl);
      }

    if (GetParameterInt("out.proj") == 0)
      {
      FloatVectorImageType::Pointer outImage = GetParameterFloatVectorImage("out.proj.image.in");

      if (outImage)
        {
        m_GeometriesProjFilter->SetOutputOrigin(outImage->GetOrigin()); // nec qd capteur
        m_GeometriesProjFilter->SetOutputSpacing(outImage->GetSpacing()); // nec qd capteur
        m_OutputProjectionRef = outImage->GetProjectionRef(); // ~ wkt
        if (m_OutputProjectionRef.empty())
          {
            m_GeometriesProjFilter->SetOutputKeywordList(outImage->GetImageKeywordlist()); // nec qd capteur
          }
        }
      else
        {
        // LogFATAl
        }
      }
    else
      {

      // Get the output projection Ref
      m_OutputProjectionRef = MapProjectionParametersHandler::GetProjectionRefFromChoice(this, "out.proj.user.map");

      }
    otbAppLogINFO(<<"Geometries reprojection with following projection reference :"
        <<std::endl<<m_OutputProjectionRef<<std::endl);

    m_GeometriesProjFilter->SetOutputProjectionRef(m_OutputProjectionRef);

    OGRDSout = otb::ogr::DataSource::New(GetParameterString("out.vd"),
                                         otb::ogr::DataSource::Modes::Update_LayerOverwrite);

    m_OutputGeomSet = OutputGeometriesType::New(OGRDSout);

    m_GeometriesProjFilter->SetOutput(m_OutputGeomSet);
    m_GeometriesProjFilter->Update();
    OGRDSout->SyncToDisk();
  }

  otb::ogr::DataSource::Pointer OGRDSout;
  std::string m_OutputProjectionRef;
  ImageKeywordlist m_KeywordList;
  InputGeometriesType::Pointer m_InputGeomSet;
  OutputGeometriesType::Pointer m_OutputGeomSet;
  //FloatVectorImageType::Pointer m_inImage;
 // FloatVectorImageType::Pointer m_outImage;
  ProjectionFilterType::Pointer m_GeometriesProjFilter;
};

  } // namespace Wrapper
} // namespace otb

OTB_APPLICATION_EXPORT(otb::Wrapper::VectorDataReprojection)