public CitynamesEntity RetrieveEntity() { if (!File.Exists(this.filePath)) { throw new FileNotFoundException(this.filePath); } var result = new CitynamesEntity(); using (var reader = new StreamReader(this.filePath)) { string pattern = @"\s+"; string line = reader.ReadLine()?.Trim(); if (string.IsNullOrEmpty(line)) { throw new InvalidDataException(this.filePath); } var array = Regex.Split(line, pattern); result.Description = array[0]; var count = 0; while ((line = reader.ReadLine()?.Trim()) != null) { count++; array = Regex.Split(line, pattern); if (array.Length != 3) { throw new InvalidDataException(this.filePath); } var item = new CitynamesEntityItem(); item.Longitude = Convert.ToSingle(array[0]); item.Latitude = Convert.ToSingle(array[1]); item.Name = array[2]; result.Items.Add(item); } } return(result); }
private GraphicsLayer GenerateGraphicLayer(CitynamesEntity entity, Color color) { var graphics = new List <Graphic>(); foreach (var item in entity.Items) { if (item.Longitude >= -180 && item.Longitude <= 180 && item.Latitude >= -90 && item.Latitude <= 90) { graphics.Add(GenerateGraphic(item, color)); } } var layer = new GraphicsLayer { GraphicsSource = graphics, DisplayName = entity.Description, ID = new Guid().ToString() }; return(layer); }