123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using System.Data;
- using System.IO;
- using Utility.Utils.ConvertUtils;
- using CoordinateFactory;
- using Utility.Utils.OfficeUtils;
- using Newtonsoft.Json;
- using System.Net;
- using System.Text;
- using ConvertService.App_Code;
- namespace ConvertService
- {
- /// <summary>
- /// Convert 的摘要说明
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
- // [System.Web.Script.Services.ScriptService]
- public class Convert : System.Web.Services.WebService
- {
- [WebMethod]
- public string locate(double lon, double lat)
- {
- try
- {
-
- double[] arr = null;
- Object thisLock = new Object();
- // lock (thisLock)
- {
- arr = CoordinateConvertor.ConvertToShLocal(lon, lat);
- }
- if (arr==null || arr.Length != 2)
- {
- return "error";
- }else{
- return arr[0].ToString("f2") + "," + arr[1].ToString("f2");
- }
- }catch(Exception e){
- return "error";
- }
-
- }
- [WebMethod]
- public string bd2sh(double lon, double lat)
- {
- try
- {
-
-
- string gps = PositionUtil.bd09_To_Gps84(lat, lon);
- double a = System.Convert.ToDouble(gps.Split(',')[0].ToString());
- double b = System.Convert.ToDouble(gps.Split(',')[1].ToString());
-
- double[] arr = CoordinateConvertor.ConvertToShLocal(a, b);
- if (arr == null || arr.Length != 2)
- {
- return "error";
- }
- else
- {
- return arr[0].ToString("f2") + "," + arr[1].ToString("f2");
- }
- }
- catch (Exception e)
- {
- return "error";
- }
- }
- //[WebMethod]
- //public String excellocate(string fileName)
- //{
- // string dic = System.Configuration.ConfigurationManager.AppSettings["dic"].ToString() + "定位\\";
- // ExcelUtil excel = new ExcelUtil();
- // try
- // {
- // FileStream fs = new FileStream(dic + fileName, FileMode.Open);
- // excel.FromStream(fs);
- // DataTable dt = excel.GetDataTable(0, true, 0);
- // convert(dt, "经度", "纬度");
- // return MapDataFormater.DataTable2FeatureJarray(dt, "经度", "纬度").ToString();
- // }
- // catch (Exception e)
- // {
- // return "error";
- // }
- //}
- private void convert(DataTable dt, String xfield = "LONGITUDE", String yfield = "LATITUDE")
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- double lon = dt.Rows[i][xfield].ToDouble();
- double lat = dt.Rows[i][yfield].ToDouble();
- double[] arr = CoordinateConvertor.ConvertToShLocal(lon, lat);
- if (arr.Length != 2)
- {
- dt.Rows[i][xfield] = 0;
- dt.Rows[i][yfield] = 0;
- }
- else
- {
- dt.Rows[i][xfield] = arr[0];
- dt.Rows[i][yfield] = arr[1];
- }
- }
- }
- }
- }
|