⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 esri_e00_import.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:

	if( depth == 2 && prec )
	{
		depth	= 3;
	}

	//-----------------------------------------------------
	switch( depth )
	{
	default:
		pGrid	= NULL;
		break;

	//-----------------------------------------------------
	case 1:
		pGrid	= SG_Create_Grid(GRID_TYPE_Int, cols, rows, xres, xmin, ymin);
		pGrid->Set_NoData_Value(nul_val);

		for(y=0; y<rows && line && Set_Progress(y, rows); y++)
		{
			for(x=0; x<cols; x+= 5)
			{
				if( (line = E00ReadNextLine(hReadPtr)) != NULL )
				{
					sscanf(line, "%ld%ld%ld%ld%ld", p, p+1, p+2, p+3, p+4);

					for(ix=0; ix<5 && x+ix<cols; ix++)
					{
						pGrid->Set_Value(x + ix, y, p[ix]);
					}
				}
			}
		}
		break;

	//-----------------------------------------------------
	case 2:
		pGrid	= SG_Create_Grid(GRID_TYPE_Float, cols, rows, xres, xmin, ymin);
		pGrid->Set_NoData_Value(nul_val);

		for(y=0; y<rows && line && Set_Progress(y, rows); y++)
		{
			for(x=0; x<cols; x+= 5)
			{
				if( (line = E00ReadNextLine(hReadPtr)) != NULL )
				{
					sscanf(line, "%f%f%f%f%f", f, f+1, f+2, f+3, f+4);

					for(ix=0; ix<5 && x+ix<cols; ix++)
					{
						pGrid->Set_Value(x + ix, y, f[ix]);
					}
				}
			}
		}
		break;

	//-----------------------------------------------------
	case 3:
		pGrid	= SG_Create_Grid(GRID_TYPE_Double, cols, rows, xres, xmin, ymin);
		pGrid->Set_NoData_Value(nul_val);

		for(y=0; y<rows && line && Set_Progress(y, rows); y++)
		{
			for(x=0; x<cols; x+= 3)
			{
				if( (line = E00ReadNextLine(hReadPtr)) != NULL )
				{
					sscanf(line, "%lf%lf%lf", d, d+1, d+2);

					for(ix=0; ix<3 && x+ix<cols; ix++)
					{
						pGrid->Set_Value(x + ix, y, d[ix]);
					}
				}
			}
		}
		break;
	}

	//-----------------------------------------------------
	skip("EOG");

	return( pGrid );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#define ARC_FNODE	2
#define ARC_TNODE	3
#define ARC_LPOL	4
#define ARC_RPOL	5

//---------------------------------------------------------
CSG_Shapes * CESRI_E00_Import::getarcs(int prec, double scale, TSG_Shape_Type &shape_type)
{
	const char	*line;

	int		covnum, cov_id, fnode, tnode, lpol, rpol, nPoints, iPoint;
	double	x_buf[2], y_buf[2];
	CSG_Shape	*pShape;
	CSG_Shapes	*pShapes;

	//-----------------------------------------------------
	pShapes	= SG_Create_Shapes(shape_type);
	pShapes->Get_Table().Add_Field("ID"	, TABLE_FIELDTYPE_Int);
	pShapes->Get_Table().Add_Field("ID#"	, TABLE_FIELDTYPE_Int);
	pShapes->Get_Table().Add_Field("FNODE"	, TABLE_FIELDTYPE_Int);
	pShapes->Get_Table().Add_Field("TNODE"	, TABLE_FIELDTYPE_Int);
	pShapes->Get_Table().Add_Field("LPOL"	, TABLE_FIELDTYPE_Int);
	pShapes->Get_Table().Add_Field("RPOL"	, TABLE_FIELDTYPE_Int);

	Set_Progress(0, 100);

	//-----------------------------------------------------
	do
	{
		Process_Set_Text(CSG_String::Format(SG_T("Loaded arcs: %d"), pShapes->Get_Count()));

		if( (line = E00ReadNextLine(hReadPtr)) == NULL )
		{
			covnum	= -1;
		}
		else
		{
			sscanf(line, "%d %d %d %d %d %d %d", &covnum, &cov_id, &fnode, &tnode, &lpol, &rpol, &nPoints);
		}

		if( covnum != -1 )
		{
			pShape	= pShapes->Add_Shape();

			pShape->Get_Record()->Set_Value(0			, covnum);
			pShape->Get_Record()->Set_Value(1			, cov_id);
			pShape->Get_Record()->Set_Value(ARC_FNODE	, fnode);
			pShape->Get_Record()->Set_Value(ARC_TNODE	, tnode);
			pShape->Get_Record()->Set_Value(ARC_LPOL	, lpol);
			pShape->Get_Record()->Set_Value(ARC_RPOL	, rpol);

			//---------------------------------------------
			if( prec )	// double precision : 1 coord pair / line
			{
				for(iPoint=0; iPoint<nPoints && line; iPoint++)
				{
					if( (line = E00ReadNextLine(hReadPtr)) != NULL )
					{
						sscanf(line, "%lf %lf", x_buf, y_buf);

						pShape->Add_Point(x_buf[0] * scale, y_buf[0] * scale);
					}
				}
			}

			//---------------------------------------------
			else		// single precision : 2 x,y pairs / line
			{
				for(iPoint=0; iPoint<nPoints && line; iPoint+=2)
				{
					if( (line = E00ReadNextLine(hReadPtr)) != NULL )
					{
						sscanf(line, "%lf %lf %lf %lf", x_buf, y_buf, x_buf + 1, y_buf + 1);

						pShape->Add_Point(x_buf[0] * scale, y_buf[0] * scale);

						if( iPoint + 1 < nPoints )
						{
							pShape->Add_Point(x_buf[1] * scale, y_buf[1] * scale);
						}
					}
				}
			}
		}
	}
	while( covnum != -1 && line && Process_Get_Okay(false) );

	//-----------------------------------------------------
	if( pShapes->Get_Count() == 0 )
	{
		delete(pShapes);

		shape_type	= SHAPE_TYPE_Point;

		return( NULL );
	}

	if( shape_type == SHAPE_TYPE_Polygon )
	{
		pShapes	= Arcs2Polygons(pShapes);

		Assign_Attributes(pShapes);
	}

	return( pShapes );
}

