00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Tim Sutton * 00003 * tim@linfiniti.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 00021 #include "omgscraperplugininterface.h" 00022 #include "omgui.h" 00023 00024 //QT Includes 00025 #include <QDebug> 00026 #include <QFileInfo> 00027 #include <QFile> 00028 #include <QTextStream> 00029 #include <QDir> 00030 00031 OmgScraperPluginInterface::~OmgScraperPluginInterface() 00032 { 00033 } 00034 00035 const OmgPluginMessenger * OmgScraperPluginInterface::getMessenger() 00036 { 00037 //qDebug("Getting messenger"); 00038 return &mMessenger; 00039 } 00040 void OmgScraperPluginInterface::setMinimumRecords(int theMinimum) 00041 { 00042 mMinimumRecords=theMinimum; 00043 if (mMinimumRecords < 1) 00044 { 00045 mMinimumRecords = 1; 00046 } 00047 } 00048 00049 QString OmgScraperPluginInterface::createTextFile(QString theFileName) 00050 { 00051 if (mLocalityVector.size() < mMinimumRecords) 00052 { 00053 return QString(); 00054 } 00055 // need to strip off the .shp and replace with .txt 00056 QFileInfo myFileInfo(theFileName); 00057 QString myBaseString = myFileInfo.dir().path()+QString("/")+myFileInfo.baseName(); // excludes any extension 00058 //create the txt file 00059 QString myFileName(myBaseString+".txt"); 00060 QFile myFile( myFileName ); 00061 if ( myFile.open( QIODevice::WriteOnly ) ) 00062 { 00063 QTextStream myQTextStream( &myFile ); 00064 for (int myIteratorInt = 0; myIteratorInt < mLocalityVector.size(); ++myIteratorInt) 00065 { 00066 OmgLocality myLocality = mLocalityVector[myIteratorInt]; 00067 myQTextStream << myLocality.id() << "\t" << myLocality.label() << "\t" << myLocality.longitude() << "\t" << myLocality.latitude() << "\r\n"; 00068 //qDebug("Writing " + 00069 // QString::number(myLocality.longitude).toLocal8Bit() + " " + 00070 // QString::number(myLocality.latitude).toLocal8Bit() + " to " 00071 // + myFileName.toLocal8Bit()); 00072 } 00073 } 00074 else 00075 { 00076 QString myWarning(QObject::tr("Unable to open ") + myFileName.toLocal8Bit() + QObject::tr(" for writing!")); 00077 mMessenger.emitError(myWarning); 00078 } 00079 myFile.close(); 00080 return QString(myFileName); 00081 } 00082 00083 void OmgScraperPluginInterface::createShapefile(QString theShapefileName) 00084 { 00085 if (mLocalityVector.size() < mMinimumRecords) 00086 { 00087 return; 00088 } 00089 Omgui::localitiesToShapefile(theShapefileName,mLocalityVector); 00090 }