Exemplo n.º 1
0
        /// <summary>
        /// 读取txt坐标文件,存入数据到TProjInfo实例中
        /// </summary>
        /// <param name="txtPath">txt文件路径</param>
        /// <param name="isAddProjZone">是否在Y坐标值上添加投影分带带号</param>
        /// <returns></returns>
        public static TProjInfo GetProjInfoFromTxt(string txtPath, bool isAddProjZone = false)
        {
            var txtInfo = new TProjInfo();

            var      lines   = File.ReadAllLines(txtPath, FileEncode.GetEncoding(txtPath));
            var      txtFlag = ETxtContent.NoDefine;
            TPolygon polygon = null;

            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    var line = lines[i];
                    if (SetStrFlag(line, ref txtFlag))
                    {
                        continue;
                    }

                    if (txtFlag == ETxtContent.Project)
                    {
                        txtInfo.AddProjectDict(line);
                    }

                    else if (txtFlag == ETxtContent.Property)
                    {
                        txtInfo.AddPropertyDict(line);
                    }

                    else if (txtFlag == ETxtContent.Coordinate)
                    {
                        string[] strArray = line.Split(',');
                        if (line.Contains("@"))
                        {
                            polygon = new TPolygon();
                            polygon.AddAttribute(strArray);
                            txtInfo.Polygons.Add(polygon);
                        }
                        else if (strArray.Length == 4)
                        {
                            var strY = isAddProjZone ? txtInfo.ProjZone + strArray[3] : strArray[3];
                            polygon.AddXY(Convert.ToInt32(strArray[1]), Convert.ToDouble(strArray[2]), Convert.ToDouble(strY));
                        }
                    }
                }
                catch (Exception ex) { throw new Exception($"读取坐标文件第{i}行发生错误:{ex.Message}"); }
            }
            CheckRepairPolygon(txtInfo);
            return(txtInfo);
        }
        public IObservable <WWW> Load(string url)
        {
            var hashCodeUrl = Path + url.GetHashCode();

            //如果之前不存在缓存文件
            if (!File.Exists(hashCodeUrl))
            {
                var www = remoteFileLoader.Load(url);
                www.Subscribe(file =>
                {
                    if (file != null)
                    {
                        var encodeBytes = FileEncode?.Invoke(file);
                        File.WriteAllBytes(hashCodeUrl, encodeBytes);
                    }
                });

                return(www);
            }
            else
            {
                return(localFileLoader.Load(hashCodeUrl));
            }
        }