27 #include "../../../dataaccess/datasource/DataSource.h" 28 #include "../../../dataaccess/datasource/DataSourceCapabilities.h" 29 #include "../../../dataaccess/datasource/DataSourceFactory.h" 30 #include "../../../srs/SpatialReferenceSystemManager.h" 31 #include "../../../core/filesystem/FileSystem.h" 32 #include "../../../common/StringUtils.h" 33 #include "../srs/SRSManagerDialog.h" 34 #include "../utils/ParameterTableWidget.h" 36 #include "../utils/FileDialog.h" 37 #include "../Exception.h" 39 #include "ui_RasterInfoWidgetForm.h" 40 #include "ui_ParameterTableWidgetForm.h" 43 #include <QFileDialog> 45 #include <QMessageBox> 48 #include <boost/tokenizer.hpp> 49 #include <boost/lexical_cast.hpp> 50 #include <boost/filesystem.hpp> 57 const bool outputMode,
58 QWidget* parent, Qt::WindowFlags f)
60 m_outputMode( outputMode ),
61 m_ui(new
Ui::RasterInfoWidgetForm)
65 QGridLayout* layout =
new QGridLayout(
m_ui->m_widget);
67 layout->addWidget(
m_table.get());
68 layout->setContentsMargins(0,0,0,0);
70 m_ui->m_openFileDlgToolButton->setIcon(QIcon::fromTheme(
"file-raster"));
71 m_ui->m_openSRIDDlgToolButton->setIcon(QIcon::fromTheme(
"srs"));
73 m_table->getForm()->m_parameterTitle->setText(tr(
"Extra parameters"));
77 m_ui->m_forceRAWRastercheckBox->setEnabled(
false );
81 m_ui->m_forceRAWRastercheckBox->setEnabled(
true );
91 connect(
m_ui->m_rowsLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
92 connect(
m_ui->m_columnsLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
93 connect(
m_ui->m_bandsLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
94 connect(
m_ui->m_dataTypeComboBox, SIGNAL(currentTextChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
96 connect(
m_ui->m_resolutionXLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
97 connect(
m_ui->m_resolutionYLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
98 connect(
m_ui->m_sridLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
100 connect(
m_ui->m_upperLeftXLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
101 connect(
m_ui->m_upperLeftYLineEdit, SIGNAL(textChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
102 connect(
m_ui->m_byteOrderComboBox, SIGNAL(currentTextChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
104 connect(
m_ui->m_interleaveComboBox, SIGNAL(currentTextChanged(
const QString &)),
this, SLOT(
rawRasterInfoChanged(
const QString &)));
122 std::map<std::string, std::string> rinfo;
124 rinfo[
"URI"] =
m_ui->m_fileNameLineEdit->text().toUtf8().data();
128 std::map<std::string, std::string> extra =
m_table->getMap();
130 rinfo.insert(extra.begin(), extra.end());
137 std::map<std::string, std::string> rinfo;
139 boost::filesystem::path path(
m_ui->m_fileNameLineEdit->text().toUtf8().data() );
143 std::string fileName =
144 path.parent_path().string()
146 + path.stem().string()
147 + std::string(
"_" );
154 + std::string(
"_" );
159 + boost::lexical_cast< std::string >( count )
160 + path.extension().string();
162 rinfo[
"URI"] = fileName;
166 std::map<std::string, std::string> extra =
m_table->getMap();
168 rinfo.insert(extra.begin(), extra.end());
175 boost::filesystem::path path(
m_ui->m_fileNameLineEdit->text().toUtf8().data());
177 const std::string connInfoRaster(
"file://" + path.parent_path().string());
187 boost::filesystem::path path(
m_ui->m_fileNameLineEdit->text().toUtf8().data() );
188 return path.filename().string();
193 boost::filesystem::path path(
m_ui->m_fileNameLineEdit->text().toUtf8().data() );
194 std::string name = path.filename().string();
196 std::size_t pos = name.find_last_of(
".");
197 if(pos != std::string::npos)
199 name = name.substr(0, pos);
207 return m_ui->m_fileNameLineEdit->text().toUtf8().data();
212 boost::filesystem::path path(
m_ui->m_fileNameLineEdit->text().toUtf8().data() );
213 return path.extension().string();
218 boost::filesystem::path path(
m_ui->m_fileNameLineEdit->text().toUtf8().data() );
219 return path.parent_path().string();
224 boost::filesystem::path path(
m_ui->m_fileNameLineEdit->text().toUtf8().data() );
230 m_ui->m_rasterPropertiesFrame->setVisible(
false);
235 m_ui->m_nameLineEdit->clear();
236 m_ui->m_fileNameLineEdit->clear();
249 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
268 m_ui->m_nameLineEdit->setText(fullFilePath.stem().string().c_str());
279 m_ui->m_sridLineEdit->clear();
301 if( state == Qt::Unchecked )
323 m_ui->m_forceRAWRastercheckBox->isChecked()
330 if( upCaseExtension !=
".VRT" )
334 std::string vrtFullFileName = fullFilePath.string();
335 std::size_t pos = vrtFullFileName.find_last_of(
".");
336 if(pos != std::string::npos)
338 vrtFullFileName = vrtFullFileName.substr(0, pos);
340 vrtFullFileName = vrtFullFileName +
".vrt";
342 boost::filesystem::path fullVrtPath( vrtFullFileName );
348 const unsigned int bandsNumber =
m_ui->m_bandsLineEdit->text().toUInt();
349 const unsigned int colsNumber =
m_ui->m_columnsLineEdit->text().toUInt();
350 const unsigned int rowsNumber =
m_ui->m_rowsLineEdit->text().toUInt();
351 const double resX =
m_ui->m_resolutionXLineEdit->text().toDouble();
352 const double resY =
m_ui->m_resolutionYLineEdit->text().toDouble();
353 const double upperLeftX =
m_ui->m_upperLeftXLineEdit->text().toDouble();
354 const double upperLeftY =
m_ui->m_upperLeftYLineEdit->text().toDouble();
355 const int SRID =
m_ui->m_sridLineEdit->text().toInt();
356 const std::string byteOrder =
m_ui->m_byteOrderComboBox->currentText().toUtf8().data();
357 const std::string dataTypeString =
m_ui->m_dataTypeComboBox->currentText().toUtf8().data();
358 const std::string interleaveString =
m_ui->m_interleaveComboBox->currentText().toUtf8().data();
360 unsigned int dataTypeSizeBytes = 0;
361 if( dataTypeString ==
"Byte" )
363 dataTypeSizeBytes = 1;
365 else if( dataTypeString ==
"UInt16" )
367 dataTypeSizeBytes = 2;
369 else if( dataTypeString ==
"Int16" )
371 dataTypeSizeBytes = 2;
373 else if( dataTypeString ==
"UInt32" )
375 dataTypeSizeBytes = 4;
377 else if( dataTypeString ==
"Int32" )
379 dataTypeSizeBytes = 4;
381 else if( dataTypeString ==
"Float32" )
383 dataTypeSizeBytes = 4;
385 else if( dataTypeString ==
"Float64" )
387 dataTypeSizeBytes = 8;
389 else if( dataTypeString ==
"CInt16" )
391 dataTypeSizeBytes = 4;
393 else if( dataTypeString ==
"CInt32" )
395 dataTypeSizeBytes = 8;
397 else if( dataTypeString ==
"CFloat32" )
399 dataTypeSizeBytes = 8;
401 else if( dataTypeString ==
"CFloat64" )
403 dataTypeSizeBytes = 16;
407 throw te::qt::widgets::Exception(
"Invalid data type" );
410 std::ofstream vrtfile;
411 vrtfile.open ( vrtFullFileName.c_str() );
413 if( !vrtfile.is_open() )
415 QMessageBox::critical(
this,
"Error",
"Unable to create a VRT file" );
420 vrtfile.precision( 20 );
423 <<
"<VRTDataset rasterXSize=\"" << colsNumber <<
"\"" 424 <<
" rasterYSize=\"" << rowsNumber <<
"\"" 431 if( ! wktStr.empty() )
433 vrtfile << std::endl <<
"<SRS>" << wktStr <<
"</SRS>";
437 if( ( resX != 0.0 ) && ( resY != 0.0 ) )
439 vrtfile << std::endl <<
"<GeoTransform>" << upperLeftX <<
"," 440 << resX <<
",0," << upperLeftY <<
",0," << (-1.0 * resY)
441 <<
"</GeoTransform>";
444 unsigned int pixelOffset = 0;
445 unsigned int lineOffset = 0;
446 unsigned int imageOffset = 0;
448 for(
unsigned int bandIdx = 0 ; bandIdx < bandsNumber ; ++bandIdx )
451 if( interleaveString ==
"BIP" )
453 pixelOffset = dataTypeSizeBytes * bandsNumber;
454 lineOffset = pixelOffset * colsNumber;
455 imageOffset = bandIdx * dataTypeSizeBytes;
461 pixelOffset = dataTypeSizeBytes;
462 lineOffset = pixelOffset * colsNumber;
463 imageOffset = bandIdx * lineOffset * rowsNumber;
468 <<
"<VRTRasterBand dataType=\"" << dataTypeString <<
"\" band=\"" << ( bandIdx + 1 )<<
"\" subClass=\"VRTRawRasterBand\">" << std::endl
469 <<
"<SourceFilename relativetoVRT=\"1\">" << fullFilePath.filename().string() <<
"</SourceFilename>" << std::endl
470 <<
"<ImageOffset>" << imageOffset <<
"</ImageOffset>" << std::endl
471 <<
"<PixelOffset>" << pixelOffset <<
"</PixelOffset>" << std::endl
472 <<
"<LineOffset>" << lineOffset <<
"</LineOffset>";
474 if( !byteOrder.empty() ) vrtfile << std::endl <<
"<ByteOrder>" << byteOrder <<
"</ByteOrder>" << std::endl;
476 vrtfile << std::endl <<
"</VRTRasterBand>";
479 vrtfile << std::endl <<
"</VRTDataset>" << std::endl;
481 m_ui->m_fileNameLineEdit->setText( vrtFullFileName.c_str() );
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
virtual const char * what() const
It outputs the exception message.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
static bool remove(const std::string &path)
Removes a file or directory from a given path in UTF-8.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
static bool isRegularFile(const std::string &path)
Checks if a given path in UTF-8 is a regular file.