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 202 203 204 205 206 207 208 209 210
|
/*=========================================================================
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.
=========================================================================*/
// Software Guide : BeginLatex
//
// This example demonstrates the use of the
// \doxygen{otb}{KmzProductWriter} and the
// \doxygen{otb}{MapFileProductWriter}.
// The first filter is intended to produce Kmz file (Google Earth
// Readable), and the second one is intended to produce map files
// callable through a WMS (Web Map Service) service. In this example
// we will use a file with no meta-data, use the
// \doxygen{otb}{GGCPToRPCSensorModelImageFilter} in order to
// approximate a rpc model, and then use our filters to produce a kmz
// and MapFile products.
// Note that the \doxygen{otb}{KmzProductWriter} and the
// \doxygen{otb}{MapFileProductWriter} can only process inputs with a
// non empty geographical information.
//
// The first step toward the use of these filters is to include the
// proper header files: the one for the rpc sensor estimation filter and
// the one defining the procedure for creating kmz files and finally
// the header concerning the MapProduct writer.
//
// Software Guide : EndLatex
#include "otbMacro.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
// Software Guide : BeginCodeSnippet
#include "otbKmzProductWriter.h"
#include "otbMapFileProductWriter.h"
#include "otbGCPsToRPCSensorModelImageFilter.h"
// Software Guide : EndCodeSnippet
//
int main(int argc, char* argv[])
{
if (argc < 6)
{
std::cerr << "Usage: " << argv[0]
<< " infname outfname kmzFileName "
<<"a1x a1y b1x b1y b1z ... aNx aNy aNz bNx bNy bNz" << std::endl;
return EXIT_FAILURE;
}
else if ((argc - 7) % 5 != 0)
{
std::cerr << "Inconsistent GCPs description!" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : BeginLatex
//
// We will start by defining the types for the image and the image file
// reader.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::VectorImage<float, 2> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
otb::DEMHandler::Instance()->OpenDEMDirectory(argv[6]);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We can now proceed to declare the type for the rpc sensor model
// estimation filter. The class \doxygen{otb}{GGCPToRPCSensorModelImageFilter} is
// templated over the input image type.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::GCPsToRPCSensorModelImageFilter<ImageType> GCPsToSensorModelFilterType;
typedef GCPsToSensorModelFilterType::Point2DType Point2DType;
typedef GCPsToSensorModelFilterType::Point3DType Point3DType;
GCPsToSensorModelFilterType::Pointer rpcEstimator = GCPsToSensorModelFilterType::New();
rpcEstimator->SetInput(reader->GetOutput());
// Software Guide : EndCodeSnippet
unsigned int nbGCPs = (argc - 6) / 5;
std::cout << "Receiving " << nbGCPs << " from command line." << std::endl;
for (unsigned int gcpId = 0; gcpId < nbGCPs; ++gcpId)
{
// Software Guide : BeginLatex
//
// Here, we set all the Ground Control Points associated to the image
// indexes. This is the entry of the rpc sensor model
// estimator. Every time a GCP is added, the output image information
// or its keywordlist is updated. In general, a dozen of GCPs are
// needed to estimate an accurate sensor model. The points are added
// via the method AddGCP(PointType2D, PointType3D). The outpput image
// obtained have the needed meta-data information for the rest of the
// process.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
Point2DType sensorPoint;
sensorPoint[0] = atof(argv[7 + gcpId * 5]);
sensorPoint[1] = atof(argv[8 + gcpId * 5]);
Point3DType geoPoint;
geoPoint[0] = atof(argv[9 + 5 * gcpId]);
geoPoint[1] = atof(argv[10 + 5 * gcpId]);
geoPoint[2] = atof(argv[11+ 5 * gcpId]);
rpcEstimator->AddGCP(sensorPoint, geoPoint);
// Software Guide : EndCodeSnippet
std::cout << "Adding GCP sensor: " << sensorPoint << " <-> geo: " << geoPoint << std::endl;
}
rpcEstimator->GetOutput()->UpdateOutputInformation();
std::cout << "Residual ground error: " << rpcEstimator->GetRMSGroundError() << std::endl;
// Software Guide : BeginLatex
//
// The last step of the chain, is to export the image to a Google
// Earth understandable format using the KmzProductWriter. Note that
// the writer can add legends via the method
// AddLegend(std::string description, ImageType * legend) and a logo in
// the kmz using SetLogo(ImageType*).
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::KmzProductWriter<ImageType> KmzProductWriterType;
KmzProductWriterType::Pointer kmzWriter = KmzProductWriterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Finally, we trigger the kmz writing by calling the \code{Update()}
// method on the writer.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
kmzWriter->SetInput(rpcEstimator->GetOutput());
kmzWriter->SetPath(argv[2]);
kmzWriter->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The Mapfile is the heart of MapServer. It defines the relationships
// between objects, points MapServer (http://mapserver.org/) to where
// data are located and defines how things are to be drawn. The class
// \doxygen{otb}{MapFileProductWriter} allow producing the mapserver
// configuration file, the tiles to draw, and shapefiles describing
// the tiles and where to find them.
// The Mapfile writer allow setting the complete path to the mapfile
// via SetFileName(std::string), the path where to store the tiles via
// the method SetShapeIndexPath() and finally the path to the cgi-bin
// to use via the method SetGCIPath().
//
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::MapFileProductWriter<ImageType> MapFileProductWriterType;
MapFileProductWriterType::Pointer mapWriter = MapFileProductWriterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The user can also specify a Spatial Reference System Identifier
// (SRID) to choose his projection. In this example we choose WGS84 to
// project our datas in. The SRID relative to WGS84 is 4326.
// Finally, we trigger the MapFile writing by calling the
// \code{Update()} method on the writer.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
mapWriter->SetInput(rpcEstimator->GetOutput());
mapWriter->SetFileName(argv[3]);
mapWriter->SetShapeIndexPath(argv[4]);
mapWriter->SetCGIPath(argv[5]);
mapWriter->SetSRID(4326);
mapWriter->Update();
// Software Guide : EndCodeSnippet
return EXIT_SUCCESS;
}
|