Convert.asmx.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Services;
  6. using System.Data;
  7. using System.IO;
  8. using Utility.Utils.ConvertUtils;
  9. using CoordinateFactory;
  10. using Utility.Utils.OfficeUtils;
  11. using Newtonsoft.Json;
  12. using System.Net;
  13. using System.Text;
  14. using ConvertService.App_Code;
  15. namespace ConvertService
  16. {
  17. /// <summary>
  18. /// Convert 的摘要说明
  19. /// </summary>
  20. [WebService(Namespace = "http://tempuri.org/")]
  21. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  22. [System.ComponentModel.ToolboxItem(false)]
  23. // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
  24. // [System.Web.Script.Services.ScriptService]
  25. public class Convert : System.Web.Services.WebService
  26. {
  27. [WebMethod]
  28. public string locate(double lon, double lat)
  29. {
  30. try
  31. {
  32. double[] arr = null;
  33. Object thisLock = new Object();
  34. // lock (thisLock)
  35. {
  36. arr = CoordinateConvertor.ConvertToShLocal(lon, lat);
  37. }
  38. if (arr==null || arr.Length != 2)
  39. {
  40. return "error";
  41. }else{
  42. return arr[0].ToString("f2") + "," + arr[1].ToString("f2");
  43. }
  44. }catch(Exception e){
  45. return "error";
  46. }
  47. }
  48. [WebMethod]
  49. public string bd2sh(double lon, double lat)
  50. {
  51. try
  52. {
  53. string gps = PositionUtil.bd09_To_Gps84(lat, lon);
  54. double a = System.Convert.ToDouble(gps.Split(',')[0].ToString());
  55. double b = System.Convert.ToDouble(gps.Split(',')[1].ToString());
  56. double[] arr = CoordinateConvertor.ConvertToShLocal(a, b);
  57. if (arr == null || arr.Length != 2)
  58. {
  59. return "error";
  60. }
  61. else
  62. {
  63. return arr[0].ToString("f2") + "," + arr[1].ToString("f2");
  64. }
  65. }
  66. catch (Exception e)
  67. {
  68. return "error";
  69. }
  70. }
  71. //[WebMethod]
  72. //public String excellocate(string fileName)
  73. //{
  74. // string dic = System.Configuration.ConfigurationManager.AppSettings["dic"].ToString() + "定位\\";
  75. // ExcelUtil excel = new ExcelUtil();
  76. // try
  77. // {
  78. // FileStream fs = new FileStream(dic + fileName, FileMode.Open);
  79. // excel.FromStream(fs);
  80. // DataTable dt = excel.GetDataTable(0, true, 0);
  81. // convert(dt, "经度", "纬度");
  82. // return MapDataFormater.DataTable2FeatureJarray(dt, "经度", "纬度").ToString();
  83. // }
  84. // catch (Exception e)
  85. // {
  86. // return "error";
  87. // }
  88. //}
  89. private void convert(DataTable dt, String xfield = "LONGITUDE", String yfield = "LATITUDE")
  90. {
  91. for (int i = 0; i < dt.Rows.Count; i++)
  92. {
  93. double lon = dt.Rows[i][xfield].ToDouble();
  94. double lat = dt.Rows[i][yfield].ToDouble();
  95. double[] arr = CoordinateConvertor.ConvertToShLocal(lon, lat);
  96. if (arr.Length != 2)
  97. {
  98. dt.Rows[i][xfield] = 0;
  99. dt.Rows[i][yfield] = 0;
  100. }
  101. else
  102. {
  103. dt.Rows[i][xfield] = arr[0];
  104. dt.Rows[i][yfield] = arr[1];
  105. }
  106. }
  107. }
  108. }
  109. }