坐标系统转换
2015-06-10 11:12:04 访问(2724) 赞(0) 踩(0)
/// <summary>
/// We use the Math.Round method since none of the transforms are exact.
/// </summary>
/// <param name="msg"></param>
/// <param name="p1"></param>
/// <param name="p2"></param>
private void ComparePoints(string msg, DPoint p1, DPoint p2)
{
int prec = 5;
if (Math.Round(p1.x, prec) == Math.Round(p2.x, prec) &&
Math.Round(p1.y, prec) == Math.Round(p2.y, prec))
{
outputTextBox.AppendText(msg + " points are equal: (" + Math.Round(p1.x, prec) + ", " + Math.Round(p1.y, prec) + ") == (" + Math.Round(p2.x, prec) + ", " + Math.Round(p2.y, prec) + ")\n");
}
else
{
outputTextBox.AppendText(msg + " points are NOT equal: (" + Math.Round(p1.x, prec) + ", " + Math.Round(p1.y, prec) + ") != (" + Math.Round(p2.x, prec) + ", " + Math.Round(p2.y, prec) + ")\n");
}
}
/// <summary>
/// We are going to use the CoordSys transform to transform a point from one coordsys to another then back
/// again to see if the round trip produces the correct results. Then test the array version of the transform.
/// </summary>
private void UseCoordinateTransform()
{
// create LongLat projection
CoordSys csys = Session.Current.CoordSysFactory.CreateFromPrjString("1, 56");
// Create Robinson projection
CoordSys csys1 = Session.Current.CoordSysFactory.CreateFromPrjString("12, 62, 7, 0");
if (csys == csys1)
{
outputTextBox.AppendText("Oops, coordsys's are equal, this is bad\n");
}
CoordinateTransform coordTransform = Session.Current.CoordSysFactory.CreateCoordinateTransform(csys, csys1);
DPoint pntSrc = new DPoint(0, 0);
DPoint pntDest = coordTransform.CoordSys1ToCoordSys2(pntSrc);
DPoint pntSrc1 = new DPoint(1, 1);
DPoint pntDest1 = coordTransform.CoordSys1ToCoordSys2(pntSrc1);
DPoint pntBackToSrc = coordTransform.CoordSys2ToCoordSys1(pntDest1);
ComparePoints("Round trip", pntSrc1, pntBackToSrc);
// compare the result with arrays
DPoint[] pnt = new DPoint[2];
pnt[0].x = 0;
pnt[0].y = 0;
pnt[1].x = 1;
pnt[1].y = 1;
coordTransform.CoordSys1ToCoordSys2(pnt, out pnt);
ComparePoints("Array converted", pntDest, pnt[0]);
ComparePoints("Array converted", pntDest1, pnt[1]);
}
/*
Round trip points are equal: (1, 1) == (1, 1)
Array converted points are equal: (-185.01084, 1016.56978) == (-185.01084, 1016.56978)
Array converted points are equal: (94252.59365, 107958.96011) == (94252.59365, 107958.96011)
*/
标签:
坐标系统转换 


上一条:
下一条:
相关评论
发表评论