+bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName,
+ const QList<int>& theIndices )
+{
+ HYDROData_ShapeFile anImporter;
+ QStringList aPolyList;
+ TopTools_SequenceOfShape aFaces;
+ int aSHapeType = -1;
+ int Stat = anImporter.ImportPolygons(HYDROData_Document::Document(1), theSHPFileName, aPolyList, aFaces, aSHapeType);
+ //
+ if (Stat != 1)
+ return false;
+ //
+ HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+ int maxInd = *std::max_element(theIndices.begin(), theIndices.end());
+ if (maxInd > aPolyList.length())
+ return false;
+ //
+ if (theIndices.empty())
+ {
+ //import all shapes
+ for ( int i = 1; i <=aFaces.Length(); i++ )
+ {
+ TopoDS_Shape aShape = aFaces(i);
+ if ( aShape.IsNull() )
+ continue;
+ aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+ }
+ }
+ else
+ {
+ //import given indices
+ foreach ( int Ind, theIndices )
+ {
+ TopoDS_Shape aShape = aFaces(Ind + 1);
+ if ( aShape.IsNull() )
+ continue;
+ aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+ }
+ }
+ //
+ StoreLandCovers(aMapFace2ST);
+ return true;
+}
+
+bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUseDiscr, double theDefl) const
+{
+ HYDROData_ShapeFile anExporter;
+ QStringList aList;
+ anExporter.Export(HYDROData_Document::Document(1), theSHPFileName, this, aList, bUseDiscr, theDefl );
+ if (aList.empty())
+ return true;
+ else
+ return false;
+}
+
+bool HYDROData_LandCoverMap::CheckLinear()
+{
+ TopoDS_Shape InpShape = GetShape();
+ TopExp_Explorer anEdgeEx(InpShape, TopAbs_EDGE);
+ for (; anEdgeEx.More(); anEdgeEx.Next())
+ {
+ TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
+ double aFP, aLP;
+ Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
+ Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
+ if (aLine.IsNull())
+ {
+ Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
+ if (!aTC.IsNull())
+ {
+ Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
+ if (aLine.IsNull())
+ return false;
+ }
+ else
+ return false;
+ }
+ }
+ return true;
+}
+
+void HYDROData_LandCoverMap::UpdateLocalCS( double theDx, double theDy )
+{
+ TopoDS_Shape aShape = GetShape();
+ TopoDS_Shape aLocatedShape = HYDROData_ShapesTool::Translated( aShape, theDx, theDy, 0 );
+ SetShape( aLocatedShape );
+}
+
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints, std::vector<std::set <QString> >& theTypes ) const
+{
+ HYDROData_LCM_FaceClassifier FC(this);
+ FC.Classify(thePoints, theTypes, NULL);
+}
+
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,
+ Handle(HYDROData_StricklerTable) theTable,
+ std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const
+{
+ std::vector<std::set <QString> > Types;
+ HYDROData_LCM_FaceClassifier FC(this);
+ FC.Classify(thePoints, Types, NULL);
+ theCoeffs.resize(thePoints.size());
+ for (size_t i = 0; i < Types.size(); i++)
+ {
+ const std::set<QString>& SStr = Types[i];
+ if (SStr.empty())
+ theCoeffs[i] = DefValue;
+ else
+ {
+ std::set<QString>::const_iterator it;
+ std::vector<double> C1(SStr.size());
+ for (it = SStr.begin(); it != SStr.end(); ++it)
+ C1.push_back(theTable->Get( *it, DefValue ));
+ double Val;
+ if (UseMax)
+ Val = *(std::max_element(std::begin(C1), std::end(C1)));
+ else
+ Val = *(std::min_element(std::begin(C1), std::end(C1)));
+ theCoeffs[i] = Val;
+ }
+ }