Salome HOME
#651: dump to Python of land cover map
authorasl <asl@opencascade.com>
Mon, 16 Nov 2015 08:44:35 +0000 (11:44 +0300)
committerasl <asl@opencascade.com>
Mon, 16 Nov 2015 08:44:35 +0000 (11:44 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROPy/HYDROData_LandCoverMap.sip
src/HYDRO_tests/reference_data/lc_dump.py

index 33933ce3dee104b9d031c0e733e5f6c719229efc..79cd217567fce60f7e3316d702887a750b6bc57a 100644 (file)
@@ -42,6 +42,7 @@
 #include <TopExp_Explorer.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+#include <TopTools_SequenceOfShape.hxx>
 #include <BOPAlgo_PaveFiller.hxx>
 #include <BRepTools.hxx>
 #include <TopExp_Explorer.hxx>
@@ -227,6 +228,34 @@ bool HYDROData_LandCoverMap::IsEmpty() const
     return false;
 }
 
+bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName )
+{
+  HYDROData_ShapeFile anImporter;
+  QStringList aPolygonsList;
+  TopTools_SequenceOfShape aPolygonFaces;
+  int aShapeTypeOfFile;
+  int aStatus = anImporter.ImportPolygons( theSHPFileName, aPolygonsList, aPolygonFaces, aShapeTypeOfFile);
+
+  bool isOK = ( aStatus == 1 );
+  if( isOK )
+  {
+    QString aDefaultStricklerType = "";
+
+    HYDROData_MapOfFaceToStricklerType aFaces;
+    for( int i=1, n=aPolygonFaces.Length(); i<=n; i++ )
+    {
+      TopoDS_Shape aShape = aPolygonFaces.Value( i );
+      if( aShape.ShapeType()==TopAbs_FACE )
+        aFaces.Add( TopoDS::Face( aShape ), aDefaultStricklerType );
+    }
+
+    StoreLandCovers( aFaces );
+  }
+
+  anImporter.Free();
+  return isOK;
+}
+
 /**
   Load attributes from DBF File
 ///
@@ -273,6 +302,11 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri
     return DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING;
 }
 
+void HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName ) const
+{
+  //TODO
+}
+
 /**
   Export attributes to DBF File
 ///
@@ -932,19 +966,21 @@ QStringList HYDROData_LandCoverMap::DumpToPython( const QString&       thePyScri
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
   QString aName = GetObjPyName();
 
-  QString aShapeFileName = thePyScriptPath;
-  aShapeFileName.replace( ".py", ".shp" );
+  QString aShpFileName = thePyScriptPath;
+  aShpFileName.replace( ".py", ".shp" );
   QString aDbfFileName = thePyScriptPath;
   aDbfFileName.replace( ".py", ".dbf" );
 
   //TODO: export shape file
+  ExportSHP( aShpFileName );
 
   QString anAttr = "CODE_06"; //TODO: some custom choice
   QStringList anAttrValues, aTypes;
   HYDROData_Document::Document( myLab )->CollectQGISValues( anAttr, anAttrValues, aTypes );
   ExportDBF( aDbfFileName, anAttr, anAttrValues, aTypes );
 
-  //TODO: insert command to import shape file
+  aResList << QString( "%1.ImportSHP( '%2' )" ).
+    arg( aName ).arg( aShpFileName );
 
   Dump( "attr_values", anAttrValues, aResList );
   Dump( "types", aTypes, aResList );
index fd6dc5861c3390217295592b35ec3e2431ba3b1c..15b697f4da1a79b8aec478bf5e2ded90b4960c7b 100644 (file)
@@ -90,12 +90,16 @@ public:
 
   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const;
 
+  HYDRODATA_EXPORT bool ImportSHP( const QString& theSHPFileName );
+
   HYDRODATA_EXPORT DBFStatus ImportDBF( const QString& theDBFFileName, 
                                         const QString& theFieldName, 
                                         const QStringList& DBFValues,
                                         const QStringList& StricklerTypes,
                                         const QList<int>& theIndices = QList<int>() );
  
+  HYDRODATA_EXPORT void ExportSHP( const QString& theSHPFileName ) const;
+
   HYDRODATA_EXPORT void ExportDBF( const QString& theDBFFileName,
                                    const QString& theFieldName, 
                                    const QStringList& theDBFValues,
index a196a37840696527ae32cb5a10e374c3cdb8e25f..2fe2c10e30009d200c1cccde9a03ee73d6823c47 100644 (file)
@@ -52,6 +52,9 @@ public:
   HYDROData_LandCoverMap();
   ~HYDROData_LandCoverMap();
 
+  bool ImportSHP( const QString& theSHPFileName );
+  void ExportSHP( const QString& theSHPFileName ) const;
+
   DBFStatus ImportDBF( const QString& theDBFFileName, 
     const QString& theFieldName, 
     const QStringList& DBFValues,
index 50c43226bb36c2dacdbb5dc0adf1ddc262ea7996..a0f6b3cd1c3b1e7e88d3d3f8aa01826a93303e01 100644 (file)
@@ -87,5 +87,6 @@ types.append( u"Zones de champs cultivé à végétation haute" )
 types.append( u"Zones de champs, prairies, sans cultures" )
 types.append( u"Zones à faible urbanization (bourg)" )
 types.append( u"Zones à forte urbanization (agglomération)" )
+test_LCM.ImportSHP( 'lc_dump.shp' )
 test_LCM.ImportDBF( 'lc_dump.dbf', 'CODE_06', attr_values, types )