]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
export Shapefiles with correction LCS
authorPaul RASCLE <paul.rascle@edf.fr>
Tue, 14 Jun 2016 21:03:13 +0000 (23:03 +0200)
committerPaul RASCLE <paul.rascle@edf.fr>
Tue, 14 Jun 2016 21:03:13 +0000 (23:03 +0200)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROData/HYDROData_ShapeFile.h
src/HYDROGUI/HYDROGUI_ExportFileOp.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx

index a701eb42a9d124140952837265b12ee4ada5425a..4ad735022b32330c1219f570afdd3ff2d35b437f 100644 (file)
@@ -1218,7 +1218,7 @@ bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUse
 {
   HYDROData_ShapeFile anExporter;
   QStringList aList;
-  anExporter.Export(theSHPFileName, this, aList, bUseDiscr, theDefl );
+  anExporter.Export(HYDROData_Document::Document(1), theSHPFileName, this, aList, bUseDiscr, theDefl );
   if (aList.empty())
     return true;
   else 
index 3538a6ea2fb86aced858736bfbe744803c0bc6b9..37f759f0d29425d55fa6173b2d82ffc4a14739b2 100644 (file)
@@ -78,24 +78,25 @@ HYDROData_ShapeFile::~HYDROData_ShapeFile()
   Free();
 }
 
-void HYDROData_ShapeFile::Export(const QString& aFileName, 
-  NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
-  NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
-  QStringList& aNonExpList)
+void HYDROData_ShapeFile::Export(Handle(HYDROData_Document) theDocument,
+                                 const QString& aFileName,
+                                 NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
+                                 NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
+                                 QStringList& aNonExpList)
 {
   SHPHandle hSHPHandle;
   if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
   {
     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARC );        
     for (int i = 1; i <= aPolyXYSeq.Size(); i++)
-      if (WriteObjectPolyXY(hSHPHandle, aPolyXYSeq(i)) != 1)
+      if (WriteObjectPolyXY(theDocument, hSHPHandle, aPolyXYSeq(i)) != 1)
         aNonExpList.append(aPolyXYSeq(i)->GetName());
   }
   else if (aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
   {
     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARCZ );
     for (int i = 1; i <= aPoly3DSeq.Size(); i++)
-      if (WriteObjectPoly3D(hSHPHandle, aPoly3DSeq(i)) != 1)
+      if (WriteObjectPoly3D(theDocument, hSHPHandle, aPoly3DSeq(i)) != 1)
         aNonExpList.append(aPoly3DSeq(i)->GetName());
   }
   if (hSHPHandle->nRecords > 0)
@@ -109,8 +110,11 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
   }
 }
 
-void HYDROData_ShapeFile::Export(const QString& aFileName, const Handle_HYDROData_LandCoverMap& aLCM, 
-                                 QStringList& aNonExpList, bool bCheckLinear, bool bUseDiscr, double theDefl)
+void HYDROData_ShapeFile::Export(Handle(HYDROData_Document) theDocument,
+                                 const QString& aFileName,
+                                 const Handle_HYDROData_LandCoverMap& aLCM,
+                                 QStringList& aNonExpList,
+                                 bool bCheckLinear, bool bUseDiscr, double theDefl)
 {
   if (bCheckLinear && !aLCM->CheckLinear())
     return;
@@ -123,7 +127,7 @@ void HYDROData_ShapeFile::Export(const QString& aFileName, const Handle_HYDRODat
     for( ; It.More(); It.Next())
     {
       TopoDS_Face aFace = It.Face();
-      if (WriteObjectPolygon(hSHPHandle, aFace, bUseDiscr, theDefl) != 1)
+      if (WriteObjectPolygon(theDocument, hSHPHandle, aFace, bUseDiscr, theDefl) != 1)
         aNonExpList.append(aLCM->GetName() + "_" +  QString::number(It.Index()));
     }
   }
@@ -139,7 +143,9 @@ void HYDROData_ShapeFile::Export(const QString& aFileName, const Handle_HYDRODat
 }
 
 
-int HYDROData_ShapeFile::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly )
+int HYDROData_ShapeFile::WriteObjectPolyXY(Handle(HYDROData_Document) theDocument,
+                                           SHPHandle theShpHandle,
+                                           Handle_HYDROData_PolylineXY thePoly )
 {
   SHPObject    *aSHPObj;
   std::vector<double> x, y;
@@ -155,13 +161,17 @@ int HYDROData_ShapeFile::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROD
     HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPoints(i);
     for (int j = 1; j <= aPointList.Size(); j++)
     {
-      x.push_back( aPointList(j).X());
-      y.push_back( aPointList(j).Y()); 
+      gp_XY P = aPointList(j);
+      theDocument->Transform(P, false);
+      x.push_back( P.X());
+      y.push_back( P.Y());
     }
     if (thePoly->IsClosedSection(i))
     {
-      x.push_back( aPointList(1).X());
-      y.push_back( aPointList(1).Y()); 
+      gp_XY P = aPointList(1);
+      theDocument->Transform(P, false);
+      x.push_back( P.X());
+      y.push_back( P.Y());
     }
   }
     
