Ejemplo n.º 1
0
        private async void LoadSpatialReferencesAsync()
        {
            //init - placeholder
            _executing = true;
            OnPropertyChanged("IsExecutingQuery");
            _timer.Start();

            _coordSystems = new ObservableCollection <CoordSystemCollection>();
            _coordSystems.Add(new CoordSystemCollection()
            {
                Name    = "Loading Geographic Coordinate Systems...",
                Regions = null
            });
            _coordSystems.Add(new CoordSystemCollection()
            {
                Name    = "Loading Projected Coordinate Systems...",
                Regions = null
            });

            try {
                await System.Threading.Tasks.Task.Run(() => {
                    Dictionary <string, Dictionary <string, CoordSystemRegion> > regions =
                        new Dictionary <string, Dictionary <string, CoordSystemRegion> >();
                    regions.Add("Geographic Coordinate Systems", new Dictionary <string, CoordSystemRegion>()); //Geographic
                    regions.Add("Projected Coordinate Systems", new Dictionary <string, CoordSystemRegion>());  //Projected

                    string content = Resource1.sr_out;                                                          //Stored coordinate system information

                    int startIndex         = 0;
                    string coordSystemType = "]]Geographic Coordinate Systems";
                    string remainder       = "";
                    int idx = 9999;
                    while (idx > 0)
                    {
                        idx = content.IndexOf(coordSystemType);
                        if (idx < 0 && coordSystemType == "]]Geographic Coordinate Systems")
                        {
                            coordSystemType = "]]Projected Coordinate Systems";
                            idx             = content.IndexOf(coordSystemType);
                        }
                        //now if it is less than zero, we are on the last coordinate system record
                        //Note: "+2" to skip the ']]' in the search string
                        string sr_record = content.Substring(0, idx > 0 ? idx + 2 : content.Length);

                        //each sr comes in blocks of 4
                        string[] srs = sr_record.Split(new char[] { '|' });
                        //Get the name components first - includes the coordinate system type
                        //and the region
                        string[] names  = srs[0].Split(new char[] { '/' });
                        var srCategory  = names[0];
                        string sep      = "";
                        string srRegion = "";
                        for (int n = 1; n < names.Length - 1; n++)
                        {
                            srRegion += sep + names[n];
                            sep       = ", ";
                        }
                        var name = string.Format("{0} ({1})", names[names.Length - 1], srs[1]);
                        var wkid = Int32.Parse(srs[2]);
                        var wkt  = srs[3];

                        //save it
                        CoordSystemRegion region = null;
                        if (!regions[srCategory].ContainsKey(srRegion))
                        {
                            region = new CoordSystemRegion();
                            region.CoordSystemInfos = new List <CoordSystemInfo>();
                            region.Name             = srRegion;
                            regions[srCategory].Add(srRegion, region);
                        }
                        else
                        {
                            region = regions[srCategory][srRegion];
                        }
                        CoordSystemInfo cs = new CoordSystemInfo()
                        {
                            Name         = name,
                            InternalName = srs[1],
                            Region       = srRegion,
                            WKID         = wkid,
                            WKT          = wkt
                        };
                        region.CoordSystemInfos.Add(cs);

                        if (idx > 0)
                        {
                            remainder = content.Substring(idx + 2);
                            content   = remainder;
                        }
                    }

                    //save them
                    _coordSystems.Clear();
                    _coordSystems = null;
                    _coordSystems = new ObservableCollection <CoordSystemCollection>();
                    _coordSystems.Add(new CoordSystemCollection()
                    {
                        Name    = "Geographic Coordinate Systems",
                        Regions = regions["Geographic Coordinate Systems"].Values.ToList()
                    });
                    _coordSystems.Add(new CoordSystemCollection()
                    {
                        Name    = "Projected Coordinate Systems",
                        Regions = regions["Projected Coordinate Systems"].Values.ToList()
                    });
                });
            }
            finally {
                _timer.Stop();
                _executing = false;
                OnPropertyChanged("IsExecutingQuery");
                OnPropertyChanged("CoordinateSystems");
            }
        }
        private async void LoadSpatialReferencesAsync() {

            //init - placeholder
            _executing = true;
            OnPropertyChanged("IsExecutingQuery");
            _timer.Start();

            _coordSystems = new ObservableCollection<CoordSystemCollection>();
            _coordSystems.Add(new CoordSystemCollection() {
                Name = "Loading Geographic Coordinate Systems...",
                Regions = null
            });
            _coordSystems.Add(new CoordSystemCollection() {
                Name = "Loading Projected Coordinate Systems...",
                Regions = null
            });

            try {
                await System.Threading.Tasks.Task.Run(() => {
                    Dictionary<string, Dictionary<string, CoordSystemRegion>> regions =
                    new Dictionary<string, Dictionary<string, CoordSystemRegion>>();
                    regions.Add("Geographic Coordinate Systems", new Dictionary<string, CoordSystemRegion>());//Geographic
                    regions.Add("Projected Coordinate Systems", new Dictionary<string, CoordSystemRegion>());//Projected

                    string content = Resource1.sr_out;//Stored coordinate system information

                    int startIndex = 0;
                    string coordSystemType = "]]Geographic Coordinate Systems";
                    string remainder = "";
                    int idx = 9999;
                    while (idx > 0) {
                        idx = content.IndexOf(coordSystemType);
                        if (idx < 0 && coordSystemType == "]]Geographic Coordinate Systems") {
                            coordSystemType = "]]Projected Coordinate Systems";
                            idx = content.IndexOf(coordSystemType);
                        }
                        //now if it is less than zero, we are on the last coordinate system record
                        //Note: "+2" to skip the ']]' in the search string
                        string sr_record = content.Substring(0, idx > 0 ? idx + 2 : content.Length);

                        //each sr comes in blocks of 4
                        string[] srs = sr_record.Split(new char[] { '|' });
                        //Get the name components first - includes the coordinate system type
                        //and the region
                        string[] names = srs[0].Split(new char[] { '/' });
                        var srCategory = names[0];
                        string sep = "";
                        string srRegion = "";
                        for (int n = 1; n < names.Length - 1; n++) {
                            srRegion += sep + names[n];
                            sep = ", ";
                        }
                        var name = string.Format("{0} ({1})", names[names.Length - 1], srs[1]);
                        var wkid = Int32.Parse(srs[2]);
                        var wkt = srs[3];

                        //save it
                        CoordSystemRegion region = null;
                        if (!regions[srCategory].ContainsKey(srRegion)) {
                            region = new CoordSystemRegion();
                            region.CoordSystemInfos = new List<CoordSystemInfo>();
                            region.Name = srRegion;
                            regions[srCategory].Add(srRegion, region);
                        }
                        else {
                            region = regions[srCategory][srRegion];
                        }
                        CoordSystemInfo cs = new CoordSystemInfo() {
                            Name = name,
                            InternalName = srs[1],
                            Region = srRegion,
                            WKID = wkid,
                            WKT = wkt
                        };
                        region.CoordSystemInfos.Add(cs);

                        if (idx > 0) {
                            remainder = content.Substring(idx + 2);
                            content = remainder;
                        }
                    }

                    //save them
                    _coordSystems.Clear();
                    _coordSystems = null;
                    _coordSystems = new ObservableCollection<CoordSystemCollection>();
                    _coordSystems.Add(new CoordSystemCollection() {
                        Name = "Geographic Coordinate Systems",
                        Regions = regions["Geographic Coordinate Systems"].Values.ToList()
                    });
                    _coordSystems.Add(new CoordSystemCollection() {
                        Name = "Projected Coordinate Systems",
                        Regions = regions["Projected Coordinate Systems"].Values.ToList()
                    });
                });
            }
            finally {
                _timer.Stop();
                _executing = false;
                OnPropertyChanged("IsExecutingQuery");
                OnPropertyChanged("CoordinateSystems");
            }
        }