From 76201e75d6245492653aa42b67ed137b3f87e687 Mon Sep 17 00:00:00 2001 From: zwnk Date: Thu, 23 May 2019 20:55:33 +0200 Subject: [PATCH] Add 'shp_2_txt.cpp' --- shp_2_txt.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 shp_2_txt.cpp diff --git a/shp_2_txt.cpp b/shp_2_txt.cpp new file mode 100644 index 0000000..d29f5a9 --- /dev/null +++ b/shp_2_txt.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +using namespace std; + +#include "shapefil.h" + +int main(int argc, char const *argv[]) +{ + DBFHandle dbfh; + int i, iRecord; + char *pszFilename = NULL; + int nWidth, nDecimals; + char szTitle[12]; + + string filename = "f:\\testing\\shp_2_txt\\MA.dbf"; + + ofstream txt_file("out.txt"); + + dbfh = DBFOpen(filename.c_str(), "rb"); + + if (dbfh <= 0) + { + throw string("File " + filename + " not found"); + } + else + { + for( iRecord = 0; iRecord < DBFGetRecordCount(dbfh); iRecord++ ) + { + + for( i = 0; i < DBFGetFieldCount(dbfh); i++ ) + { + DBFFieldType eType; + eType = DBFGetFieldInfo( dbfh, i, szTitle, &nWidth, &nDecimals ); + string dec_lat = "DEC_LAT"; + string dec_lon = "DEC_LON"; + string ellip_h = "ELLIP_HT"; + string ortho_h = "ORTHO_HT"; + string str(szTitle); + string line; + + if (szTitle == dec_lat or szTitle == dec_lon or szTitle == ortho_h) + { + txt_file << DBFReadStringAttribute( dbfh, iRecord, i ); + txt_file << " "; + } + } + txt_file << endl; + } + + DBFClose( dbfh ); + free( panWidth ); + txt_file.close(); + } + + return 0; +} \ No newline at end of file