Beispiel #1
0
        public FormattedLatLongVirtualColumn(DataMatrix matrix)
        {
            var areaTypeCol = matrix.IndexOf("AreaType");
            var latCol      = matrix.IndexOf("Lat");
            var longCol     = matrix.IndexOf("Long");
            var latCol2     = matrix.IndexOf("Lat2");
            var longCol2    = matrix.IndexOf("Long2");

            this.Name = "FormattedLatLong";

            this.ValueGenerator = (row) => {
                object objLat      = row[latCol];
                object objlong     = row[longCol];
                object objAreaType = row[areaTypeCol];

                AreaType areaType = AreaType.Point;
                if (objAreaType != null)
                {
                    areaType = (AreaType)int.Parse(objAreaType.ToString());
                }

                if (objLat != null && objlong != null)
                {
                    double lat   = (double)objLat;
                    double @long = (double)objlong;
                    switch (areaType)
                    {
                    case AreaType.Point:
                        return(string.Format("{0}, {1}", GeoUtils.DecDegToDMS(lat, CoordinateType.Latitude), GeoUtils.DecDegToDMS(@long, CoordinateType.Longitude)));

                    case AreaType.Line:
                        double lat2  = (double)row[latCol2];
                        double long2 = (double)row[longCol2];
                        return(string.Format("Line: {0}, {1} - {2}, {3}",
                                             GeoUtils.DecDegToDMS(lat, CoordinateType.Latitude), GeoUtils.DecDegToDMS(@long, CoordinateType.Longitude),
                                             GeoUtils.DecDegToDMS(lat2, CoordinateType.Latitude), GeoUtils.DecDegToDMS(long2, CoordinateType.Longitude)));

                    case AreaType.Box:
                        lat2  = (double)row[latCol2];
                        long2 = (double)row[longCol2];
                        return(string.Format("Box: {0}, {1} - {2}, {3}",
                                             GeoUtils.DecDegToDMS(lat, CoordinateType.Latitude), GeoUtils.DecDegToDMS(@long, CoordinateType.Longitude),
                                             GeoUtils.DecDegToDMS(lat2, CoordinateType.Latitude), GeoUtils.DecDegToDMS(long2, CoordinateType.Longitude)));
                    }
                }

                return("");
            };
        }
        private DataMatrix MergeItemMatrices(DataMatrix siteData, DataMatrix siteVisitData, DataMatrix materialData)
        {
            var result = new DataMatrix();

            // Create the final column set (based on the specified criteria)
            foreach (QueryCriteria c in Criteria)
            {
                result.Columns.Add(new MatrixColumn {
                    Name = c.Field.DisplayName
                });
            }

            // Now add the identity columns (as hidden columns, unless they already exist)
            string[] cols = { "Site Identifier", "Visit Identifier", "Material Identifier" };
            foreach (string col in cols)
            {
                if (result.IndexOf(col) < 0)
                {
                    result.Columns.Add(new MatrixColumn {
                        Name = col, IsHidden = true
                    });
                }
            }

            int          currentOrderNum = 1;
            LabelSetItem item            = null;

            while ((item = Items.FirstOrDefault((candidate) => { return(candidate.PrintOrder == currentOrderNum); })) != null)
            {
                if (item.NumCopies > 0)
                {
                    var row = result.AddRow();

                    if (item.SiteID > 0)
                    {
                        AddFieldData(row, item.SiteID, "Site Identifier", siteData);
                    }

                    if (item.VisitID > 0)
                    {
                        AddFieldData(row, item.VisitID, "Visit Identifier", siteVisitData);
                    }

                    if (item.MaterialID > 0)
                    {
                        AddFieldData(row, item.MaterialID, "Material Identifier", materialData);
                    }

                    if (item.NumCopies > 1)
                    {
                        CopyRow(result, row, item.NumCopies - 1);
                    }
                }

                currentOrderNum++;
            }

            return(result);
        }
