/// <summary> /// Convert a WebSpeciesFact instance into /// an ISpeciesFact instance. /// </summary> /// <param name="webSpeciesFact">A WebSpeciesFact instance.</param> /// <param name="factors">List of factors.</param> /// <param name="individualCategories">List of individual categories.</param> /// <param name="periods">List of periods.</param> /// <returns>An ISpeciesFact instance.</returns> private ISpeciesFact GetSpeciesFact( WebSpeciesFact webSpeciesFact, FactorList factors, IndividualCategoryList individualCategories, PeriodList periods) { IFactor factor; IPeriod period; ISpeciesFact speciesFact; ITaxon host, taxon; factor = factors.Get(webSpeciesFact.FactorId); if (webSpeciesFact.IsHostSpecified) { host = new Data.Taxon(); host.Id = webSpeciesFact.HostId; } else { if (factor.IsTaxonomic) { host = new Data.Taxon { Id = (int)TaxonId.Life }; } else { host = null; } } if (webSpeciesFact.IsPeriodSpecified) { period = periods.Get(webSpeciesFact.PeriodId); } else { period = null; } taxon = new Data.Taxon(); taxon.Id = webSpeciesFact.TaxonId; speciesFact = new SpeciesFact( webSpeciesFact.Id, taxon, individualCategories.Get(webSpeciesFact.IndividualCategoryId), factor, host, period, webSpeciesFact.FieldValue1, webSpeciesFact.IsFieldValue1Specified, webSpeciesFact.FieldValue2, webSpeciesFact.IsFieldValue2Specified, webSpeciesFact.FieldValue3, webSpeciesFact.IsFieldValue3Specified, webSpeciesFact.FieldValue4, webSpeciesFact.IsFieldValue4Specified, webSpeciesFact.FieldValue5, webSpeciesFact.IsFieldValue5Specified, null, null, webSpeciesFact.ModifiedBy, webSpeciesFact.ModifiedDate); return(speciesFact); }
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); }
/// <summary> /// Convert a WebSpeciesFact instance into /// an ISpeciesFact instance. /// </summary> /// <param name="userContext"> /// Information about the user that makes this method call. /// </param> /// <param name="webSpeciesFact">A WebSpeciesFact instance.</param> /// <param name="factors">List of factors.</param> /// <param name="individualCategories">List of individual categories.</param> /// <param name="periods">List of periods.</param> /// <param name="references">List of references.</param> /// <param name="speciesFactQualities">List of species fact qualities.</param> /// <param name="taxa">Taxa that are used in the species facts.</param> /// <returns>An ISpeciesFact instance.</returns> private ISpeciesFact GetSpeciesFact(IUserContext userContext, WebSpeciesFact webSpeciesFact, FactorList factors, IndividualCategoryList individualCategories, PeriodList periods, ReferenceList references, SpeciesFactQualityList speciesFactQualities, TaxonList taxa) { IFactor factor; IPeriod period; ISpeciesFact speciesFact; ITaxon host, taxon; factor = factors.Get(webSpeciesFact.FactorId); if (webSpeciesFact.IsHostSpecified) { #if EXAMINE_PROBLEM if (!(taxa.Contains(webSpeciesFact.HostId))) { throw new Exception("Host with id = " + webSpeciesFact.HostId + " is not in taxon list." + webSpeciesFact.GetString()); } #endif host = taxa.Get(webSpeciesFact.HostId); } else { if (factor.IsTaxonomic) { host = CoreData.TaxonManager.GetTaxon(userContext, 0); } else { host = null; } } if (webSpeciesFact.IsPeriodSpecified) { #if EXAMINE_PROBLEM if (!(periods.Contains(webSpeciesFact.PeriodId))) { throw new Exception("Period with id = " + webSpeciesFact.PeriodId + " is not in period list." + webSpeciesFact.GetString()); } #endif period = periods.Get(webSpeciesFact.PeriodId); } else { period = null; } #if EXAMINE_PROBLEM if (!(taxa.Contains(webSpeciesFact.TaxonId))) { throw new Exception("Taxon with id = " + webSpeciesFact.TaxonId + " is not in taxon list." + webSpeciesFact.GetString()); } #endif taxon = taxa.Get(webSpeciesFact.TaxonId); #if EXAMINE_PROBLEM if (!(individualCategories.Contains(webSpeciesFact.IndividualCategoryId))) { throw new Exception("Individual category with id = " + webSpeciesFact.IndividualCategoryId + " is not in individual category list." + webSpeciesFact.GetString()); } if (!(speciesFactQualities.Contains(webSpeciesFact.QualityId))) { throw new Exception("Quality with id = " + webSpeciesFact.QualityId + " is not in quality list." + webSpeciesFact.GetString()); } if (!(references.Contains(webSpeciesFact.ReferenceId))) { throw new Exception("Reference with id = " + webSpeciesFact.ReferenceId + " is not in reference list." + webSpeciesFact.GetString()); } #endif speciesFact = CoreData.SpeciesFactManager.GetSpeciesFact(userContext, webSpeciesFact.Id, taxon, individualCategories.Get(webSpeciesFact.IndividualCategoryId), factor, host, period, webSpeciesFact.FieldValue1, webSpeciesFact.IsFieldValue1Specified, webSpeciesFact.FieldValue2, webSpeciesFact.IsFieldValue2Specified, webSpeciesFact.FieldValue3, webSpeciesFact.IsFieldValue3Specified, webSpeciesFact.FieldValue4, webSpeciesFact.IsFieldValue4Specified, webSpeciesFact.FieldValue5, webSpeciesFact.IsFieldValue5Specified, speciesFactQualities.Get(webSpeciesFact.QualityId), references.Get(webSpeciesFact.ReferenceId), webSpeciesFact.ModifiedBy, webSpeciesFact.ModifiedDate); return(speciesFact); }