读取数据库geometry类型
1. 首先需要在vs中安装Microsoft.SqlServer.Types10.50(可以在NuGet包中安装)
2. 引用using Microsoft.SqlServer.Types;
3. 获得数据库geometry对象存储的点对象:
var point =(SqlGeometry)reader.GetValue(4);//读取数据库的geometry对象
Point = new Point(Convert.ToInt32(point.STX.Value),Convert.ToInt32(point.STY.Value)), //将读取的对象转换为点对象,usingSystem.Drawing
4. 获得数据库geometry对象存储的线对象:
//首先自己定义了一个Line类
var line = (SqlGeometry)reader.GetValue(3);//取出数据库geometry对象
var temp = line.ToString();//将该对象转换为字符串
SqlGeometry geo =SqlGeometry.Parse(temp);//不知道这里是不是多余,可以直接定义为取出的geometry对象
intnum = geo.STNumPoints().Value;//获得数量
for(int i = 1; i <= num; ++i)
{//取出line的两个端点
SqlGeometry geo1 =SqlGeometry.Parse(geo.STPointN(i).ToString());
intx = Convert.ToInt32(geo1.STX.Value);
inty = Convert.ToInt32(geo1.STY.Value);
point[i- 1].X = x;
point[i- 1].Y = y;
}
Line p = new Line(point[0],point[1])();