Beispiel #3
0
        public FormattedDateVirtualColumn(DataMatrix matrix)
        {
            int dateTypeCol   = matrix.IndexOf("DateType");
            int startDateCol  = matrix.IndexOf("StartDate");
            int endDateCol    = matrix.IndexOf("EndDate");
            int casualDateCol = matrix.IndexOf("CasualDate");

            Name           = "Dates";
            ValueGenerator = (row) => {
                int    dateType    = 0;
                object objDateType = row[dateTypeCol];
                if (objDateType != null)
                {
                    int.TryParse(objDateType.ToString(), out dateType);
                    return(DateUtils.FormatDates(dateType, row[startDateCol] as int?, row[endDateCol] as int?, row[casualDateCol] as string));
                }
                return("");
            };
        }
 private void CopyRow(DataMatrix dest, MatrixRow srcRow, int numCopies)
 {
     for (int i = 0; i < numCopies; ++i)
     {
         var newRow = dest.AddRow();
         foreach (MatrixColumn col in dest.Columns)
         {
             int index = dest.IndexOf(col.Name);
             newRow[index] = srcRow[index];
         }
     }
 }
        public override DataMatrix ExtractReportData(IProgressObserver progress)
        {
            var matrix = new DataMatrix();

            if (IsGroupedByTaxon)
            {
                matrix.Columns.Add(new MatrixColumn {
                    Name = "TaxonName"
                });
                matrix.Columns.Add(new MatrixColumn {
                    Name = "BiotaID", IsHidden = true
                });
            }

            matrix.Columns.Add(new MatrixColumn {
                Name = "Count"
            });

            foreach (string colname in SelectedColumns)
            {
                matrix.Columns.Add(new MatrixColumn {
                    Name = colname
                });
            }

            // Open the feature layer data
            SelectedFeatureLayer.DataSource.Open();

            var map = new Dictionary <string, FeatureCountPair>();

            if (progress != null)
            {
                progress.ProgressMessage("Counting points...", 0);
            }

            int pointCount = 0;

            foreach (VectorLayer pointLayer in SelectedPointLayers)
            {
                var ds = pointLayer.DataSource;
                ds.Open();
                pointCount += ds.GetFeatureCount();
            }

            if (progress != null)
            {
                progress.ProgressStart(String.Format("Processing {0} points...", pointCount));
            }

            int processed     = 0;
            int notFoundCount = 0;

            var materialService = new MaterialService(User);
            var taxaService     = new TaxaService(User);

            foreach (VectorLayer pointLayer in SelectedPointLayers)
            {
                var pointProvider = pointLayer.DataSource;
                pointProvider.Open();
                for (uint i = 0; i < pointProvider.GetFeatureCount(); ++i)
                {
                    var row = pointProvider.GetFeature(i);

                    Taxon taxon = null;
                    if (IsGroupedByTaxon)
                    {
                        int?materialId = (int?)row["MaterialID"];
                        if (materialId.HasValue)
                        {
                            var m = materialService.GetMaterial(materialId.Value);
                            if (m.BiotaID > 0)
                            {
                                if (_taxonCache.ContainsKey(m.BiotaID))
                                {
                                    taxon = _taxonCache[m.BiotaID];
                                }
                                else
                                {
                                    taxon = taxaService.GetTaxon(m.BiotaID);
                                    _taxonCache[m.BiotaID] = taxon;
                                }
                            }
                        }
                    }

                    SharpMap.Geometries.Point p = row.Geometry as Point;
                    if (!ProcessPoint(SelectedFeatureLayer.DataSource, pointLayer, p, map, taxon))
                    {
                        notFoundCount++;
                    }
                    processed++;
                    if (progress != null)
                    {
                        double percent = ((double)processed) / ((double)pointCount) * 100;
                        progress.ProgressMessage(String.Format("Processing {0} points...", pointCount), percent);
                    }
                }
            }

            if (progress != null)
            {
                progress.ProgressMessage("Constructing result set...", 100);
            }

            int countIndex   = matrix.IndexOf("Count");
            int taxaIndex    = matrix.IndexOf("TaxonName");
            int biotaIDIndex = matrix.IndexOf("BiotaID");

            foreach (FeatureCountPair pair in map.Values)
            {
                var matrixRow = matrix.AddRow();
                foreach (DataColumn col in pair.First.Table.Columns)
                {
                    if (SelectedColumns.Contains(col.ColumnName))
                    {
                        var index = matrix.IndexOf(col.ColumnName);
                        matrixRow[index] = pair.First[col];
                    }
                }
                matrixRow[countIndex] = pair.Second;
                if (IsGroupedByTaxon)
                {
                    matrixRow[taxaIndex]    = pair.Taxon == null ? "Unidentified" : pair.Taxon.TaxaFullName;
                    matrixRow[biotaIDIndex] = pair.Taxon == null ? -1 : pair.Taxon.TaxaID.Value;
                }
            }

            if (IncludeUnmatchedPointRow && notFoundCount > 0)
            {
                var unmatched = matrix.AddRow();
                unmatched[countIndex] = notFoundCount;
            }

            if (progress != null)
            {
                progress.ProgressEnd(String.Format("{0} points processed.", pointCount));
            }

            return(matrix);
        }
