// GET: Color public ActionResult Resistor() { ViewBag.Message = "Calculate the Ohms of your resistor"; ColorBands vs = new ColorBands(); return(View(vs)); }
public ActionResult Index(TilesData tilesData) { Heatmap tile = new Heatmap(256, 256, tilesData.x, tilesData.y, tilesData.zoom); BoundingBox boundingBox = tile.GetBoundingBox(TileBuffer); double tolerance = GetPolygonTolerance(tilesData.zoom); var boundingGeo = boundingBox.GetDbGeography(); using (var context = ContextFactory.SizeUpContext) { var kvf = new List <KeyValue <DbGeography, Band <double> > >(); if (tilesData != null && tilesData.Bands != null) { var geoIdList = (from b in tilesData.Bands from s in b.band select s.geoId).ToList(); var goegraphies = context.Geographies.Where(i => geoIdList.Contains(i.Id)); var kv = goegraphies.Select(i => new KeyValue <DbGeography, double>() { Key = SqlSpatialFunctions.Reduce(i.Polygon, tolerance).Intersection(boundingGeo), Value = i.Id }).ToList(); kvf = (from tl in tilesData.Bands from t in tl.band from k in kv where k.Value == t.geoId select new KeyValue <DbGeography, Band <double> >(k.Key, new Band <double>() { Min = t.min, Max = t.max })) .ToList(); } var quantiles = kvf .Where(i => i.Value != null) .NTileDescending(i => i.Value.Max, 5); ColorBands colorBands = new ColorBands(ColorTranslator.FromHtml("#" + tilesData.startColor), ColorTranslator.FromHtml("#" + tilesData.endColor), quantiles.Count()); string[] bandList = colorBands.GetColorBands().ToArray(); var validValues = quantiles .Select((i, index) => i.Where(g => g.Key != null).Select(g => new GeographyEntity() { Geography = SqlGeography.Parse(g.Key.AsText()), Color = bandList[index] })) .SelectMany(i => i) .ToList(); var invalidValues = kvf .Where(i => i.Value == null) .Where(i => i.Key != null) .Select(g => new GeographyEntity() { Geography = SqlGeography.Parse(g.Key.AsText()) }) .ToList(); var output = validValues.Union(invalidValues).ToList(); tile.Draw(output); var stream = new MemoryStream(); tile.Bitmap.Save(stream, ImageFormat.Png); return(File(stream.GetBuffer(), "image/png")); } }