/// <summary> /// 高德矢量要素下载 /// </summary> /// <param name="Result"></param> /// <returns></returns> public WebApiResult <string> GaodeDownload(GaodeMapFeatureDownloadResult Result) { this.countdown = new CountdownEvent(Result.TaskCount); this.Result_AFeature = Result; this.N = Result.TaskCount; UpdateLastLoc <GaodeMapFeatureDownloadResult>(Result.GUID); log = new TaskLogEntity() { GUID = Result.GUID, Name = Result.TName, Type = "矢量要素", Description = "GaodeDownload", Status = "进行中", Parameter = JsonHelper.ToJson(Result), SavePath = Result.SavePathText }; //操作日志 new Log <GaodeMapFeatureDownloadResult>(log); if (Result.LayerName == "道路") { xmlDoc.Load(MapFeatureConfig); /////////////////////////////////////////////////////////////////////////////// // GDAL创建shp文件 // 注册所有的驱动 Ogr.RegisterAll(); // GDAL中文路径支持 OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 属性表字段中文支持 OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", "CP936"); // 设置坐标系存储文件夹gdal-data路径 OSGeo.GDAL.Gdal.SetConfigOption("GDAL_DATA", System.Windows.Forms.Application.StartupPath + "\\gdal-data"); Driver oDriver = Ogr.GetDriverByName("ESRI Shapefile"); if (oDriver == null) { return(new WebApiResult <string>() { success = 0, msg = "GDAL驱动不可用,请检查!" }); } // 创建数据源 DataSource oDS = oDriver.CreateDataSource(Result.SavePathText, null); if (oDS == null) { return(new WebApiResult <string>() { success = 0, msg = "创建数据源失败,请检查!" }); } oLayer = oDS.GetLayerByName(Result.TName); if (oLayer == null) { // 创建图层,创建一个多线图层,并指定空间参考 //第一种方法 OSGeo.OSR.SpatialReference oSRS = new OSGeo.OSR.SpatialReference("PROJCS[\"WGS_1984_Pseudo_Mercator\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator\"],PARAMETER[\"false_easting\",0.0],PARAMETER[\"false_northing\",0.0],PARAMETER[\"central_meridian\",0.0],PARAMETER[\"standard_parallel_1\",0.0],UNIT[\"Meter\",1.0]]"); //第二种方法 //OSGeo.OSR.SpatialReference oSRS = new OSGeo.OSR.SpatialReference(""); //oSRS.SetWellKnownGeogCS("EPSG:4326"); oLayer = oDS.CreateLayer(Result.TName, oSRS, wkbGeometryType.wkbMultiLineString, null); if (oLayer == null) { return(new WebApiResult <string>() { success = 0, msg = "创建图层失败,请检查!" }); } // 创建属性表 // 先创建一个叫Name的字符型属性,字符长度为100 FieldDefn oFieldName = new FieldDefn("Name", FieldType.OFTString); oFieldName.SetWidth(100); oLayer.CreateField(oFieldName, 1); // 再创建一个叫FeatureName的字符型属性,字符长度为50 FieldDefn oFieldUID = new FieldDefn("RID", FieldType.OFTString); oFieldUID.SetWidth(50); oLayer.CreateField(oFieldUID, 1); } ///////////////////////////////////////////////////////////////////////////////// threadlog = new ThreadTaskLogEntity() { GUID = Result.GUID, TaskLog_GUID = Result.GUID, Status = "进行中", TStatus = 1, TName = Result.TName, IsPaused = false, URL = Result.URL, Parameter = JsonHelper.ToJson(Result) }; //计算Total并更新 threadlog.Total = GetList("SELECT KWName FROM mapbar_poi WHERE KWType = '道路'", "KWName").Count; new Log <GaodeMapFeatureDownloadResult>(threadlog); log.Count = threadlog.Total; new Log <GaodeMapFeatureDownloadResult>(log); Thread[] t = new Thread[Result.TaskCount]; for (int num = 0; num < Result.TaskCount; num++) { try { t[num] = new Thread(new ParameterizedThreadStart(run_AFeature)) { Name = "Thread " + num.ToString() }; t[num].Start(num); } catch (Exception ex) { threadlog.Status = "错误"; threadlog.TStatus = 3; threadlog.ErrorMsg = ex.ToString(); new Log <GaodeMapFeatureDownloadResult>(threadlog); log.Status = "错误"; log.ErrorMsg = ex.ToString(); log.ErrorDate = DateTime.Now.ToString(); //操作日志 new Log <BaiduMapFeatureDownloadResult>(log); return(new WebApiResult <string>() { success = 0, msg = ex.ToString() }); } } countdown.Wait(); oLayer.Dispose(); oDS.Dispose(); for (int num = 0; num < Result.TaskCount; num++) { t[num].Abort(); } lock (obj) { if (!Log <GaodeMapFeatureDownloadResult> .GetThreadLogEntity(this.Result_AFeature.GUID).IsPaused) { //配置文件参数信息更新 xmlDoc["MapFeature"]["bmap"]["dict_index"].InnerText = "0"; xmlDoc.Save(MapFeatureConfig); log.Status = "已完成"; log.CompleteTime = DateTime.Now.ToString(); log.Current = log.Count; threadlog.Status = "已完成"; threadlog.TStatus = 2; threadlog.Current = threadlog.Total; threadlog.Current_loc = List2Str(current_loc); //操作日志 new Log <GaodeMapFeatureDownloadResult>(threadlog); new Log <GaodeMapFeatureDownloadResult>(log); return(new WebApiResult <string>() { success = 1, msg = "高德地图要素下载完成!" }); } } } else { return(new WebApiResult <string>() { success = 2, msg = "图层类型不符合" }); } return(null); }
/// <summary> /// 高德矢量要素下载 /// </summary> /// <param name="request"></param> /// <returns></returns> public WebApiResult <string> Any(GaodeMapFeatureDownloadResult request) { MapFeatureDownloadService service = new MapFeatureDownloadService(); return(service.GaodeDownload(request)); }