From: asl Date: Mon, 16 Nov 2015 08:44:35 +0000 (+0300) Subject: #651: dump to Python of land cover map X-Git-Tag: v1.5~40^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b7155f7adc38585ddaad0cd19dc0cc3ea13693fa;p=modules%2Fhydro.git #651: dump to Python of land cover map --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 33933ce3..79cd2175 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -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 ); diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index fd6dc586..15b697f4 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -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& theIndices = QList() ); + HYDRODATA_EXPORT void ExportSHP( const QString& theSHPFileName ) const; + HYDRODATA_EXPORT void ExportDBF( const QString& theDBFFileName, const QString& theFieldName, const QStringList& theDBFValues, diff --git a/src/HYDROPy/HYDROData_LandCoverMap.sip b/src/HYDROPy/HYDROData_LandCoverMap.sip index a196a378..2fe2c10e 100644 --- a/src/HYDROPy/HYDROData_LandCoverMap.sip +++ b/src/HYDROPy/HYDROData_LandCoverMap.sip @@ -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, diff --git a/src/HYDRO_tests/reference_data/lc_dump.py b/src/HYDRO_tests/reference_data/lc_dump.py index 50c43226..a0f6b3cd 100644 --- a/src/HYDRO_tests/reference_data/lc_dump.py +++ b/src/HYDRO_tests/reference_data/lc_dump.py @@ -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 )