Leo,
Here is the full code minus the part about adding the polygons to the allBins object since that is a data specific process. Essentially, the allBins object has a double value which is used to color code the individual polygons with a class break style. The polygons are all rectangles that create a map. So, you could generically make some code that took a rectangle shape and translated it in rows and columns and randomly assign to values between 0 and 10. The rows times the columns should be greater than 16M. In my specific case, I had 27M cells.
Please look at the memory usage on your machine when you add polygons to the InMemoryFeatureLayer and see if the memory is actually being totally consumed. As I said, mine is not and the maxpg segmentation gets me past the out of memory error…
ConcurrentDictionary<double, MultipolygonShape> allBins = new ConcurrentDictionary<double, MultipolygonShape>();
int maxpg = 15000000;
foreach (var pg in allBins)
{
if (pg.Value.Polygons.Count == 0) continue;
if (pg.Value.Polygons.Count > maxpg)
{
int fc = Convert.ToInt32(Math.Ceiling(pg.Value.Polygons.Count / (float)maxpg));
for (int i = 0; i < fc; i++)
{
List<PolygonShape> pgs = pg.Value.Polygons.Skip(i * maxpg).Take(maxpg).ToList();
MultipolygonShape mpg = new MultipolygonShape(pgs);
imfl.InternalFeatures.Add(new Feature(mpg, new List<string>() { offsetName + ":" + pg.Key }));
}
}
else
imfl.InternalFeatures.Add(new Feature(pg.Value, new List<string>() { offsetName + ":" + pg.Key }));
}
Debug.Print(string.Format("Adding bins to imfl took {0:0.0} s", s.Elapsed.Seconds));
s.Restart();
imfl.Open();
RectangleShape rect = imfl.GetBoundingBox();
// Have to set map size first otherwise it is taking forever if the data are already loaded
double mapX = rect.LowerRightPoint.X - rect.LowerLeftPoint.X;
double minBin = model.GridDef.BinX;
if (model.GridDef.BinY < model.GridDef.BinX)
minBin = model.GridDef.BinY;
double ratio = 16 / 9f;
ratio = rect.Width / rect.Height;
int w = 5120;
int h = Convert.ToInt32(w / ratio);
double pixelsPerBin = minBin * w / mapX;
while (pixelsPerBin < 4)
{
w += 100;
h = Convert.ToInt32(w / ratio);
double imageSize = w * h * 4f;
if (imageSize >= 2.147483648e9)
{
w -= 100;
h = Convert.ToInt32(w / ratio);
break;
}
pixelsPerBin = minBin * w / mapX;
}
// Bitmap can't exceed 65535 x 65535
if (h >= 65535)
{
h = 65535;
w = Convert.ToInt32(h * ratio);
}
Debug.Print(string.Format("Building map took {0:0.0} s", s.Elapsed.Seconds));
s.Restart();
using (Bitmap bitmap = new Bitmap(w, h))
{
PlatformGeoCanvas canvas = new PlatformGeoCanvas();
canvas.BeginDrawing(bitmap, rect, GeographyUnit.Meter);
imfl.Draw(canvas, new Collection<SimpleCandidate>());
canvas.EndDrawing();
bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
}
Regards,
Damian