//---------------------------------------------------------
CSG_Shapes * CESRI_E00_Import::Arcs2Polygons(CSG_Shapes *pArcs)
{
	int			iArc, nArcs, id;
	CSG_Shapes	*pPolygons;

	//-----------------------------------------------------
	Process_Set_Text(_TL("Arcs to polygons"));

	pPolygons	= SG_Create_Shapes(SHAPE_TYPE_Polygon);
	pPolygons->Get_Table().Add_Field("ID", TABLE_FIELDTYPE_Int);

	nArcs		= pArcs->Get_Count();

	//-----------------------------------------------------
	while( (iArc = pArcs->Get_Count() - 1) >= 0 && Set_Progress(nArcs - iArc - 1, nArcs) )
	{
		id	= pArcs->Get_Shape(iArc)->Get_Record()->asInt(ARC_LPOL);

		if( id == pArcs->Get_Shape(iArc)->Get_Record()->asInt(ARC_RPOL) )
		{
			pArcs->Del_Shape(iArc);
		}
		else if( id > 1 )
		{
			Arcs2Polygon(pArcs, pPolygons, id);
		}

		if( (iArc = pArcs->Get_Count() - 1) >= 0 )
		{
			id	= pArcs->Get_Shape(iArc)->Get_Record()->asInt(ARC_RPOL);

			if( id > 1 )
			{
				Arcs2Polygon(pArcs, pPolygons, id);
			}
		}
	}

	//-----------------------------------------------------
	delete( pArcs );

	return( pPolygons );
}

