Exemplo n.º 1
0
 /// <summary>
 /// Creates a new data series associated with the specific site, variable,
 /// method, quality control level and source. This series will contain zero
 /// data values after creation.
 /// </summary>
 /// <param name="site">the observation site (location of measurement)</param>
 /// <param name="variable">the observed variable</param>
 /// <param name="method">the observation method</param>
 /// <param name="qualControl">the quality control level of observed values</param>
 /// <param name="source">the source of the data values for this series</param>
 public SeriesMetadata(Site site, Variable variable, Method method, QualityControlLevel qualControl, Source source)
 {
     ValueCount = 0;
     Site = site;
     Variable = variable;
     Method = method;
     QualityControlLevel = qualControl;
     Source = source;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new data series associated with the specific site, variable,
 /// method, quality control level and source. This series will contain zero
 /// data values after creation.
 /// </summary>
 /// <param name="site">the observation site (location of measurement)</param>
 /// <param name="variable">the observed variable</param>
 /// <param name="method">the observation method</param>
 /// <param name="qualControl">the quality control level of observed values</param>
 /// <param name="source">the source of the data values for this series</param>
 public Series(Site site, Variable variable, Method method, QualityControlLevel qualControl, Source source)
     : this()
 {
     Site = site;
     Variable = variable;
     Method = method;
     QualityControlLevel = qualControl;
     Source = source;
 }
Exemplo n.º 3
0
        protected virtual void ReadSpatialReference(XmlReader r, Site site)
        {
            while (r.Read())
            {
                //lat long datum (srs)
                if (r.NodeType == XmlNodeType.Element && r.Name == "geogLocation")
                {
                    if (r.HasAttributes)
                    {
                        site.SpatialReference = new SpatialReference();
                        string srsName = r.GetAttribute("srs");
                        if (String.IsNullOrEmpty(srsName))
                        {
                            srsName = "unknown";
                        }
                        site.SpatialReference.SRSName = srsName;
                    }
                }

                //local projection
                if (r.NodeType == XmlNodeType.Element && r.Name == "localSiteXY" && r.HasAttributes)
                {
                    site.LocalProjection = new SpatialReference();
                    site.LocalProjection.SRSName = r.GetAttribute("projectionInformation");
                }

                if (XmlContext.AdvanceReaderPastEmptyElement(r))
                {
                    //Empty element - advance and continue...
                    continue;
                }

                //latitude
                if (r.NodeType == XmlNodeType.Element && r.Name == "latitude")
                {
                    r.Read();
                    site.Latitude = r.ReadContentAsDouble();
                }

                //longitude
                if (r.NodeType == XmlNodeType.Element && r.Name == "longitude")
                {
                    r.Read();
                    site.Longitude = r.ReadContentAsDouble();
                }

                //local projection
                if (r.NodeType == XmlNodeType.Element && r.Name == "localSiteXY" && r.HasAttributes)
                {
                    site.LocalProjection = new SpatialReference();
                    site.LocalProjection.SRSName = r.GetAttribute("projectionInformation");
                }

                if (r.NodeType == XmlNodeType.Element && r.Name == "X")
                {
                    r.Read();
                    site.LocalX = r.ReadContentAsDouble();
                }

                if (r.NodeType == XmlNodeType.Element && r.Name == "Y")
                {
                    r.Read();
                    site.LocalY = r.ReadContentAsDouble();
                }

                if (r.NodeType == XmlNodeType.EndElement && r.Name == "geoLocation")
                {
                    return;
                }
            }
        }
Exemplo n.º 4
0
        protected virtual Site ReadSite(XmlReader r)
        {
            var site = new Site();
            while (r.Read())
            {
                var nodeName = r.Name.ToLower();

                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    if (nodeName == "sitename")
                    {
                        r.Read();
                        site.Name = r.Value;
                    }
                    else if (nodeName == "geolocation")
                    {
                        ReadSpatialReference(r, site);
                    }
                    else if (nodeName.IndexOf("sitecode", StringComparison.Ordinal) >= 0)
                    {
                        string networkPrefix = r.GetAttribute("network");

                        //BCC - 08-Aug-2016 - Retrieve siteID attribute value...
                        string siteID = r.GetAttribute("siteID");
                        long result = 0;
                        if (long.TryParse(siteID, out result))
                        {
                            site.Id = result;
                        }

                        r.Read();
                        string siteCode = r.Value;
                        if (!String.IsNullOrEmpty(networkPrefix))
                        {
                            siteCode = networkPrefix + ":" + siteCode;
                        }
                        site.Code = siteCode;
                        site.NetworkPrefix = networkPrefix;
                    }
                    else if (nodeName == "verticaldatum")
                    {
                        r.Read();
                        site.VerticalDatum = r.Value;
                    }
                    else if (nodeName == "timezoneinfo")
                    {
                        site.DefaultTimeZone = ReadTimeZoneInfo(r);
                    }
                    else if (nodeName == "elevation_m")
                    {
                        r.Read();
                        site.Elevation_m = Convert.ToDouble(r.Value, CultureInfo.InvariantCulture);
                    }
                    // WaterML 1.0 notes
                    else if (nodeName == "note")
                    {
                        var title = r.GetAttribute("title");
                        if (!String.IsNullOrEmpty(title))
                        {
                            title = title.ToLower();
                            r.Read();
                            var value = r.Value;
                            switch (title)
                            {
                                case "county":
                                    site.County = value;
                                    break;
                                case "state":
                                    site.State = value;
                                    break;
                                case "comments":
                                    site.Comments = value;
                                    break;
                            }
                        }
                    }
                    // WaterML 1.1 site properties
                    else if (nodeName == "siteproperty")
                    {
                        var title = r.GetAttribute("name");
                        if (!String.IsNullOrEmpty(title))
                        {
                            title = title.ToLower();
                            r.Read();
                            var value = r.Value;
                            switch (title)
                            {
                                case "county":
                                    site.County = value;
                                    break;
                                case "state":
                                    site.State = value;
                                    break;
                                case "comments":
                                    site.Comments = value;
                                    break;
                                case "sitetype":
                                    site.SiteType = value;
                                    break;
                                case "country":
                                    site.Country = value;
                                    break;
                                case "posaccuracy_m":
                                    site.PosAccuracy_m = Convert.ToDouble(value, CultureInfo.InvariantCulture);
                                    break;
                            }
                        }
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement &&
                    (nodeName.StartsWith("source") || nodeName.StartsWith("siteinfo")))
                {
                    //ensure that spatial reference is set
                    if (site.SpatialReference == null)
                    {
                        site.SpatialReference = new SpatialReference { SRSID = 0, SRSName = "unknown" };
                    }

                    return site;
                }
            }
            return null;
        }
Exemplo n.º 5
0
        protected virtual SeriesMetadata ReadSeriesFromSiteInfo(XmlReader r, Site site)
        {
            var series = new SeriesMetadata { Site = site };

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    string nodeName = r.Name.ToLower();
                    if (nodeName == "variable")
                    {
                        series.Variable = ReadVariable(r);
                    }
                    else if (nodeName == "valuecount")
                    {
                        r.Read();
                        series.ValueCount = Convert.ToInt32(r.Value);
                    }
                    else if (nodeName == "begindatetime")
                    {
                        r.Read();
                        series.BeginDateTime = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                        series.BeginDateTimeUTC = series.BeginDateTime;
                    }
                    else if (nodeName == "enddatetime")
                    {
                        r.Read();
                        series.EndDateTime = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                        series.EndDateTimeUTC = series.EndDateTime;
                    }
                    else if (nodeName == "begindatetimeutc")
                    {
                        r.Read();
                        series.BeginDateTimeUTC = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                    }
                    else if (nodeName == "enddatetimeutc")
                    {
                        r.Read();
                        series.EndDateTimeUTC = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                    }
                    else if (nodeName == "method")
                    {
                        series.Method = ReadMethod(r);
                    }
                    else if (nodeName == "source")
                    {
                        series.Source = ReadSource(r);
                    }
                    else if (nodeName == "qualitycontrollevel")
                    {
                        series.QualityControlLevel = ReadQualityControlLevel(r);
                    }
                }
                else
                {
                    if (r.NodeType == XmlNodeType.EndElement && r.Name == "series")
                    {
                        return series;
                    }
                }
            }
            return series;
        }