From de943c84f0d1cbe605d3f5f845b8d2915d95fa3d Mon Sep 17 00:00:00 2001 From: zwnk Date: Thu, 23 May 2019 21:08:28 +0200 Subject: [PATCH] Update 'shp_2_txt.cpp' --- shp_2_txt.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/shp_2_txt.cpp b/shp_2_txt.cpp index b8a38c7..9bdca9c 100644 --- a/shp_2_txt.cpp +++ b/shp_2_txt.cpp @@ -1,3 +1,10 @@ +/* +http://shapelib.maptools.org/dbf_api.html + +basic funtionality taken from dbfdump.c +path to libshp.dll has to be added as a PATH var + +*/ #include #include #include @@ -17,20 +24,23 @@ int main(int argc, char const *argv[]) char szTitle[12]; string filename = "f:\\testing\\shp_2_txt\\MA.dbf"; + // open textfile and dbf handle ofstream txt_file("out.txt"); dbfh = DBFOpen(filename.c_str(), "rb"); + // check if (dbfh <= 0) { throw string("File " + filename + " not found"); } else { - for( iRecord = 0; iRecord < DBFGetRecordCount(dbfh); iRecord++ ) + // loop over dbf records + for( iRecord = 0; iRecord < DBFGetRecordCount(dbfh); iRecord++ ) { - - for( i = 0; i < DBFGetFieldCount(dbfh); i++ ) - { + // loop over fields of record + for( i = 0; i < DBFGetFieldCount(dbfh); i++ ) + { DBFFieldType eType; eType = DBFGetFieldInfo( dbfh, i, szTitle, &nWidth, &nDecimals ); string dec_lat = "DEC_LAT"; @@ -40,6 +50,7 @@ int main(int argc, char const *argv[]) string str(szTitle); string line; + // parse for lat, lon in degrees and orhto height if (szTitle == dec_lat or szTitle == dec_lon or szTitle == ortho_h) { txt_file << DBFReadStringAttribute( dbfh, iRecord, i ); @@ -48,7 +59,7 @@ int main(int argc, char const *argv[]) } txt_file << endl; } - + // close dbf handle and textfile DBFClose( dbfh ); txt_file.close(); }