【发布时间】:2017-05-25 21:57:58
【问题描述】:
我正在使用 asp.net 开发一个本地化网站。它的工作原理是从数据库中制作 .kml 文件并将其显示在地图上。
我的问题是我在数据库中的坐标具有比双精度更高的精度(15 个字符)例如:34.25912472611852,-6.588685512542725 所以我使用了十进制类型,但我正在努力使用 CoordinateCollection,它只接受具有双值的向量
这是我的代码帮助。谢谢
public kml_createur()
{
var document = new Document();
document.Id = "null";
document.Name = "null";
LineString linestring = new LineString();
CoordinateCollection coordinates = new CoordinateCollection();
SqlConnection sqlcon = new SqlConnection("Data Source=DESKTOP-2FB04SU\\SQLEXPRESS; Initial Catalog = sys_geo_domaine_etat_db; Integrated Security=True");
String com = "select X, Y from Coordonner where idTerrain = 1";
SqlCommand sqlcom = new SqlCommand(com, sqlcon);
//sqlcom.CommandType = CommandType.StoredProcedure;
//sqlcom.Parameters.Add("@IMEI", SqlDbType.VarChar).Value = TextBox1.Text;
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlcom);
sda.Fill(dt);
try
{
sqlcon.Open();
sqlcom.ExecuteNonQuery();
foreach (DataRow dr in dt.Rows)
{
decimal lon = decimal.Parse(dr["x"].ToString());
decimal lat = decimal.Parse(dr["y"].ToString());
//这是错误-------- 向量 v = 新向量(经度,纬度); --------------------------
坐标.Add(v);
}
Polygon p = new Polygon();
LinearRing lr = new LinearRing();
OuterBoundary o = new OuterBoundary();
p.OuterBoundary = o;
p.OuterBoundary.LinearRing=lr;
p.OuterBoundary.LinearRing.Coordinates = coordinates;
Placemark placemark = new Placemark();
placemark.Name = "terrain";
placemark.Geometry = p;
document.AddFeature(placemark);
var kml = new Kml();
kml.Feature = document;
kml.Feature = placemark;
KmlFile kmlFile = KmlFile.Create(kml, true);
using (var stream = System.IO.File.OpenWrite("D:\\marouane\\file.KML"))
{
kmlFile.Save(stream);
System.Diagnostics.Debug.Write("file created");
}
}
catch (Exception exc)
{
System.Diagnostics.Debug.Write(exc.Message);
}
finally
{
sqlcon.Close();
}
}
【问题讨论】:
标签: asp.net double decimal coordinates