return;
}
-void HYDROData_ShapeFile::Parse1(SHPHandle theHandle)
+void HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType)
{
int aShapeType;
mySHPObjects.clear();
SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
- if (aShapeType == 5)
+ bool ToRead = (theType == ShapeType_Polyline && (aShapeType == 3 || aShapeType == 13 || aShapeType == 23)) ||
+ (theType == ShapeType_Polygon && aShapeType == 5);
+ if (ToRead)
{
for (int i = 0; i < theHandle->nRecords; i++)
mySHPObjects.push_back(SHPReadObject(theHandle, i));
}
}
-void HYDROData_ShapeFile::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F)
+void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F)
{
TopoDS_Wire W;
TopoDS_Edge E;
{
Free();
myHSHP = SHPOpen( theFileName.toAscii().data(), "rb" );
- Parse1(myHSHP);
- for (int i = 0; i < mySHPObjects.size(); i++)
+ Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon);
+ for (size_t i = 0; i < mySHPObjects.size(); i++)
thePolygonsList.append("polygon_" + QString::number(i + 1));
TopoDS_Face aF;
if (myHSHP->nShapeType == 5)
{
- for (int i = 0; i < mySHPObjects.size(); i++)
+ for (size_t i = 0; i < mySHPObjects.size(); i++)
{
- ProcessSHP(mySHPObjects[i], i, aF);
+ ReadSHPPolygon(mySHPObjects[i], i, aF);
theFaces.Append(aF);
}
return true;
}
-void HYDROData_ShapeFile::ProcessSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
{
}
-void HYDROData_ShapeFile::ProcessSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
{
Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
}
-void HYDROData_ShapeFile::Parse2(SHPHandle theHandle)
-{
- int aShapeType;
- mySHPObjects.clear();
- SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
- if (aShapeType == 3 || aShapeType == 13 || aShapeType == 23)
- {
- for (int i = 0; i < theHandle->nRecords; i++)
- mySHPObjects.push_back(SHPReadObject(theHandle, i));
- }
-}
+
bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
{
QFileInfo aFileInfo(theFileName);
QString aBaseFileName = aFileInfo.baseName();
- Parse2(aHSHP);
+ Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline);
bool aStat = false;
if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23)
{
for (size_t i = 0; i < mySHPObjects.size(); i++ )
{
- ProcessSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities);
+ ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities);
}
aStat = true;
}
anInd++;
}
for (size_t i = 0; i < mySHPObjects.size(); i++ )
- ProcessSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities);
+ ReadSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities);
aStat = true;
}
else
class HYDROData_ShapeFile
{
+enum ShapeType
+{
+ ShapeType_Polyline,
+ ShapeType_Polygon
+};
+
public:
HYDRODATA_EXPORT HYDROData_ShapeFile( );
virtual HYDRODATA_EXPORT ~HYDROData_ShapeFile();
-public:
//Export operation
HYDRODATA_EXPORT void Export(const QString& aFileName,
NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly );
int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly );
int WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC );
+ //Import
+ void Parse(SHPHandle theHandle, ShapeType theType);
//Import Landcover
- void Parse1(SHPHandle theHandle);
- void ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F);
+ void ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F);
HYDRODATA_EXPORT bool ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces);
HYDRODATA_EXPORT void Free();
//Import Polyline
- void Parse2( SHPHandle theHandle);
- void ProcessSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+ void ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
- void ProcessSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
+ void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName,
int theInd, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
HYDRODATA_EXPORT bool ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName,
NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);