[QGIS Commit] r9404 - in trunk/external_plugins/cdp2/src: lib tests
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Sep 24 12:35:10 EDT 2008
Author: timlinux
Date: 2008-09-24 12:35:10 -0400 (Wed, 24 Sep 2008)
New Revision: 9404
Modified:
trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.cpp
trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.h
trunk/external_plugins/cdp2/src/lib/climatefilereader.cpp
trunk/external_plugins/cdp2/src/lib/climatefilereader.h
trunk/external_plugins/cdp2/src/tests/cdptest.cpp
Log:
Softcode header calcs
Modified: trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.cpp
===================================================================
--- trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.cpp 2008-09-24 14:00:55 UTC (rev 9403)
+++ trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.cpp 2008-09-24 16:35:10 UTC (rev 9404)
@@ -467,11 +467,12 @@
}
myCurrentFileName+="."+myExtension;
qDebug( "initialiseFileGroup - opening file : " + myCurrentFileName.toLocal8Bit() );
- ClimateFileReader *myClimateFileReader = new ClimateFileReader();
- myClimateFileReader->initialise(myCurrentFileName,mInputFileType);
+ ClimateFileReader *mypClimateFileReader = new ClimateFileReader();
+ mypClimateFileReader->initialise(myCurrentFileName,mInputFileType);
+ mOutputHeader=mypClimateFileReader->getAsciiHeader();
qDebug( "initialiseFileGroup - *** Adding " + myCurrentFileName.toLocal8Bit()
+ " to file group *********************" );
- myFileGroup->add(myClimateFileReader);
+ myFileGroup->add(mypClimateFileReader);
}
@@ -931,6 +932,7 @@
myNumberOfVariablesInt++;
}
}
+ makeFileGroups();
//
//work out how many cells need to be processed for each calculations
//
@@ -1018,39 +1020,10 @@
//set the extension
myFileName = mOutputPath + myFileName + ".asc";
FileWriter * myFileWriter = new FileWriter(myFileName,mOutputFileType);
+ // add check to make sure header was initialised
+ myFileWriter->writeString(mOutputHeader);
- //Use externally defined header if its been set
- if (!mOutputHeader.isEmpty())
- {
- myFileWriter->writeString(mOutputHeader);
- }
- //Otherwise calculate one dynamically
- else
- {
- // Use the matrix dimensions to create the ascii file
- // Warning: this assumes a GLOBAL dataset
- // Warning: this screws up cellsizes that are not square
- // Warning: this only works for integers at present
- QString myHeader(
- "ncols " + QString::number (myXDimInt) + "\n" +
- "nrows " + QString::number (myYDimInt) + "\n" +
- "xllcorner -180\n" +
- "yllcorner -90\n"+
- "cellsize " + QString::number (360/static_cast<float>(myXDimInt)) + "\n" +
- "nodata_value -9999.5\n");
- qDebug("Header:" + myHeader.toLocal8Bit());
- myFileWriter->writeString(myHeader);
- // Formerly this was fixed to the following
- //QString myHeader=
- //QString ("ncols 720\n")+
- //QString ("nrows 360\n")+
- //QString ("xllcorner -180\n")+
- //QString ("yllcorner -90\n")+
- //QString ("cellsize 0.5\n")+
- //QString ("nodata_value -9999\n"); myFileWriter->writeString(myHeader);
- }
-
qDebug( "Added " + myFileWriter->fileName().toLocal8Bit() );
FileWriterStruct myFileWriterStruct;
myFileWriterStruct.fileWriter=myFileWriter;
Modified: trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.h
===================================================================
--- trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.h 2008-09-24 14:00:55 UTC (rev 9403)
+++ trunk/external_plugins/cdp2/src/lib/climatedataprocessorcontroller.h 2008-09-24 16:35:10 UTC (rev 9404)
@@ -161,7 +161,7 @@
* @return a QString containing the filename (which will be the first file
* in the series if the files are in series).
*/
- const QString windSpeedFileName ();
+ const QString windSpeedFileName ();
/** Mutator for directory name for the calculation output files.
* @param theFilePath - The name of an existing directory where the
@@ -274,11 +274,6 @@
const FileWriter::FileType outputFileType();
- /**
- * Set up the filegroups for each filename that has been registered
- * @return bool - A boolean indicating success or failure of the operation
- */
- bool makeFileGroups();
/** Build a list of which calculations can be performed given the input files
* that have been registered. The boolean field indicates whether the user actually
@@ -409,6 +404,11 @@
private:
// Private methods
+ /**
+ * Set up the filegroups for each filename that has been registered
+ * @return bool - A boolean indicating success or failure of the operation
+ */
+ bool makeFileGroups();
/** This method is intended for debugging purposes only */
void printVectorAndResult(QVector<float> theVector, float theResult);
Modified: trunk/external_plugins/cdp2/src/lib/climatefilereader.cpp
===================================================================
--- trunk/external_plugins/cdp2/src/lib/climatefilereader.cpp 2008-09-24 14:00:55 UTC (rev 9403)
+++ trunk/external_plugins/cdp2/src/lib/climatefilereader.cpp 2008-09-24 16:35:10 UTC (rev 9404)
@@ -641,3 +641,100 @@
}
}
}
+const QString ClimateFileReader::getWorldFile()
+{
+ QString myHeader;
+ if (mFileType==GDAL)
+ {
+ GDALDataset *gdalDataset = (GDALDataset *) GDALOpen( mFileName.toLocal8Bit(), GA_ReadOnly );
+ if ( gdalDataset == NULL )
+ {
+ return QString("");
+ }
+ //get the geotransform stuff from gdal
+ double myTransform[6];
+ if (gdalDataset->GetGeoTransform(myTransform) != CE_None)
+ {
+ std::cout << "Failed to get geo transform from GDAL, aborting" << std::endl;
+ GDALClose(gdalDataset);
+ return QString("");
+ }
+ else
+ {
+ GDALClose(gdalDataset);
+ }
+
+ myHeader += "Pixel XDim " + QString::number(myTransform[1]) + "\r\n";
+ myHeader += "Rot 0 \r\n";
+ myHeader += "Rot 0 \r\n";
+ myHeader += "Pixel YDim " + QString::number(myTransform[5]) + "\r\n";
+ myHeader += "Origin X " + QString::number(myTransform[0]) + "\r\n";
+ myHeader += "Origin Y " + QString::number(myTransform[3]) + "\r\n";
+ }
+ return myHeader;
+}
+
+const QString ClimateFileReader::getAsciiHeader()
+{
+ QString myHeader;
+ if (mFileType==GDAL)
+ {
+ GDALDataset *gdalDataset = (GDALDataset *) GDALOpen( mFileName.toLocal8Bit(), GA_ReadOnly );
+ if ( gdalDataset == NULL )
+ {
+ return QString("");
+ }
+
+ //get dimesnions and no data value
+ int myColsInt = gdalDataset->GetRasterXSize();
+ int myRowsInt = gdalDataset->GetRasterYSize();
+ double myNullValue=gdalDataset->GetRasterBand(1)->GetNoDataValue();
+ //get the geotransform stuff from gdal
+ double myTransform[6];
+ if (gdalDataset->GetGeoTransform(myTransform) != CE_None)
+ {
+ std::cout << "Failed to get geo transform from GDAL, aborting" << std::endl;
+ GDALClose(gdalDataset);
+ return QString("");
+ }
+ else
+ {
+ GDALClose(gdalDataset);
+ }
+
+
+
+ myHeader = "NCOLS " + QString::number(myColsInt) + "\r\n";
+ myHeader += "NROWS " + QString::number(myRowsInt) + "\r\n";
+ float myYTop = myTransform[3];
+ float myXLeft = myTransform[0];
+ float myCellHeight = myTransform[5];
+ float myAbsCellHeight = fabs(myCellHeight);
+ float myHeight = myAbsCellHeight * myRowsInt;
+ float myYBottom = myYTop - myHeight;
+ //qDebug("YTop: " + QString::number(myYTop).toLocal8Bit());
+ //qDebug("XLeft: " + QString::number(myXLeft).toLocal8Bit());
+ //qDebug("CellHeight: " + QString::number(myCellHeight).toLocal8Bit());
+ //qDebug("RowCount: " + QString::number(myRowsInt).toLocal8Bit());
+ //qDebug("YBottom = YTop - (fabs(CellHeight) * fabs(RowsCount))");
+ //qDebug("YBottom: " + QString::number(myYBottom).toLocal8Bit());
+ myHeader += "XLLCORNER " + QString::number(myXLeft) + "\r\n";;
+ myHeader += "YLLCORNER " + QString::number(myYBottom) + "\r\n";
+ myHeader += "CELLSIZE " + QString::number(myTransform[1]) + "\r\n";
+ myHeader += "NODATA_VALUE " + QString::number(myNullValue) + "\r\n";
+ }
+ else // non gdal
+ {
+ // Use the fixed matrix dimensions to create the ascii file
+ // Warning: this assumes a GLOBAL dataset
+ // Warning: this screws up cellsizes that are not square
+ // Warning: this only works for integers at present
+ myHeader = "ncols " + QString::number (mXDim) + "\n" +
+ "nrows " + QString::number (mYDim) + "\n" +
+ "xllcorner -180\n" +
+ "yllcorner -90\n"+
+ "cellsize " + QString::number (360/static_cast<float>(mXDim)) + "\n" +
+ "nodata_value -9999.5\n";
+ }
+ return myHeader;
+}
Modified: trunk/external_plugins/cdp2/src/lib/climatefilereader.h
===================================================================
--- trunk/external_plugins/cdp2/src/lib/climatefilereader.h 2008-09-24 14:00:55 UTC (rev 9403)
+++ trunk/external_plugins/cdp2/src/lib/climatefilereader.h 2008-09-24 16:35:10 UTC (rev 9404)
@@ -199,6 +199,17 @@
* @note This will likely be removed!
*/
void printBlock(int theBlock);
+ /** Get a world file based on the file reader. This is useful when you
+ are writing out a new file and want it to have the same positional info
+ and dimensions as the original input file.
+ */
+ const QString getWorldFile();
+
+ /** Get an ascii grid header file based on the file reader. This is useful when you
+ are writing out a new file and want it to have the same positional info
+ and dimensions as the original input file.
+ */
+ const QString getAsciiHeader();
signals:
void error (QString theError);
void message (QString theMessage);
Modified: trunk/external_plugins/cdp2/src/tests/cdptest.cpp
===================================================================
--- trunk/external_plugins/cdp2/src/tests/cdptest.cpp 2008-09-24 14:00:55 UTC (rev 9403)
+++ trunk/external_plugins/cdp2/src/tests/cdptest.cpp 2008-09-24 16:35:10 UTC (rev 9404)
@@ -91,10 +91,6 @@
myController.setOutputFileType(FileWriter::ESRI_ASCII);
// Show a summary of the controller state (for debug purposes only)
qDebug(myController.description().toLocal8Bit());
- if (! myController.makeFileGroups() )
- {
- QFAIL ("Failed to make file groups");
- }
myController.run();
}
More information about the QGIS-commit
mailing list