@@ -171,7 +181,9 @@ int HYDROData_ShapeFile::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROD
   return 1;
 }
 
-int HYDROData_ShapeFile::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly )
+int HYDROData_ShapeFile::WriteObjectPoly3D(Handle(HYDROData_Document) theDocument,
+                                           SHPHandle theShpHandle,
+                                           Handle_HYDROData_Polyline3D thePoly )
 {
   SHPObject    *aSHPObj;
   std::vector<double> x, y, z;
@@ -187,14 +199,18 @@ int HYDROData_ShapeFile::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROD
     HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPolylineXY()->GetPoints(i);
     for (int j = 1; j <= aPointList.Size(); j++)
     {
-      x.push_back( aPointList(j).X());
-      y.push_back( aPointList(j).Y()); 
+      gp_XY P = aPointList(j);
+      theDocument->Transform(P, false);
+      x.push_back( P.X());
+      y.push_back( P.Y());
       z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(j).X(), aPointList(j).Y())));
     }
     if ( thePoly->GetPolylineXY()->IsClosedSection(i))
     {
-      x.push_back( aPointList(1).X());
-      y.push_back( aPointList(1).Y()); 
+      gp_XY P = aPointList(1);
+      theDocument->Transform(P, false);
+      x.push_back( P.X());
+      y.push_back( P.Y());
       z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(1).X(), aPointList(1).Y())));
 
     }
@@ -206,7 +222,9 @@ int HYDROData_ShapeFile::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROD
   return 1;
 }
 
-int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape,
+int HYDROData_ShapeFile::WriteObjectPolygon(Handle(HYDROData_Document) theDocument,
+                                            SHPHandle theShpHandle,
+                                            const TopoDS_Shape& theInputShape,
                                             bool bUseDiscr, double theDefl)
 {
   if (theInputShape.IsNull())
@@ -214,7 +232,7 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS
 
   if (theInputShape.ShapeType() == TopAbs_FACE)
   {
-    ProcessFace(TopoDS::Face(theInputShape), theShpHandle, bUseDiscr, theDefl);
+    ProcessFace(theDocument, TopoDS::Face(theInputShape), theShpHandle, bUseDiscr, theDefl);
   }
   else if (theInputShape.ShapeType() == TopAbs_COMPOUND)
   {
@@ -224,7 +242,7 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS
       TopoDS_Face aF = TopoDS::Face(Ex.Current());   
       if (aF.IsNull())
         continue;
-      ProcessFace(aF, theShpHandle, bUseDiscr, theDefl);
+      ProcessFace(theDocument, aF, theShpHandle, bUseDiscr, theDefl);
     }
   }
   else
@@ -234,7 +252,9 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS
  
 }
 
