📄 shapes_io.cpp
字号:
}
SG_UI_Process_Set_Ready();
return( bError == false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define Save_ESRI_RecordHeader Stream .Write_Int(RecordNumber++, true);\
Stream .Write_Int(ContentLength , true);\
Stream_Idx.Write_Int(FileLength , true);\
Stream_Idx.Write_Int(ContentLength , true);\
FileLength += 4 + ContentLength;\
FileLength_idx += 4;\
//---------------------------------------------------------
bool CSG_Shapes::_Save_ESRI(const SG_Char *File_Name)
{
char buf_Header[100];
int FileLength, FileLength_idx, Type_File,
RecordNumber, ContentLength,
iShape, iPoint, iPart, nPoints;
TSG_Point dPoint;
TSG_Rect dRect;
CSG_String fName;
CSG_File Stream, Stream_Idx;
CSG_Shape *pShape;
//-----------------------------------------------------
// Set Shape m_Type...
switch( m_Type )
{
case SHAPE_TYPE_Point: // Point...
Type_File = 1;
break;
case SHAPE_TYPE_Points: // Multipoint...
Type_File = 8;
break;
case SHAPE_TYPE_Line: // Line, Polyline...
Type_File = 3;
break;
case SHAPE_TYPE_Polygon: // Polygon...
Type_File = 5;
break;
default: // unsupported...
return( false );
}
//-----------------------------------------------------
// File Access...
SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Save shapes"), File_Name), true);
fName = SG_File_Make_Path(NULL, File_Name, SG_T("shx"));
if( !Stream_Idx.Open(fName, SG_FILE_W, true) )
{
SG_UI_Msg_Add(LNG("[MSG] failed"), false);
SG_UI_Msg_Add_Error(LNG("[ERR] Shape index file could not be opened."));
return( false );
}
fName = SG_File_Make_Path(NULL, File_Name, SG_T("shp"));
if( !Stream.Open(fName, SG_FILE_W, true) )
{
SG_UI_Msg_Add(LNG("[MSG] failed"), false);
SG_UI_Msg_Add_Error(LNG("[ERR] Shape file could not be opened."));
return( false );
}
SG_UI_Process_Set_Text(CSG_String::Format(SG_T("%s: %s"), LNG("[DAT] Save shapes"), fName.c_str() ));
//-----------------------------------------------------
// Save Header...
_Extent_Update();
dRect = m_Extent.m_rect;
SG_Mem_Set_Int (buf_Header + 0, 9994 , true ); // Byte 0 -> File Code 9994 Integer Big...
SG_Mem_Set_Int (buf_Header + 4, 0 , true ); // Byte 4 -> unused Integer Big...
SG_Mem_Set_Int (buf_Header + 8, 0 , true ); // Byte 8 -> unused Integer Big...
SG_Mem_Set_Int (buf_Header + 12, 0 , true ); // Byte 12 -> unused Integer Big...
SG_Mem_Set_Int (buf_Header + 16, 0 , true ); // Byte 16 -> unused Integer Big...
SG_Mem_Set_Int (buf_Header + 20, 0 , true ); // Byte 20 -> unused Integer Big...
SG_Mem_Set_Int (buf_Header + 24, 0 , true ); // Byte 24 -> File Length File Length Integer Big...
SG_Mem_Set_Int (buf_Header + 28, 1000 , false); // Byte 28 -> Version 1000 Integer Little...
SG_Mem_Set_Int (buf_Header + 32, Type_File , false); // Byte 32 -> Shape m_Type Shape m_Type Integer Little...
SG_Mem_Set_Double (buf_Header + 36, dRect.xMin, false); // Byte 36 -> Bounding Box Xmin Double Little...
SG_Mem_Set_Double (buf_Header + 44, dRect.yMin, false); // Byte 44 -> Bounding Box Ymin Double Little...
SG_Mem_Set_Double (buf_Header + 52, dRect.xMax, false); // Byte 52 -> Bounding Box Xmax Double Little...
SG_Mem_Set_Double (buf_Header + 60, dRect.yMax, false); // Byte 60 -> Bounding Box Ymax Double Little...
SG_Mem_Set_Double (buf_Header + 68, 0 , false); // Byte 68 -> Bounding Box Zmin Double Little...
SG_Mem_Set_Double (buf_Header + 76, 0 , false); // Byte 76 -> Bounding Box Zmax Double Little...
SG_Mem_Set_Double (buf_Header + 84, 0 , false); // Byte 84 -> Bounding Box Mmin Double Little...
SG_Mem_Set_Double (buf_Header + 92, 0 , false); // Byte 92 -> Bounding Box Mmax Double Little...
Stream .Write(buf_Header, sizeof(char), 100);
Stream_Idx .Write(buf_Header, sizeof(char), 100);
FileLength = 50; // FileLength measured in 16-bit words...
FileLength_idx = 50; // FileLength measured in 16-bit words...
RecordNumber = 1;
//-----------------------------------------------------
// Save Shapes...
for(iShape=0; iShape<Get_Count() && SG_UI_Process_Set_Progress(iShape, Get_Count()); iShape++)
{
pShape = Get_Shape(iShape);
switch( Type_File )
{
//-------------------------------------------------
case 1: // Point...
//---------------------------------------------
// Record-Header...
ContentLength = 10; // ShapeType + Point...
Save_ESRI_RecordHeader;
//---------------------------------------------
// Shape-Header...
Stream.Write(&Type_File , sizeof(Type_File));
//---------------------------------------------
// Shape-Points...
dPoint = pShape->Get_Point(0);
Stream.Write(&dPoint , sizeof(TSG_Point));
break;
//-------------------------------------------------
case 8: // Multipoint...
//---------------------------------------------
// Total Number of Points in Shape...
for(iPart=0, nPoints=0; iPart<pShape->Get_Part_Count(); iPart++)
{
nPoints += pShape->Get_Point_Count(iPart);
}
//-----------------------------------------
// Record-Header...
ContentLength = 10; // ShapeType + Point...
Save_ESRI_RecordHeader;
//-----------------------------------------
// Shape-Header...
dRect = pShape->Get_Extent();
Stream.Write(&Type_File , sizeof(Type_File));
Stream.Write(&dRect , sizeof(TSG_Rect));
Stream.Write(&nPoints , sizeof(int));
//-----------------------------------------
// Shape-Points...
for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
{
for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
{
dPoint = pShape->Get_Point(iPoint, iPart);
Stream.Write(&dPoint, sizeof(TSG_Point));
}
}
break;
//-------------------------------------------------
case 3: case 5: // Line, Polygon...
//---------------------------------------------
// Total Number of Points in Shape...
for(iPart=0, nPoints=0; iPart<pShape->Get_Part_Count(); iPart++)
{
nPoints += pShape->Get_Point_Count(iPart);
}
//---------------------------------------------
// Record-Header...
ContentLength = 22 + 2 * pShape->Get_Part_Count() + 8 * nPoints; // ShapeType + nParts + nParts*Offsets + nPoints...
Save_ESRI_RecordHeader;
//---------------------------------------------
// Shape-Header...
dRect = pShape->Get_Extent();
iPart = pShape->Get_Part_Count();
Stream.Write(&Type_File , sizeof(Type_File));
Stream.Write(&dRect , sizeof(TSG_Rect));
Stream.Write(&iPart , sizeof(int));
Stream.Write(&nPoints , sizeof(int));
for(iPart=0, iPoint=0; iPart<pShape->Get_Part_Count(); iPart++)
{
Stream.Write(&iPoint, sizeof(int));
iPoint += pShape->Get_Point_Count(iPart);
}
//---------------------------------------------
// Shape-Points...
for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
{
for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
{
dPoint = pShape->Get_Point(iPoint, iPart);
Stream.Write(&dPoint, sizeof(TSG_Point));
}
}
break;
}
}
//-----------------------------------------------------
// File Sizes...
Stream .Seek(24);
Stream_Idx .Seek(24);
Stream .Write_Int(FileLength , true);
Stream_Idx .Write_Int(FileLength_idx, true);
SG_UI_Msg_Add(LNG("[MSG] okay"), false);
SG_UI_Process_Set_Ready();
//-----------------------------------------------------
// Attributes...
fName = SG_File_Make_Path(NULL, File_Name, SG_T("dbf"));
return( m_Table.Save(fName, TABLE_FILETYPE_DBase) );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -