}
+int HYDROData_ShapeFile::DBF_GetNbRecords()
+{
+ if(myHDBF == NULL)
+ return 0;
+ return DBFGetRecordCount(myHDBF);
+}
+
+void HYDROData_ShapeFile::DBF_GetAttributeList(int theIndexOfField, std::vector<DBF_AttrValue>& theAttrV)
+{
+ int nWidth, nDecimals;
+ char chField[12];
+
+ for( int i = 0; i < DBFGetRecordCount(myHDBF); i++ )
+ {
+ DBFFieldType eType;
+ DBF_AttrValue anAttr;
+ eType = DBFGetFieldInfo( myHDBF, theIndexOfField, chField, &nWidth, &nDecimals );
+
+ if( DBFIsAttributeNULL( myHDBF, i, theIndexOfField ) )
+ {
+ anAttr.myIsNull = true;
+ }
+ else
+ {
+ switch( eType )
+ {
+ case FTString:
+ {
+ const char* chAttr = DBFReadStringAttribute( myHDBF, i, theIndexOfField );
+ anAttr.myIsNull = false;
+ anAttr.myFieldType = DBF_FieldType_String;
+ anAttr.myRawValue = chAttr;
+ anAttr.myStrVal = QString(chAttr);
+ break;
+ }
+
+ case FTInteger:
+ {
+ int iAttr = DBFReadIntegerAttribute( myHDBF, i, theIndexOfField );
+ anAttr.myIsNull = false;
+ anAttr.myFieldType = DBF_FieldType_Integer;
+ anAttr.myRawValue = DBFReadStringAttribute( myHDBF, i, theIndexOfField );
+ anAttr.myStrVal = QString::number(iAttr);
+ break;
+ }
+
+ case FTDouble:
+ {
+ double dAttr = DBFReadDoubleAttribute( myHDBF, i, theIndexOfField );
+ anAttr.myIsNull = false;
+ anAttr.myFieldType = DBF_FieldType_Double;
+ anAttr.myRawValue = DBFReadStringAttribute( myHDBF, i, theIndexOfField );
+ anAttr.myStrVal = QString::number(dAttr, 'g', 20);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ theAttrV.push_back(anAttr);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+PROJCS["RGF93 / Lambert-93", GEOGCS["RGF93", DATUM["Reseau Geodesique Francais 1993", SPHEROID["GRS 1980", 6378137.0, 298.257222101, AUTHORITY["EPSG","7019"]], TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], AUTHORITY["EPSG","6171"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4171"]], PROJECTION["Lambert_Conformal_Conic_2SP", AUTHORITY["EPSG","9802"]], PARAMETER["central_meridian", 3.0], PARAMETER["latitude_of_origin", 46.5], PARAMETER["standard_parallel_1", 49.0], PARAMETER["false_easting", 700000.0], PARAMETER["false_northing", 6600000.0], PARAMETER["scale_factor", 1.0], PARAMETER["standard_parallel_2", 44.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","2154"]]
\ No newline at end of file
{
QString aDBFPath = REF_PATH + "/cyprus_natural.dbf";
HYDROData_ShapeFile aSHPFile;
- aSHPFile.DBF_OpenDBF(aDBFPath);
+ CPPUNIT_ASSERT_EQUAL(true, aSHPFile.DBF_OpenDBF(aDBFPath));
int NbF = aSHPFile.DBF_GetNbFields();
CPPUNIT_ASSERT_EQUAL( 2, NbF );
aSHPFile.DBF_CloseDBF();
{
QString aDBFPath = REF_PATH + "/cyprus_natural.dbf";
HYDROData_ShapeFile aSHPFile;
- aSHPFile.DBF_OpenDBF(aDBFPath);
+ CPPUNIT_ASSERT_EQUAL(true, aSHPFile.DBF_OpenDBF(aDBFPath));
QStringList FL = aSHPFile.DBF_GetFieldList();
CPPUNIT_ASSERT_EQUAL(true, "NAME" == FL[0]);
{
QString aDBFPath = REF_PATH + "/cyprus_natural.dbf";
HYDROData_ShapeFile aSHPFile;
- aSHPFile.DBF_OpenDBF(aDBFPath);
+ CPPUNIT_ASSERT_EQUAL(true, aSHPFile.DBF_OpenDBF(aDBFPath));
std::vector<HYDROData_ShapeFile::DBF_FieldType> FTVect;
aSHPFile.DBF_GetFieldTypeList(FTVect);
aSHPFile.DBF_CloseDBF();
}
+void test_HYDROData_ShapeFile::test_NbRecordsDbf()
+{
+ QString aDBFPath = REF_PATH + "/cyprus_natural.dbf";
+ HYDROData_ShapeFile aSHPFile;
+ CPPUNIT_ASSERT_EQUAL(true, aSHPFile.DBF_OpenDBF(aDBFPath));
+ int NbR = aSHPFile.DBF_GetNbRecords();
+ CPPUNIT_ASSERT_EQUAL( 268, NbR );
+ aSHPFile.DBF_CloseDBF();
+}
+
+void test_HYDROData_ShapeFile::test_GetAttrListIndex()
+{
+ { //cyprus_natural
+ QString aDBFPath = REF_PATH + "/cyprus_natural.dbf";
+ HYDROData_ShapeFile aSHPFile;
+ CPPUNIT_ASSERT_EQUAL(true, aSHPFile.DBF_OpenDBF(aDBFPath));
+ std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
+ aSHPFile.DBF_GetAttributeList(0, theAttrV ); //get all records take from the first field
+ //Check Values
+ //Non-null attr
+ CPPUNIT_ASSERT_EQUAL( 268, (int)theAttrV.size() );
+ CPPUNIT_ASSERT_EQUAL( true, std::string("Ovgos Dam") == theAttrV[22].myRawValue);
+ CPPUNIT_ASSERT_EQUAL( true, QString("Ovgos Dam") == theAttrV[22].myStrVal);
+ CPPUNIT_ASSERT_EQUAL( false, theAttrV[22].myIsNull);
+ CPPUNIT_ASSERT_EQUAL( HYDROData_ShapeFile::DBF_FieldType_String, theAttrV[22].myFieldType);
+
+ //Null attr
+ CPPUNIT_ASSERT_EQUAL( true, theAttrV[35].myIsNull);
+ CPPUNIT_ASSERT_EQUAL( true, theAttrV[35].myRawValue.empty());
+ CPPUNIT_ASSERT_EQUAL( HYDROData_ShapeFile::DBF_FieldType_None, theAttrV[35].myFieldType);
+
+ theAttrV.clear();
+ aSHPFile.DBF_GetAttributeList(1, theAttrV ); //second field
+ CPPUNIT_ASSERT_EQUAL( 268, (int)theAttrV.size() );
+ CPPUNIT_ASSERT_EQUAL( true, std::string("water") == theAttrV[3].myRawValue);
+ CPPUNIT_ASSERT_EQUAL( true, QString("water") == theAttrV[3].myStrVal);
+ CPPUNIT_ASSERT_EQUAL( false, theAttrV[3].myIsNull);
+ CPPUNIT_ASSERT_EQUAL( HYDROData_ShapeFile::DBF_FieldType_String, theAttrV[3].myFieldType);
+
+ aSHPFile.DBF_CloseDBF();
+ }
+ { //CLC06
+ QString aDBFPath = REF_PATH + "/CLC06.dbf";
+ HYDROData_ShapeFile aSHPFile;
+ CPPUNIT_ASSERT_EQUAL (true, aSHPFile.DBF_OpenDBF(aDBFPath));
+ std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
+
+ aSHPFile.DBF_GetAttributeList(0, theAttrV );
+ CPPUNIT_ASSERT_EQUAL( 3269, (int)theAttrV.size() );
+ CPPUNIT_ASSERT_EQUAL( true, std::string("FR-184045") == theAttrV[2].myRawValue);
+ CPPUNIT_ASSERT_EQUAL( true, QString("FR-184045") == theAttrV[2].myStrVal);
+ CPPUNIT_ASSERT_EQUAL( false, theAttrV[2].myIsNull);
+ CPPUNIT_ASSERT_EQUAL( HYDROData_ShapeFile::DBF_FieldType_String, theAttrV[2].myFieldType);
+ //
+ theAttrV.clear();
+ aSHPFile.DBF_GetAttributeList(2, theAttrV );
+ CPPUNIT_ASSERT_EQUAL( 3269, (int)theAttrV.size() );
+ CPPUNIT_ASSERT_EQUAL( true, std::string("6621.1654324936000000000000000000") == theAttrV[2].myRawValue);
+ CPPUNIT_ASSERT_EQUAL( true, QString("6621.1654324935998375") == theAttrV[2].myStrVal);
+ CPPUNIT_ASSERT_EQUAL( false, theAttrV[2].myIsNull);
+ CPPUNIT_ASSERT_EQUAL( HYDROData_ShapeFile::DBF_FieldType_Double, theAttrV[2].myFieldType);
+
+ aSHPFile.DBF_CloseDBF();
+ }
+}