public Image CreateGraphFromWaterML(Series mySeries, int widthPixels, int heightPixels) { ZedGraph.GraphPane p = SetupGraphPane(mySeries, widthPixels, heightPixels); if (mySeries != null) { if (mySeries.DataValueList != null) { DataSourcePointList source = new DataSourcePointList(); source.DataSource = mySeries.DataValueList; source.XDataMember = "LocalDateTime"; source.YDataMember = "Value"; LineItem line = p.AddCurve(mySeries.Variable.Name, source, Color.Blue, SymbolType.None); line.Line.Width = 2f; p.XAxis.Type = AxisType.Date; //adjust x axis range p.XAxis.Scale.Min = XDate.DateTimeToXLDate(mySeries.BeginDateTime); p.XAxis.Scale.Max = XDate.DateTimeToXLDate(mySeries.EndDateTime); p.AxisChange(); //Bitmap bm = new Bitmap(10, 10); //Graphics ge = Graphics.FromImage(bm); //p.AxisChange(ge); } } Image img = p.GetImage(); return img; }
/// <summary> /// Creates a copy of the original series. If copyDataValues is set to true, /// then the data values are also copied. /// The new series shares the same site, variable, source, method and quality /// control level. The new series does not belong to any data theme. /// </summary> /// <param name="original">The original series</param> /// <param name="copyDataValues">if set to true, then all data values are copied</param> public Series(Series original, bool copyDataValues) { //TODO: need to include series provenance information BeginDateTime = original.BeginDateTime; EndDateTime = original.EndDateTime; CreationDateTime = DateTime.Now; DataValueList = original.DataValueList; EndDateTime = original.EndDateTime; EndDateTimeUTC = original.EndDateTimeUTC; IsCategorical = original.IsCategorical; Method = original.Method; QualityControlLevel = original.QualityControlLevel; Source = original.Source; UpdateDateTime = DateTime.Now; ValueCount = original.ValueCount; Variable = original.Variable; //to copy the data values if (copyDataValues) { foreach (DataValue originalDataValue in original.DataValueList) { AddDataValue(originalDataValue.Copy()); } } }
private GraphPane SetupGraphPane(Series mySeries, int width, int height) { string graphTitle = "No Data"; string xAxisTitle = "Time"; string yAxisTitle = "Data Value"; if (mySeries != null) { graphTitle = mySeries.Site.Name; xAxisTitle = "Time"; yAxisTitle = string.Format("{0} [{1}]", mySeries.Variable.Name, mySeries.Variable.VariableUnit.Abbreviation); } GraphPane myPane = new GraphPane(new RectangleF(0f, 0f, (float)width, (float)height), graphTitle, xAxisTitle, yAxisTitle); myPane.Border.IsVisible = false; myPane.Legend.IsVisible = true; return myPane; }
///// <summary> ///// Information about data service that was used to ///// retrieve this site ///// </summary> //public virtual DataServiceInfo DataService { get; set; } /// <summary> /// Associates a data series with this site /// </summary> /// <param name="dataSeries">the data series</param> public void AddDataSeries(Series dataSeries) { if (DataSeriesList == null) DataSeriesList = new List<Series>(); DataSeriesList.Add(dataSeries); }
/// <summary> /// Reads the DataValues section /// </summary> protected override IList<Series> ReadDataValues(XmlReader r) { int valueCount; var lst = new List<DataValueWrapper>(Int32.TryParse(r.GetAttribute("count"), out valueCount) ? valueCount : 4); var qualifiers = new Dictionary<string, Qualifier>(); var methods = new Dictionary<string, Method>(); var sources = new Dictionary<string, Source>(); var qualityControlLevels = new Dictionary<string, QualityControlLevel>(); var samples = new Dictionary<string,Sample>(); var offsets = new Dictionary<string, OffsetType>(); var seriesDictionary = new Dictionary<string, Series>(); while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { if (r.Name == "value") { //create a new empty data value and add it to the list var wrapper = new DataValueWrapper(); var val = new DataValue(); wrapper.DataValue = val; lst.Add(wrapper); if (r.HasAttributes) { var censorCode = r.GetAttribute("censorCode"); if (!string.IsNullOrEmpty(censorCode)) { val.CensorCode = censorCode; } //fix by Jiri - sometimes the dateTime attribute is uppercase var localDateTime = r.GetAttribute("dateTime"); if (string.IsNullOrEmpty(localDateTime)) { localDateTime = r.GetAttribute("DateTime"); } val.LocalDateTime = Convert.ToDateTime(localDateTime, CultureInfo.InvariantCulture); val.DateTimeUTC = val.LocalDateTime; val.UTCOffset = 0.0; //method var methodID = r.GetAttribute("methodID"); if (String.IsNullOrEmpty(methodID)) { methodID = "0"; //when a method ID is unspecified } if (!methods.ContainsKey(methodID)) { var newMethod = Method.Unknown; methods.Add(methodID, newMethod); } wrapper.MethodID = methodID; //quality control level string qualityCode = r.GetAttribute("qualityControlLevel"); if (String.IsNullOrEmpty(qualityCode)) { qualityCode = "unknown"; //when the quality control level is unspecified } if (!qualityControlLevels.ContainsKey(qualityCode)) { var qualControl = QualityControlLevel.Unknown; qualControl.Code = qualityCode; qualControl.Definition = qualityCode; qualControl.Explanation = qualityCode; qualityControlLevels.Add(qualityCode, qualControl); } //source var sourceID = r.GetAttribute("sourceID"); if (String.IsNullOrEmpty(sourceID)) { sourceID = "0"; //when a source ID is unspecified } if (!sources.ContainsKey(sourceID)) { sources.Add(sourceID, Source.Unknown); } wrapper.SourceID = sourceID; wrapper.SeriesCode = SeriesCodeHelper.CreateSeriesCode(methodID, qualityCode, sourceID); //----method-source-qualityControl combination---- //sample var sampleID = r.GetAttribute("sampleID"); if (!String.IsNullOrEmpty(sampleID)) { if (!samples.ContainsKey(sampleID)) { samples.Add(sampleID, Sample.Unknown); } } wrapper.SampleID = sampleID; //qualifiers string qualifierCodes = r.GetAttribute("qualifiers"); if (!String.IsNullOrEmpty(qualifierCodes)) { if (!qualifiers.ContainsKey(qualifierCodes)) { var newQualifier = new Qualifier {Code = qualifierCodes}; qualifiers.Add(qualifierCodes, newQualifier); val.Qualifier = newQualifier; } else { val.Qualifier = qualifiers[qualifierCodes]; } } //vertical offset var offsetID = r.GetAttribute("offsetTypeID"); if (!String.IsNullOrEmpty(offsetID)) { if (!offsets.ContainsKey(offsetID)) { offsets.Add(offsetID, new OffsetType()); } var offsetValue = r.GetAttribute("offsetValue"); if (!String.IsNullOrEmpty(offsetValue)) { val.OffsetValue = Convert.ToDouble(offsetValue, CultureInfo.InvariantCulture); } } wrapper.OffsetID = offsetID; //data value val.Value = Convert.ToDouble(r.ReadString(), CultureInfo.InvariantCulture); } } else if (r.Name == "method") { var method = ReadMethod(r); var methodCodeKey = method.Code.ToString(CultureInfo.InvariantCulture); if (methods.ContainsKey(methodCodeKey)) { methods[methodCodeKey] = method; } } else if (r.Name == "source") { var source = ReadSource(r); var sourceCodeKey = source.OriginId.ToString(CultureInfo.InvariantCulture); if (sources.ContainsKey(sourceCodeKey)) { sources[sourceCodeKey] = source; } } else if (r.Name == "qualityControlLevel") { //quality control level seems to be included with each value } else if (r.Name == "qualifier") { ReadQualifier(r, qualifiers); } else if (r.Name == "offset") { ReadOffset(r, offsets); } } } //to assign special properties of each data value foreach (var wrapper in lst) { var val = wrapper.DataValue; //which series does the data value belong to? var seriesCode = wrapper.SeriesCode; if (!seriesDictionary.ContainsKey(seriesCode)) { var newSeries = new Series(); seriesDictionary.Add(seriesCode, newSeries); //assign method, source and qual.control level //assign method, source and qual.control level try { newSeries.Method = methods[SeriesCodeHelper.GetMethodCode(seriesCode)]; //fix by Jiri: fixes the case when sourceID is unspecified sources //has more than one source entry string sourceCode = SeriesCodeHelper.GetSourceCode(seriesCode); if (sourceCode == "0" && sources.Count > 0) { foreach (string sc in sources.Keys) { if (sc != "0") { sourceCode = sc; break; } } } newSeries.Source = sources[sourceCode]; newSeries.QualityControlLevel = qualityControlLevels[SeriesCodeHelper.GetQualityCode(seriesCode)]; } catch { } } //add the data value to the correct series var series = seriesDictionary[seriesCode]; series.DataValueList.Add(val); val.Series = series; Sample sample; if (!string.IsNullOrEmpty(wrapper.SampleID) && samples.TryGetValue(wrapper.SampleID, out sample)) { val.Sample = sample; } OffsetType offset; if (!string.IsNullOrEmpty(wrapper.OffsetID) && offsets.TryGetValue(wrapper.OffsetID, out offset)) { val.OffsetType = offset; } if (series.Method == null) { series.Method = methods[wrapper.MethodID]; } if (series.Source == null) { series.Source = sources[wrapper.SourceID]; } } //to check the qualifiers CheckQualifiers(qualifiers); return seriesDictionary.Values.ToList(); }
/// <summary> /// Adds a data series to this theme /// </summary> public virtual void AddSeries(Series series) { if (SeriesList == null) { SeriesList = new List<Series>(); } this.SeriesList.Add(series); series.ThemeList.Add(this); }
/// <summary> /// Reads DataValues from a WaterML2.0 XML file /// </summary> /// <param name="XmlNodeList"></param> private IList<Series> ReadDataValues(XmlDocument wmlDoc) { IList<Series> seriesList = new List<Series>(); XmlNodeList observations = wmlDoc.GetElementsByTagName("wml2:observationMember"); if (observations.Count == 0) observations = wmlDoc.GetElementsByTagName("om:OM_Observation"); if (observations.Count == 0) { Series newSeries = new Series(); newSeries = ReadDataSeries(wmlDoc); //add parsed series data to list if (newSeries.GetValueCount() > 0) seriesList.Add(newSeries); } //loop through each series observation foreach (XmlNode observation in observations) { Series newSeries = new Series(); XmlDocument xml = new XmlDocument(); xml.LoadXml(observation.OuterXml); newSeries = ReadDataSeries(xml); //add parsed series data to list if (newSeries.GetValueCount() > 0) seriesList.Add(newSeries); } return seriesList; }
/// <summary> /// Reads DataValues from a Series /// </summary> /// <param name="XmlNodeList"></param> private Series ReadDataSeries(XmlDocument xml) { Series newSeries = new Series(); XmlNodeList tvps = GetTVPList(xml); GetSeriesMetadata(xml, newSeries); GetDefaultNodeMetadata(xml, newSeries); //add Begin and End datetime to the series try { XmlNode begin = xml.GetElementsByTagName("gml:beginPosition").Item(0); XmlNode end = xml.GetElementsByTagName("gml:endPosition").Item(0); if (begin.InnerText.Length > 19) newSeries.BeginDateTime = Convert.ToDateTime(begin.InnerText.Remove(19)); else newSeries.BeginDateTime = Convert.ToDateTime(begin.InnerText); if (end.InnerText.Length > 19) newSeries.EndDateTime = Convert.ToDateTime(end.InnerText.Remove(19)); else newSeries.EndDateTime = Convert.ToDateTime(end.InnerText); } catch { } //add each Time-Value-Pair to the series foreach (XmlNode tvp in tvps) { Double value = -9999; DateTime time = new DateTime(); double utcOffset = 0; //parse Time-Value-Pair foreach (XmlNode child in tvp.ChildNodes) { if (!String.IsNullOrEmpty(child.Name)) { if (child.Name.ToLower() == "wml2:value" && child.InnerText != "") value = Double.Parse(child.InnerText); if (child.Name.ToLower() == "wml2:time" && child.InnerText != "") { String dateTime = child.InnerText; String utcoffset = "Z"; if (dateTime.Length > 19) { utcoffset = dateTime.Substring(19); dateTime = dateTime.Remove(19); } time = Convert.ToDateTime(dateTime); if (utcoffset.ToLower() == "z") utcOffset = 0; else utcOffset = ConvertUtcOffset(utcoffset); } if (child.Name.ToLower() == "wml2:metadata" && child.InnerText != "") GetNodeMetadata(child, newSeries); } } //add parsed Time-Value-Pair to series DataValue dataValue = new DataValue(value, time, utcOffset); newSeries.DataValueList.Add(dataValue); dataValue.Series = newSeries; } return newSeries; }
private void GetSeriesMetadata(XmlDocument xml, Series newSeries) { XmlNodeList meta = xml.GetElementsByTagName("wml2:MeasurementTimeseriesMetadata"); if (meta.Count == 0) meta = xml.GetElementsByTagName("wml2:TimeseriesMetadata"); if (meta.Count == 0) meta = xml.GetElementsByTagName("wml2:CategoricalTimeseriesMetadata"); }
private void GetNodeMetadata(XmlNode xmlNode, Series newSeries) { foreach (XmlNode child in xmlNode.FirstChild.ChildNodes) { } }
private void GetDefaultNodeMetadata(XmlDocument xml, Series newSeries) { XmlNodeList meta = xml.GetElementsByTagName("wml2:DefaultTVPMeasurementMetadata"); if (meta.Count == 0) meta = xml.GetElementsByTagName("wml2:DefaultTVPCategoricalMetadata"); if (meta.Count == 0) meta = xml.GetElementsByTagName("wml2:DefaultTVPMetadata"); if(meta.Count != 0) { foreach (XmlNode child in meta.Item(0).ChildNodes) { if (child.Name == "wml2:quality") { } if (child.Name == "wml2:qualifier") { } if (child.Name == "wml2:processing") { } if (child.Name == "wml2:uom") { } if (child.Name == "wml2:interpolationType") { foreach (XmlAttribute attribute in child.Attributes) { if (attribute.Name == "xlink:href") { string interpolationType = attribute.InnerText.Split('/').Last(); if (newSeries.Variable == null) newSeries.Variable = new Variable(); newSeries.Variable.DataType = interpolationType; } } } } } }