Beispiel #1
0
        /// <summary>
        /// 百度矢量要素下载(数据下载写入shp文件的时候可能出现问题,比如下载网络波动中断到时系统无法识别(解决办法先吧数据下载到数据在写入shp文件))
        /// </summary>
        /// <param name="Result"></param>
        /// <returns></returns>
        public WebApiResult <string> BaiduDownload(BaiduMapFeatureDownloadResult Result)
        {
            this.countdown       = new CountdownEvent(Result.TaskCount);
            this.Result_BFeature = Result;
            this.N = Result.TaskCount;

            UpdateLastLoc <BaiduMapFeatureDownloadResult>(Result.GUID);

            log = new TaskLogEntity()
            {
                GUID = Result.GUID, Name = Result.TName, Type = "矢量要素", Description = "BaiduDownload", Status = "进行中", Parameter = JsonHelper.ToJson(Result), SavePath = Result.SavePathText
            };
            //操作日志
            new Log <BaiduMapFeatureDownloadResult>(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);
                    // 再创建一个叫Type的字符型属性,字符长度为50
                    FieldDefn oFieldType = new FieldDefn("Type", FieldType.OFTString);
                    oFieldType.SetWidth(50);
                    oLayer.CreateField(oFieldType, 1);
                    // 再创建一个叫UID的字符型属性,字符长度为50
                    FieldDefn oFieldUID = new FieldDefn("UID", 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 <BaiduMapFeatureDownloadResult>(threadlog);
                log.Count = threadlog.Total;
                new Log <BaiduMapFeatureDownloadResult>(log);

                Thread[] t = new Thread[Result.TaskCount];
                for (int num = 0; num < Result.TaskCount; num++)
                {
                    try
                    {
                        t[num] = new Thread(new ParameterizedThreadStart(run_BFeature))
                        {
                            Name = "Thread " + num.ToString()
                        };
                        t[num].Start(num);
                    }
                    catch (Exception ex)
                    {
                        threadlog.Status   = "错误";
                        threadlog.ErrorMsg = ex.ToString();
                        threadlog.TStatus  = 3;
                        new Log <BaiduMapFeatureDownloadResult>(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 <BaiduMapFeatureDownloadResult> .GetThreadLogEntity(this.Result_BFeature.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 <BaiduMapFeatureDownloadResult>(threadlog);
                        new Log <BaiduMapFeatureDownloadResult>(log);
                        return(new WebApiResult <string>()
                        {
                            success = 1, msg = "百度地图要素下载完成!"
                        });
                    }
                }
            }
            else
            {
                return(new WebApiResult <string>()
                {
                    success = 2, msg = "图层类型不符合"
                });
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// 百度矢量要素下载
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public WebApiResult <string> Any(BaiduMapFeatureDownloadResult request)
        {
            MapFeatureDownloadService service = new MapFeatureDownloadService();

            return(service.BaiduDownload(request));
        }