Update 'shp_2_txt.cpp'

This commit is contained in:
zwnk 2019-05-23 21:01:55 +02:00
parent 22365c220e
commit 92ee58e14e

View file

@ -9,50 +9,49 @@ using namespace std;
#include "shapefil.h" #include "shapefil.h"
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
DBFHandle dbfh; DBFHandle dbfh;
int i, iRecord; int i, iRecord;
char *pszFilename = NULL; char *pszFilename = NULL;
int nWidth, nDecimals; int nWidth, nDecimals;
char szTitle[12]; char szTitle[12];
string filename = "f:\\testing\\shp_2_txt\\MA.dbf"; string filename = "f:\\testing\\shp_2_txt\\MA.dbf";
ofstream txt_file("out.txt"); ofstream txt_file("out.txt");
dbfh = DBFOpen(filename.c_str(), "rb");
dbfh = DBFOpen(filename.c_str(), "rb"); if (dbfh <= 0)
{
throw string("File " + filename + " not found");
}
else
{
for( iRecord = 0; iRecord < DBFGetRecordCount(dbfh); iRecord++ )
{
if (dbfh <= 0) for( i = 0; i < DBFGetFieldCount(dbfh); i++ )
{ {
throw string("File " + filename + " not found");
}
else
{
for( iRecord = 0; iRecord < DBFGetRecordCount(dbfh); iRecord++ )
{
for( i = 0; i < DBFGetFieldCount(dbfh); i++ )
{
DBFFieldType eType; DBFFieldType eType;
eType = DBFGetFieldInfo( dbfh, i, szTitle, &nWidth, &nDecimals ); eType = DBFGetFieldInfo( dbfh, i, szTitle, &nWidth, &nDecimals );
string dec_lat = "DEC_LAT"; string dec_lat = "DEC_LAT";
string dec_lon = "DEC_LON"; string dec_lon = "DEC_LON";
string ellip_h = "ELLIP_HT"; string ellip_h = "ELLIP_HT";
string ortho_h = "ORTHO_HT"; string ortho_h = "ORTHO_HT";
string str(szTitle); string str(szTitle);
string line; string line;
if (szTitle == dec_lat or szTitle == dec_lon or szTitle == ortho_h) if (szTitle == dec_lat or szTitle == dec_lon or szTitle == ortho_h)
{ {
txt_file << DBFReadStringAttribute( dbfh, iRecord, i ); txt_file << DBFReadStringAttribute( dbfh, iRecord, i );
txt_file << " "; txt_file << " ";
} }
} }
txt_file << endl; txt_file << endl;
} }
DBFClose( dbfh ); DBFClose( dbfh );
txt_file.close(); txt_file.close();
} }
return 0; return 0;
} }