-void HYDROData_ShapeFile::ProcessFace(const TopoDS_Face& theFace, SHPHandle theShpHandle,
+void HYDROData_ShapeFile::ProcessFace(Handle(HYDROData_Document) theDocument,
+                                      const TopoDS_Face& theFace,
+                                      SHPHandle theShpHandle,
                                       bool bUseDiscr, double theDefl )
 {
   if (theFace.ShapeType() != TopAbs_FACE)
@@ -334,12 +354,16 @@ void HYDROData_ShapeFile::ProcessFace(const TopoDS_Face& theFace, SHPHandle theS
     //any other wires (holes) - in anticlockwise direction
     for (int j = aNPnts.Size(); j >= 1; j--)
     { 
-      x.push_back( aNPnts(j).X());
-      y.push_back( aNPnts(j).Y()); 
+      gp_XY P = gp_XY(aNPnts(j).X(), aNPnts(j).Y());
+      theDocument->Transform(P, false);
+      x.push_back( P.X());
+      y.push_back( P.Y());
     }
     //first point is same as the last one => closed polygon
-    x.push_back( aNPnts.Last().X());
-    y.push_back( aNPnts.Last().Y()); 
+    gp_XY P = gp_XY(aNPnts.Last().X(), aNPnts.Last().Y());
+    theDocument->Transform(P, false);
+    x.push_back( P.X());
+    y.push_back( P.Y());
 
   }
   
index 157ea9a438ef36159f598043b1e19ef4a654c768..fbeeb64358ec0bb0a78641f47ef4ff79dcbee1e9 100644 (file)
@@ -81,23 +81,28 @@ public:
   virtual HYDRODATA_EXPORT ~HYDROData_ShapeFile();
 
   //Export operation
-  HYDRODATA_EXPORT void Export(const QString& aFileName, 
+  HYDRODATA_EXPORT void Export(Handle(HYDROData_Document) theDocument,
+                               const QString& aFileName,
                                NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
                                NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
                                QStringList& aNonExpList);
 
-  HYDRODATA_EXPORT void Export(const QString& aFileName,
+  HYDRODATA_EXPORT void Export(Handle(HYDROData_Document) theDocument,
+                               const QString& aFileName,
                                const Handle_HYDROData_LandCoverMap& aLCM,
                                QStringList& aNonExpList,
                                bool bCheckLinear = true,
                                bool bUseDiscr = false, 
                                double theDefl = 0.1);
 
-  int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly );
+  int WriteObjectPolyXY(Handle(HYDROData_Document) theDocument, SHPHandle theShpHandle,
+                        Handle_HYDROData_PolylineXY thePoly );
 
-  int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly );
+  int WriteObjectPoly3D(Handle(HYDROData_Document) theDocument, SHPHandle theShpHandle,
+                        Handle_HYDROData_Polyline3D thePoly );
 
-  int WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape, bool bUseDiscr, double theDefl );
+  int WriteObjectPolygon(Handle(HYDROData_Document) theDocument, SHPHandle theShpHandle,
+                         const TopoDS_Shape& theInputShape, bool bUseDiscr, double theDefl );
   //Import
   bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile);
   //Import Landcover
@@ -136,7 +141,8 @@ public:
 
 private:
   
-  void ProcessFace(const TopoDS_Face& theFace, SHPHandle theShpHandle,
+  void ProcessFace(Handle(HYDROData_Document) theDocument,
+                   const TopoDS_Face& theFace, SHPHandle theShpHandle,
                    bool bUseDiscr, double theDefl);
 
   bool CheckLinear(const TopoDS_Shape& theInpShape);
index b256ba4f28d70a4b9376bde57cff4aef3c63ecd7..76cbf0dc732f91e297675c0ba3a0890dd2b056be 100644 (file)
@@ -107,14 +107,14 @@ void HYDROGUI_ExportFileOp::startOperation()
     {
       QStringList aNonExpList;
       HYDROData_ShapeFile anExporter;
+      Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
       if (!aPolyXYSeq.IsEmpty() || !aPolyXYSeq.IsEmpty())
         //Export polylines
-        anExporter.Export(aFileName, aPolyXYSeq, aPoly3DSeq, aNonExpList);
+        anExporter.Export(aDoc, aFileName, aPolyXYSeq, aPoly3DSeq, aNonExpList);
       else
       {
         //Export polygons
         //Extract all attribute names from all strickler tables
-        Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
         QSet<QString> anAttrNames;
         //use QSet to store attribute names. Yet it's not so good if the document contains two strickler types
         //with the same name
@@ -154,7 +154,7 @@ void HYDROGUI_ExportFileOp::startOperation()
           }
 
           //export shape-data
-          anExporter.Export(aFileName, aLCM, aNonExpList, false, !IsLinear, aDlg.getDeflValue());
+          anExporter.Export(aDoc, aFileName, aLCM, aNonExpList, false, !IsLinear, aDlg.getDeflValue());
           QString aDBFFileName = aFileName.replace( ".shp", ".dbf", Qt::CaseInsensitive);
           //Even if attribute-checkbox is unchecked, the .dbf-file should be removed. 
           //otherwise it may be used with wrong .shp-file. This is an incorrect behaivor.
index 698ea3193fcf465b12081692f8bde642301b5687..895a52b601a3cc7bd619854a5a3cd6ab4c55ab03 100644 (file)
@@ -934,7 +934,7 @@ void test_HYDROData_LandCoverMap::test_shp_loop_back()
     //export lcm
     HYDROData_ShapeFile anExporter;
     QStringList aNonExpList;
-    anExporter.Export(aSFileName, LCM, aNonExpList);
+    anExporter.Export(aDoc, aSFileName, LCM, aNonExpList);
     CPPUNIT_ASSERT (aNonExpList.empty());
 
     aDoc->Close();