public static void Main() { XNamespace svgNamespace = "http://www.w3.org/2000/svg"; IEnumerable<XElement> elements; using (CoffeeEntities entities = new CoffeeEntities()) { IEnumerable<CoffeeShop> coffeeShops = entities.CoffeeShops; double maxLatitude = coffeeShops.Max(cs => cs.Location.Latitude); double minLongitude = coffeeShops.Min(cs => cs.Location.Longitude); var coordinates = coffeeShops .OrderBy(cs => cs.Location.Latitude) .ThenBy(cs => cs.Location.Longitude) .Select(cs => new { X = (cs.Location.Longitude - minLongitude) * LongitudeScaleFactor * DistanceMultiplier, Y = (cs.Location.Latitude - maxLatitude) * -1 * LatitudeScaleFactor * DistanceMultiplier, }) .ToList(); elements = coordinates .Select(c => new XElement(svgNamespace + "circle", new XAttribute("cx", c.X), new XAttribute("cy", c.Y), new XAttribute("r", Radius), new XAttribute("style", string.Format("fill:{0};opacity:{1}", Color, Opacity)))); } XObject[] childObjects = new XObject[] { new XAttribute("version", "1.1") } .Concat(elements) .ToArray(); XDocument xDoc = new XDocument( new XDeclaration("1.0", null, "no"), new XDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null), new XElement(svgNamespace + "svg", elements)); using (XmlWriter writer = XmlWriter.Create(FileName, new XmlWriterSettings { Indent = true, })) { xDoc.Save(writer); } }
public void Run() { CoffeeEntities entities = new CoffeeEntities(); DbSet<CoffeeShop> coffeeShops = entities.CoffeeShops; this.ClearDatabase(coffeeShops); entities.SaveChanges(); SearchArea searchArea = new SearchArea { SouthwestCorner = new Coordinate { latitude = (double)MinLatitude, longitude = (double)MinLongitude, }, NortheastCorner = new Coordinate { latitude = (double)MaxLatitude, longitude = (double)MaxLongitude, } }; SearchResult result = this._coffeeSearcher.Search(searchArea).Result; if (result.Error != null) { throw new Exception(result.Error.Description); } else { foreach (CoffeeShop shop in result.Results) { coffeeShops.Add(shop); } entities.SaveChanges(); } }