From: isn Date: Tue, 17 Nov 2015 09:07:06 +0000 (+0300) Subject: Use discretization to write non-linear borders of LCM to SHP file // p.3 X-Git-Tag: v1.5~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2226b7cf9e77d4bfa79c75a5e7037bb3df846268;p=modules%2Fhydro.git Use discretization to write non-linear borders of LCM to SHP file // p.3 --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 951f77d3..1187916c 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -939,7 +939,7 @@ QStringList HYDROData_LandCoverMap::DumpToPython( const QString& thePyScri QString aDbfFileName = thePyScriptPath; aDbfFileName.replace( ".py", ".dbf" ); - ExportSHP( aShpFileName ); + ExportSHP( aShpFileName, true, 1 ); QString anAttr = "CODE_06"; //TODO: some custom choice QStringList anAttrValues, aTypes; @@ -1048,11 +1048,11 @@ bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName, return true; } -bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName) const +bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUseDiscr, double theDefl) const { HYDROData_ShapeFile anExporter; QStringList aList; - anExporter.Export(theSHPFileName, this, aList); + anExporter.Export(theSHPFileName, this, aList, bUseDiscr, theDefl ); if (aList.empty()) return true; else diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 656a482e..c2437d8c 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -93,7 +93,7 @@ public: HYDRODATA_EXPORT bool ImportSHP( const QString& theSHPFileName, const QList& theIndices = QList() ); - HYDRODATA_EXPORT bool ExportSHP( const QString& theSHPFileName ) const; + HYDRODATA_EXPORT bool ExportSHP( const QString& theSHPFileName, bool bUseDiscr = false, double theDefl = 0.1) const; HYDRODATA_EXPORT DBFStatus ImportDBF( const QString& theDBFFileName, const QString& theFieldName, diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index d3ade82a..8b0711f8 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -104,8 +104,8 @@ void HYDROData_ShapeFile::Export(const QString& aFileName, } } -void HYDROData_ShapeFile::Export(const QString& aFileName, - const Handle_HYDROData_LandCoverMap& aLCM, QStringList& aNonExpList) +void HYDROData_ShapeFile::Export(const QString& aFileName, const Handle_HYDROData_LandCoverMap& aLCM, + QStringList& aNonExpList, bool bUseDiscr, double theDefl) { SHPHandle hSHPHandle; if ( !aLCM.IsNull() && !aLCM->IsEmpty()) @@ -115,7 +115,7 @@ void HYDROData_ShapeFile::Export(const QString& aFileName, for( ; It.More(); It.Next()) { TopoDS_Face aFace = It.Face(); - if (WriteObjectPolygon(hSHPHandle, aFace) != 1) + if (WriteObjectPolygon(hSHPHandle, aFace, bUseDiscr, theDefl) != 1) aNonExpList.append(aLCM->GetName() + "_" + QString::number(It.Index())); } } @@ -289,11 +289,29 @@ void HYDROData_ShapeFile::ProcessFace(const TopoDS_Face& theFace, SHPHandle theS BRepAdaptor_Curve Cur( E ); GCPnts_QuasiUniformDeflection Discr( Cur, theDefl ); if( !Discr.IsDone() ) - continue; //skip all edge? - for( int i = 1; i <= Discr.NbPoints(); i++ ) + continue; //skip edge? + double NewDefl = theDefl/2.0; + while (Discr.NbPoints() < 2) { - gp_Pnt P = Discr.Value( i ); - aPnts.Append(gp_Pnt2d(P.X(), P.Y())); + Discr.Initialize(Cur, NewDefl); + NewDefl = NewDefl/2.0; + } + // + if (E.Orientation() == TopAbs_FORWARD) + { + for( int i = 1; i <= Discr.NbPoints(); i++ ) + { + gp_Pnt P = Discr.Value( i ); + aPnts.Append(gp_Pnt2d(P.X(), P.Y())); + } + } + else + { + for( int i = Discr.NbPoints(); i > 0; i-- ) + { + gp_Pnt P = Discr.Value( i ); + aPnts.Append(gp_Pnt2d(P.X(), P.Y())); + } } } } diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index cf24d3b5..95a8b175 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -88,13 +88,15 @@ public: HYDRODATA_EXPORT void Export(const QString& aFileName, const Handle_HYDROData_LandCoverMap& aLCM, - QStringList& aNonExpList); + QStringList& aNonExpList, + bool bUseDiscr = false, + double theDefl = 0.1); int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly ); int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly ); - int WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape, bool bUseDiscr = false, double theDefl = 0.1 ); + int WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape, bool bUseDiscr, double theDefl ); //Import bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile); //Import Landcover