/// <summary> /// Read a shapefile MultiPoint record. /// </summary> /// <param name="stream">Input stream.</param> /// <param name="record">Shapefile record to be updated.</param> private static void ReadMultipoint(Stream stream, ShapeFileRecord record) { // Bounding Box. record.XMin = ShapeFile.ReadDouble64_LE(stream); record.YMin = ShapeFile.ReadDouble64_LE(stream); record.XMax = ShapeFile.ReadDouble64_LE(stream); record.YMax = ShapeFile.ReadDouble64_LE(stream); // Num Points. int numPoints = ShapeFile.ReadInt32_LE(stream); // Points. for (int i = 0; i < numPoints; i++) { Point p = new Point(); p.X = ShapeFile.ReadDouble64_LE(stream); p.Y = ShapeFile.ReadDouble64_LE(stream); record.Points.Add(p); } }
private Bitmap getBitmap() { Bitmap bitmap; float xScale = 1.0F * _bitmapWidth / _width; float yScale = 1.0F * _bitmapHeight / _height; if (xScale < yScale) { _scale = xScale; } else { _scale = yScale; } //_shapeTransform = new TransformGroup(); bitmap = new Bitmap(_bitmapWidth + _legendBoxWidth - _legendBoxOffsetX, _bitmapHeight + 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics canvas = Graphics.FromImage(bitmap)) { using (Pen pen = new Pen(Color.Black, 1)) { using (Brush backgroundBrush = new SolidBrush(_colorBackground)) { String countyCode = ""; int countyOccurenceKey = 0; canvas.FillRectangle(backgroundBrush, 0, 0, _bitmapWidth + _legendBoxWidth - _legendBoxOffsetX, _bitmapHeight + 2); for (int recordIndex = 0; recordIndex < _shapeFile.Records.Count; recordIndex++) { try { ShapeFileRecord record = _shapeFile.Records[recordIndex]; if (_countyInformation.IsNotEmpty()) { countyCode = record.Attributes[2].ToString(); int countyId = getCountyId(countyCode); if (countyId > 0) { ISpeciesFact fact = null; SpeciesFactList facts = null; if (_counties.Exists(countyId)) { try { facts = _countyInformation.GetSpeciesFacts(_counties.Get(countyId)); if (facts.IsNotEmpty()) { fact = facts[0]; } } catch (Exception) { throw; } if (fact.IsNotNull()) { countyOccurenceKey = fact.MainField.EnumValue.KeyInt.GetValueOrDefault(0); } else { countyOccurenceKey = 0; } } else { countyOccurenceKey = 0; } } } else { countyOccurenceKey = -1; } for (int i = 0; i < record.NumberOfParts; i++) { List <Point> points = new List <Point>(); // Determine the starting index and the end index // into the points array that defines the figure. int start = record.Parts[i]; int end; if (record.NumberOfParts > 1 && i != (record.NumberOfParts - 1)) { end = record.Parts[i + 1]; } else { end = record.NumberOfPoints; } for (int j = start; j < end; j++) { System.Windows.Point pt = record.Points[j]; // Transform from lon/lat to canvas coordinates. //pt = this._shapeTransform.Transform(pt); Point point = new Point(_legendBoxWidth - _legendBoxOffsetX + (int)((pt.X - _xMin) * _scale), _bitmapHeight - (int)((pt.Y - _yMin) * _scale)); points.Add(point); } using (Brush countyOccurrenceBrush = getBrush(countyOccurenceKey)) { canvas.FillPolygon(countyOccurrenceBrush, points.ToArray()); } canvas.DrawPolygon(pen, points.ToArray()); } } catch (Exception) { throw; } } if (_countyInformation.IsEmpty()) { using (Font font = new Font("Arial", 24 * _bitmapHeight / 708)) { using (Brush brush = new SolidBrush(Color.Red)) { canvas.DrawString("Information saknas", font, brush, _legendBoxWidth, _bitmapHeight / 2); } } } if (UpdateInformation.IsNotEmpty()) { canvas.DrawImage(GetUpdateInformationBox(), 0, 0); canvas.DrawImage(getLegendBox(), 0, _updateInformationBoxHeight); } else { canvas.DrawImage(getLegendBox(), 0, 0); } } } } return(bitmap); }
private Bitmap getBitmap() { Bitmap bitmap; float xScale = 1.0F * _bitmapWidth / _width; float yScale = 1.0F * _bitmapHeight / _height; if (xScale < yScale) { _scale = xScale; } else { _scale = yScale; } bitmap = new Bitmap(_bitmapWidth + _legendBoxWidth - _legendBoxOffsetX, _bitmapHeight + 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics canvas = Graphics.FromImage(bitmap)) { using (Pen pen = new Pen(_colorLine, 1)) { using (Brush backgroundBrush = new SolidBrush(_colorBackground)) { canvas.FillRectangle(backgroundBrush, 0, 0, _bitmapWidth + _legendBoxWidth - _legendBoxOffsetX, _bitmapHeight + 2); //Draw background map from initialized shape file for (int recordIndex = 0; recordIndex < _shapeFile.Records.Count; recordIndex++) { ShapeFileRecord record = _shapeFile.Records[recordIndex]; for (int i = 0; i < record.NumberOfParts; i++) { List <System.Drawing.Point> points = new List <System.Drawing.Point>(); // Determine the starting index and the end index // into the points array that defines the figure. int start = record.Parts[i]; int end; if (record.NumberOfParts > 1 && i != (record.NumberOfParts - 1)) { end = record.Parts[i + 1]; } else { end = record.NumberOfPoints; } for (int j = start; j < end; j++) { System.Windows.Point pt = record.Points[j]; // Transform from lon/lat to canvas coordinates. //pt = this._shapeTransform.Transform(pt); System.Drawing.Point point = new System.Drawing.Point(_legendBoxWidth - _legendBoxOffsetX + (int)((pt.X - _xMin) * _scale), _bitmapHeight - (int)((pt.Y - _yMin) * _scale)); points.Add(point); } using (Brush countyBrush = new SolidBrush(_colorLandBackground)) { canvas.FillPolygon(countyBrush, points.ToArray()); } } } //Heat rects if (_observationCounts.IsNotNull()) { int radius = (Int32)Math.Round(_observationCounts[0].GridCellSize * _scale * 0.5) + 1; long maxCount = 0; foreach (IGridCellSpeciesObservationCount cell in _observationCounts) { if (cell.ObservationCount > maxCount) { maxCount = cell.ObservationCount; } } canvas.DrawImage(getLegendBox(maxCount), 2, 2); foreach (IGridCellSpeciesObservationCount cell in _observationCounts) { Double cellX = cell.OrginalGridCellCentreCoordinate.X; Double cellY = cell.OrginalGridCellCentreCoordinate.Y; System.Drawing.Point point = new System.Drawing.Point(_legendBoxWidth - _legendBoxOffsetX + (int)((cellX - _xMin) * _scale), _bitmapHeight - (int)((cellY - _yMin) * _scale)); using (Brush heatBrush = getHeatBrush(Math.Log(cell.ObservationCount), Math.Log(1), Math.Log(maxCount))) { canvas.FillRectangle(heatBrush, point.X - radius, point.Y - radius, 2 * radius, 2 * radius); } } } //Draw polygon border lines from initialized shape file for (int recordIndex = 0; recordIndex < _shapeFile.Records.Count; recordIndex++) { ShapeFileRecord record = _shapeFile.Records[recordIndex]; for (int i = 0; i < record.NumberOfParts; i++) { List <System.Drawing.Point> points = new List <System.Drawing.Point>(); // Determine the starting index and the end index // into the points array that defines the figure. int start = record.Parts[i]; int end; if (record.NumberOfParts > 1 && i != (record.NumberOfParts - 1)) { end = record.Parts[i + 1]; } else { end = record.NumberOfPoints; } for (int j = start; j < end; j++) { System.Windows.Point pt = record.Points[j]; System.Drawing.Point point = new System.Drawing.Point(_legendBoxWidth - _legendBoxOffsetX + (int)((pt.X - _xMin) * _scale), _bitmapHeight - (int)((pt.Y - _yMin) * _scale)); points.Add(point); } canvas.DrawPolygon(pen, points.ToArray()); } } } } } return(bitmap); }