From 30e0eaffa5c4b665d92643ba9d2a25c77f10a42f Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Fri, 2 Oct 2020 09:06:44 +0200 Subject: [PATCH] write dbf with Hydro shapefiles, attribute string "PartName" with polyline name --- src/HYDROData/HYDROData_ShapeFile.cxx | 45 +++++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 3e7b3486..12cb1106 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -62,6 +62,9 @@ #include #include +//#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + #ifdef WIN32 #pragma warning( disable: 4996 ) #endif @@ -84,13 +87,20 @@ void HYDROData_ShapeFile::Export(Handle(HYDROData_Document) theDocument, NCollection_Sequence aPoly3DSeq, QStringList& aNonExpList) { + DEBTRACE("aFileName " << aFileName.toStdString()); SHPHandle hSHPHandle; + QStringList anExpList; if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty()) { hSHPHandle = SHPCreate( aFileName.toLatin1().data(), SHPT_ARC ); for (int i = 1; i <= aPolyXYSeq.Size(); i++) if (WriteObjectPolyXY(theDocument, hSHPHandle, aPolyXYSeq(i)) != 1) aNonExpList.append(aPolyXYSeq(i)->GetName()); + else + { + anExpList.append(aPolyXYSeq(i)->GetName()); + DEBTRACE(" aName: " << aPolyXYSeq(i)->GetName().toStdString()); + } } else if (aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty()) { @@ -98,9 +108,28 @@ void HYDROData_ShapeFile::Export(Handle(HYDROData_Document) theDocument, for (int i = 1; i <= aPoly3DSeq.Size(); i++) if (WriteObjectPoly3D(theDocument, hSHPHandle, aPoly3DSeq(i)) != 1) aNonExpList.append(aPoly3DSeq(i)->GetName()); + else + { + anExpList.append(aPoly3DSeq(i)->GetName()); + DEBTRACE(" aName: " << aPoly3DSeq(i)->GetName().toStdString()); + } } if (hSHPHandle->nRecords > 0) + { SHPClose( hSHPHandle ); + std::vector theAttrV; + for (int i=0; iCheckLinear()) return; - // + SHPHandle hSHPHandle = NULL; if ( !aLCM.IsNull() && !aLCM->IsEmpty()) { @@ -150,11 +179,6 @@ int HYDROData_ShapeFile::WriteObjectPolyXY(Handle(HYDROData_Document) theDocumen SHPObject *aSHPObj; std::vector x, y; std::vector anPartStart; - -// for (int i = 0; i < thePoly->NbSections(); i++) -// if (thePoly->GetSectionType(i) == HYDROData_IPolyline::SECTION_SPLINE) -// return -1; - for (int i = 0; i < thePoly->NbSections(); i++) { anPartStart.push_back(x.size()); @@ -190,9 +214,6 @@ int HYDROData_ShapeFile::WriteObjectPoly3D(Handle(HYDROData_Document) theDocumen std::vector anPartStart; anPartStart.push_back(0); //one section only - if (thePoly->GetPolylineXY()->GetSectionType(0) == HYDROData_IPolyline::SECTION_SPLINE) - return -1; - HYDROData_Polyline3D::Polyline3DPoints aPointList3D = thePoly->GetProfilePoints3D(true); for (int j = 1; j <= aPointList3D.Size(); j++) { @@ -1164,6 +1185,7 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co default: break; } + DEBTRACE("theAttrV.size() " << theAttrV.size()); if (DBFGetFieldCount( hDBF ) != 1) { @@ -1181,6 +1203,7 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co { for (size_t i = 0; i < theAttrV.size(); i++) { + DEBTRACE(" rawValue"); if (!theAttrV[i].myIsNull) stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myRawValue.c_str()); else @@ -1197,11 +1220,13 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co { for (size_t i = 0; i < theAttrV.size(); i++) { + DEBTRACE(" typeValue " << theAttrV[i].myIsNull); if (!theAttrV[i].myIsNull) switch( theType ) { case DBF_FieldType_String: { + DEBTRACE(" write dbf " << i << " " << theAttrV[i].myStrVal.toStdString()); stat = DBFWriteStringAttribute(hDBF, (int)i, 0, theAttrV[i].myStrVal.toStdString().c_str()); break; } @@ -1222,7 +1247,7 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co } else stat = DBFWriteNULLAttribute(hDBF, (int)i, 0 ); - + DEBTRACE(" stat " << stat); if (stat != 1) { DBFClose( hDBF ); -- 2.39.2