//---------------------------------------------------------
void CESRI_E00_Import::Arcs2Polygon(CSG_Shapes *pArcs, CSG_Shapes *pPolygons, int id)
{
	int		iShape, iPart, iPoint, iNode;
	CSG_Shape	*pArc, *pShape;
	CSG_Shapes	Arcs;

	//-----------------------------------------------------
	Arcs.Create(SHAPE_TYPE_Line);
	Arcs.Get_Table().Add_Field("FROM_NODE", TABLE_FIELDTYPE_Int);
	Arcs.Get_Table().Add_Field("TO___NODE", TABLE_FIELDTYPE_Int);

	//-----------------------------------------------------
	for(iShape=pArcs->Get_Count()-1; iShape>=0; iShape--)
	{
		pShape	= pArcs->Get_Shape(iShape);

		if( id == pShape->Get_Record()->asInt(ARC_LPOL) )
		{
			pArc	= Arcs.Add_Shape();
			pArc->Get_Record()->Set_Value(0, pShape->Get_Record()->asInt(ARC_FNODE));
			pArc->Get_Record()->Set_Value(1, pShape->Get_Record()->asInt(ARC_TNODE));

			for(iPoint=0; iPoint<pShape->Get_Point_Count(0); iPoint++)
			{
				pArc->Add_Point(pShape->Get_Point(iPoint, 0), 0);
			}

			if( pShape->Get_Record()->asInt(ARC_RPOL) <= 1 )
			{
				pArcs->Del_Shape(iShape);
			}
			else
			{
				pShape->Get_Record()->Set_Value(ARC_LPOL, 1);
			}
		}
		else if( id == pShape->Get_Record()->asInt(ARC_RPOL) )
		{
			pArc	= Arcs.Add_Shape();
			pArc->Get_Record()->Set_Value(1, pShape->Get_Record()->asInt(ARC_FNODE));
			pArc->Get_Record()->Set_Value(0, pShape->Get_Record()->asInt(ARC_TNODE));

			for(iPoint=pShape->Get_Point_Count(0)-1; iPoint>=0; iPoint--)
			{
				pArc->Add_Point(pShape->Get_Point(iPoint, 0), 0);
			}

			if( pShape->Get_Record()->asInt(ARC_LPOL) <= 1 )
			{
				pArcs->Del_Shape(iShape);
			}
			else
			{
				pShape->Get_Record()->Set_Value(ARC_RPOL, 1);
			}
		}
	}

	//-----------------------------------------------------
	if( Arcs.Get_Count() > 0 )
	{
		iPart	= 0;
		pShape	= pPolygons->Add_Shape();
		pShape->Get_Record()->Set_Value(0, id);

		do
		{
			pArc	= Arcs.Get_Shape(0);

			while( pArc )
			{
				for(iPoint=0; iPoint<pArc->Get_Point_Count(0); iPoint++)
				{
					pShape->Add_Point(pArc->Get_Point(iPoint, 0), iPart);
				}

				iNode	= pArc->Get_Record()->asInt(1);
				Arcs.Del_Shape(pArc);

				for(iShape=0, pArc=NULL; iShape<Arcs.Get_Count() && !pArc; iShape++)
				{
					if( iNode == Arcs.Get_Shape(iShape)->Get_Record()->asInt(0) )
					{
						pArc	= Arcs.Get_Shape(iShape);
					}
				}
			}

			iPart++;
		}
		while( Arcs.Get_Count() > 0 );
	}
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CSG_Shapes * CESRI_E00_Import::getlabels(int prec, double scale)	// shape_type: LINE or AREA
{
	const char	*line;

	int		num, id;	// coverage-# and coverage-ID
	double	x, y;
	CSG_Shapes	*pShapes;
	CSG_Shape	*pShape;

	pShapes	= SG_Create_Shapes(SHAPE_TYPE_Point);

	pShapes->Get_Table().Add_Field("ID#"	, TABLE_FIELDTYPE_Int);
	pShapes->Get_Table().Add_Field("ID"	, TABLE_FIELDTYPE_Int);

	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
	{
		sscanf(line, "%d %d %lf %lf", &id, &num, &x, &y);

		if( id == -1 )
		{
			break;
		}
		else
		{
			pShape	= pShapes->Add_Shape();

			pShape->Add_Point(x * scale, y * scale);

			pShape->Get_Record()->Set_Value(0, num);
			pShape->Get_Record()->Set_Value(1, id);

			//---------------------------------------------
			E00ReadNextLine(hReadPtr);		// 4 values to skip

			if( prec )
			{
				E00ReadNextLine(hReadPtr);	// on 2nd line when double precision
			}
		}
	}

	if( pShapes->Get_Count() <= 0 )
	{
		delete( pShapes );
		pShapes	= NULL;
	}

	return( pShapes );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CSG_Shapes * CESRI_E00_Import::getsites(int prec, double scale)
{
	const char	*line;

	int		id;
	double	x, y;
	CSG_Shape	*pShape;
	CSG_Shapes	*pShapes;

	pShapes	= SG_Create_Shapes(SHAPE_TYPE_Point);
	pShapes->Get_Table().Add_Field("ID", TABLE_FIELDTYPE_Int);

	while( (line = E00ReadNextLine(hReadPtr)) != NULL )
	{
		sscanf(line, "%d %*d %lf %lf", &id, &x, &y);

		if( id == -1 )
		{
			break;
		}

		pShape	= pShapes->Add_Shape();

		pShape->Add_Point(x * scale, y * scale);
		pShape->Get_Record()->Set_Value(0, id);

		//-------------------------------------------------
		E00ReadNextLine(hReadPtr);		// 4 values to skip

		if( prec )
		{
			E00ReadNextLine(hReadPtr);	// on 2nd line when double precision
		}
	}

	if( pShapes->Get_Count() <= 0 )
	{
		delete( pShapes );
		pShapes	= NULL;
	}
	else
	{
		Assign_Attributes(pShapes);
	}

	return( pShapes );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
double CESRI_E00_Import::getproj(void)
{
	const char	*line;

	double	scale	= 1.0;

	while( (line = E00ReadNextLine(hReadPtr)) != NULL && strncmp(line, "EOP", 3) )
	{
		if( !strncmp(line, "Units", 5) )
		{
			sscanf(line + 6, "%lf", &scale);
		}
	}

	scale	= 1.0 / scale;

	return( scale );
}


///////////////////////////////////////////////////////////
//														 //
//						info section					 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
struct info_Field
{
	char				Name[18];	// name of item

	int					Position,	// position in data line
						Size,		// size for reading
						Type;		// type of data
};

//---------------------------------------------------------
struct info_Table
{
	char				Name[34],
						AI[4];		// XX if Arc/info file, spaces otherwise

	int					uFields,	// number of usable items in this table
						nFields,	// number of items in this table
						ldr;		// length of data record

	long				nRecords,	// number of data records
						length;		// total length for one data line

	struct info_Field	*Field;		// One per field...
};

//---------------------------------------------------------
// [06.06.2006] ESRI E00 Import crash fix, James Flemer
int CESRI_E00_Import::info_Get_Tables(void)
{
	const char *line;

	char				tmp[12], *p;
	int					i;
	CSG_String			s;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -