【问题标题】:probleme coordinates with bigger precision then double ???精度更高的问题坐标然后加倍???
【发布时间】: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


    【解决方案1】:

    首先,您应该使用 SqlDataReader 而不是数据表,我认为您的代码永远不会提取数据。

    using (SqlDataReader reader = sqlcom.ExecuteReader())
    {
    while (reader.read())
    {
    decimal lon = decimal.Parse(reader("x"));
                decimal lat = decimal.Parse(reader("y"));
    }
    }
    

    在那之后,我对您的错误消息的更完整描述可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-07-09
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      相关资源
      最近更新 更多