Beispiel #6
0
        public TabularDataViewer(IBioLinkReport report, DataMatrix data, IProgressObserver progress)
        {
            InitializeComponent();
            this.Data = data;
            _progress = progress;
            _report   = report;
            var view = new GridView();

            var columns = report.DisplayColumns;

            if (columns == null || columns.Count == 0)
            {
                columns = GenerateDefaultColumns(data);
            }

            var hcs = viewerGrid.Resources["hcs"] as Style;

            foreach (DisplayColumnDefinition c in columns)
            {
                DisplayColumnDefinition coldef = c;
                var column = new GridViewColumn {
                    Header = BuildColumnHeader(coldef), DisplayMemberBinding = new Binding(String.Format("[{0}]", data.IndexOf(coldef.ColumnName))), HeaderContainerStyle = hcs
                };
                view.Columns.Add(column);
            }

            lvw.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(GridViewColumnHeaderClickedHandler));

            lvw.MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(lvw_MouseRightButtonUp);

            lvw.ItemsSource = Data.Rows;
            this.lvw.View   = view;
        }
        public System.Windows.FrameworkElement ConstructView(IBioLinkReport report, DataMatrix reportData, IProgressObserver progress)
        {
            var options = (report as ReferenceLinksReport).Options;

            var viewer = new RTFReportViewer {
                ReportName = report.Name
            };
            var rtf = new RTFReportBuilder();

            rtf.AppendFullHeader();
            rtf.ReportHeading(options.BibliographyTitle);

            var idx      = 1;
            var colIndex = reportData.IndexOf("RefID");

            var refIds = new List <Int32>();

            for (var i = 0; i < reportData.Rows.Count; ++i)
            {
                refIds.Add(i);
            }

            int sortColumnIdx = reportData.IndexOf(options.SortColumn);
            int refTypeIndex  = reportData.IndexOf("RefType");

            refIds.Sort((idx1, idx2) => {
                // If grouping, first check the ref type
                if (options.GroupByReferenceType)
                {
                    var refType1 = reportData.Rows[idx1][refTypeIndex] as String;
                    var refType2 = reportData.Rows[idx2][refTypeIndex] as String;
                    if (!refType1.Equals(refType2))
                    {
                        return(String.Compare(refType1, refType2, true));
                    }
                }

                // then by the nominated sort column
                var objVal1 = reportData.Rows[idx1][sortColumnIdx];
                var objVal2 = reportData.Rows[idx2][sortColumnIdx];
                var val1    = RTFUtils.StripMarkup(objVal1 == null ? "" : objVal1.ToString());
                var val2    = RTFUtils.StripMarkup(objVal2 == null ? "" : objVal2.ToString());

                if (options.SortAscending)
                {
                    return(String.Compare((String)val1, (String)val2, true));
                }
                else
                {
                    return(String.Compare((String)val2, (String)val1, true));
                }
            });


            var lastRefType = "";

            String[] allowedKeywords = { "b", "i", "sub", "super", "strike", "ul", "ulnone", "nosupersub" };
            foreach (var rowIdx in refIds)
            {
                var row = reportData.Rows[rowIdx];

                if (options.GroupByReferenceType)
                {
                    var refType = row["RefType"] as String;
                    if (!String.Equals(refType, lastRefType, StringComparison.CurrentCultureIgnoreCase))
                    {
                        rtf.Par();
                        rtf.Append(@" \pard\fs24\b\f1 ");
                        rtf.Append(refType);
                        rtf.Append(@" \b0");
                        rtf.Par();
                        lastRefType = refType;
                    }
                }

                rtf.Par();
                rtf.Append(@" \pard\fs20\f1 ");
                if (options.BibliographyIndexStyle != BibliographyIndexStyle.None)
                {
                    rtf.Append("[");
                    switch (options.BibliographyIndexStyle)
                    {
                    case BibliographyIndexStyle.Number:
                        rtf.Append(idx);
                        break;

                    case BibliographyIndexStyle.RefCode:
                        rtf.Append(row["RefCode"]);
                        break;
                    }
                    rtf.Append("] ");
                }
                idx++;

                var fullRTF = RTFUtils.filter(row["FullRTF"] as string, true, false, allowedKeywords);
                rtf.Append(fullRTF);

                var bits = new List <String>();
                if (!String.IsNullOrWhiteSpace(row["LinkPage"] as String))
                {
                    bits.Add(String.Format("page {0}", row["LinkPage"] as String));
                }

                if (options.IncludeQualification)
                {
                    var qual = row["LinkQualificationRTF"] as string;
                    if (!String.IsNullOrEmpty(qual))
                    {
                        bits.Add(RTFUtils.filter(qual, true, true, allowedKeywords).Trim());
                    }
                }

                if (bits.Count > 0)
                {
                    rtf.Append(" (").Append(bits.Join("; ").Trim()).Append(")");
                }

                rtf.Par();
            }

            Console.WriteLine(rtf.RTF);

            viewer.rtf.Rtf = rtf.RTF;

            return(viewer);
        }