/// <summary>
            /// Creates the URL
            /// </summary>
            /// <param name="startDate"></param>
            /// <param name="endDate"></param>
            /// <param name="variables"></param>
            /// <param name="stations"></param>
            /// <param name="agency"></param>
            /// <returns></returns>
            private string InstantaneousData(W3CDateTime?startDate, W3CDateTime?endDate, string[] variables, string[] stations, string agency)
            {
                String StartDate = USGSCommon.usgsTime(startDate);
                String EndDate   = USGSCommon.usgsTime(endDate);
                // Feb 2007 added parameters

                /*
                 * http://nwis.waterdata.usgs.gov/nwis/qwdata?site_no=01578310
                 * &agency_cd=USGS&begin_date=&end_date=
                 * &TZoutput=0&qw_attributes=0&inventory_output=0&rdb_inventory_output=value
                 * &format=rdb&qw_sample_wide=0&rdb_qw_attributes=0
                 * &date_format=YYYY-MM-DD&rdb_compression=value&submitted_form=brief_list
                 *
                 * important one is &qw_sample_wide=0
                 */
                // adding one day to make the service function correctly.
                string URL = BaseUrl + "?" +
                             USGSCommon.usgsStationQP(stations) +
                             "&agency_cd=" + agency +
                             //StationsList +
                             USGSCommon.usgsVariablesQP(variables) +
                             //"&parameter_cd=" + Variable +
                             USGSCommon.usgsTimePeriodQP(startDate,
                                                         endDate.HasValue ? endDate.Value.AddDays(1) : endDate) +
                             "&format=rdb&" +
                             "qw_attributes=0&inventory_output=0" +
                             "&rdb_inventory_output=value" +
                             "&qw_sample_wide=0" +
                             "&rdb_qw_attributes=0"
                ;

                //"&date_format=YYYY-MM-DD" + "&begin_date=" + StartDate + "&end_date=" + EndDate;

                return(URL);
            }
Example #2
0
            private TsValuesSingleVariableType CreateGWTimeSeriesObject(VariableParam vp, string aURL)
            {
                // download the iformation
                String resultFile = USGSCommon.GetHTTPFile(aURL, 10);

                TsValuesSingleVariableType values = new TsValuesSingleVariableType();
                //result.TimeSeries.Values.valueUnits = units; // this needs to be done earlier


                DataTable aTable = NWISDelimitedTextParser.ParseFileIntoDT(resultFile);

                // dwv add code to get the code, and use that to find the correct columns
                int    time = 2; // present location of time column
                String code = vp.Code;
                String stat = null;
                int    aValue;
                int    qualifier;

                //if (result.timeSeries.variable.options != null)
                //{
                //    stat = result.timeSeries.variable.options[0].Value;
                //}
                try
                {
                    aValue    = USGSCommon.getVarColumn(aTable, "lev_va", null); // uses eEndWith... so this should work
                    qualifier = USGSCommon.getVarQualifiersColumn(aTable, "lev_status_cd", null);
                }
                catch (WaterOneFlowException we)
                {
                    // need to insert the URL in the exception
                    if (string.IsNullOrEmpty(stat))
                    {
                        throw new WaterOneFlowException("URL: '" + aURL, we);
                        //+"' variable '"+code+"' not found at site.");
                    }
                    else
                    {
                        throw new WaterOneFlowException("URL: '" + aURL, we);
                        //+ "' variable '"+code+"' statistic '"+stat +"' not found at site. Try not using the statistic", we);
                    }
                }

                List <ValueSingleVariable> tsTypeList = new List <ValueSingleVariable>();

                //TimeSeriesFromRDB(aTable, time, aValue, qualifier, tsTypeList);

                USGSCommon.TimeSeriesFromRDB(aTable, time, aValue, qualifier, tsTypeList, false);

                values.count = tsTypeList.Count;
                values.value = tsTypeList.ToArray();

                return(values);
            }
            /// <summary>
            /// Creates the URL
            /// </summary>
            /// <param name="startDate"></param>
            /// <param name="endDate"></param>
            /// <param name="stations"></param>
            /// <param name="agency"></param>
            /// <returns></returns>
            // really is only one groundwater parameter
            private string GroundWater(W3CDateTime?startDate, W3CDateTime?endDate, string[] stations, string agency)
            {
                // convert date to string and trim off Time
                String StartDate = USGSCommon.usgsTime(startDate);
                String EndDate   = USGSCommon.usgsTime(endDate);
                string URL       = BaseUrl + "?" +
                                   USGSCommon.usgsStationQP(stations) +
                                   //StationsList +
                                   "&agency_cd=" + agency +
                                   USGSCommon.usgsTimePeriodQP(startDate, endDate) +
                                   //"&date_format=YYYY-MM-DD" + "&begin_date=" + StartDate + "&end_date=" + EndDate +
                                   "&set_logscale_y=1" +
                                   "&format=rdb&rdb_compression=value";

                return(URL);
            }
Example #4
0
            /// <summary>
            /// Creates the URL
            /// </summary>
            /// <param name="startDate"></param>
            /// <param name="endDate"></param>
            /// <param name="stations"></param>
            /// <returns></returns>
            // really is only one groundwater parameter
            private string GroundWater(Nullable <W3CDateTime> startDate, Nullable <W3CDateTime> endDate, string[] stations)
            {
                // convert date to string and trim off Time
                String StartDate = USGSCommon.usgsTime(startDate);
                String EndDate   = USGSCommon.usgsTime(endDate);
                string URL       = "http://nwis.waterdata.usgs.gov/nwis/gwlevels?" +
                                   USGSCommon.usgsStationQP(stations) +
                                   //StationsList +
                                   "&agency_cd=USGS" +
                                   USGSCommon.usgsTimePeriodQP(startDate, endDate) +
                                   //"&date_format=YYYY-MM-DD" + "&begin_date=" + StartDate + "&end_date=" + EndDate +
                                   "&set_logscale_y=1" +
                                   "&format=rdb&rdb_compression=value";

                return(URL);
            }
Example #5
0
            private static string UnitValues(
                Nullable <W3CDateTime> startDate, Nullable <W3CDateTime> endDate,
                string[] variables, string[] stations)
            {
                // only a start date is needed.
                String StartDate = USGSCommon.usgsTime(startDate);
                String EndDate   = USGSCommon.usgsTime(endDate);
                string URL       = "http://nwis.waterdata.usgs.gov/nwis/uv?format=rdb&date_format=YYYY-MM-DD&" +
                                   USGSCommon.usgsStationQP(stations) +
                                   //StationsList +
                                   USGSCommon.usgsVariablesQP(variables) +
                                   //"&parameter_cd=" + Variable +
                                   // no longer accepts begin_date= as parameter
                                   USGSCommon.usgsTimePeriodQP(startDate, endDate);

                //USGSCommon.usgsUnitValuesPeriod(startDate, endDate);


                return(URL);
            }
            /// <summary>
            /// Creates the URL
            /// </summary>
            /// <param name="startDate"></param>
            /// <param name="endDate"></param>
            /// <param name="variables"></param>
            /// <param name="stations"></param>
            /// <returns></returns>
            private string InstantaneousData(
                Nullable <W3CDateTime> startDate, Nullable <W3CDateTime> endDate,
                string[] variables,
                string[] stations)
            {
                String StartDate = USGSCommon.usgsTime(startDate);
                String EndDate   = USGSCommon.usgsTime(endDate);
                // Feb 2007 added parameters

                /*
                 * http://nwis.waterdata.usgs.gov/nwis/qwdata?site_no=01578310
                 * &agency_cd=USGS&begin_date=&end_date=
                 * &TZoutput=0&qw_attributes=0&inventory_output=0&rdb_inventory_output=value
                 * &format=rdb&qw_sample_wide=0&rdb_qw_attributes=0
                 * &date_format=YYYY-MM-DD&rdb_compression=value&submitted_form=brief_list
                 *
                 * important one is &qw_sample_wide=0
                 */

                string URL = "http://nwis.waterdata.usgs.gov/nwis/qwdata?" +
                             USGSCommon.usgsStationQP(stations) +
                             //StationsList +
                             USGSCommon.usgsVariablesQP(variables) +
                             //"&parameter_cd=" + Variable +
                             USGSCommon.usgsTimePeriodQP(startDate, endDate) +
                             "&format=rdb&" +
                             "qw_attributes=0&inventory_output=0" +
                             "&rdb_inventory_output=value" +
                             "&qw_sample_wide=0" +
                             "&rdb_qw_attributes=0"
                ;

                //"&date_format=YYYY-MM-DD" + "&begin_date=" + StartDate + "&end_date=" + EndDate;

                return(URL);
            }
            public override object GetTimeSeries(
                locationParam lp,
                VariableParam vp,
                Nullable <W3CDateTime> startDate,
                Nullable <W3CDateTime> endDate)
            {
                if (lp.isGeometry)
                {
                    throw new WaterOneFlowException("Geometry not supported ");
                }

                TimeSeriesResponseType result = null;

                //string Network;
                //string SiteCode;
                ////WSUtils.ParseSiteId(siteId, out Network, out SiteCode);
                //try
                //{
                //    locationParam sq = new locationParam(siteNumber);
                //    Network = sq.Network;
                //    SiteCode = sq.SiteCode;
                //    if (sq.isGeometry)
                //    {
                //        throw new WaterOneFlowException("Location by Geometry not accepted: " + siteNumber);
                //    }
                //}
                //catch (WaterOneFlowException we)
                //{
                //    log.Info("Bad SiteID:" + siteNumber);
                //    throw;
                //}
                //catch (Exception e)
                //{
                //    log.Error("Uncaught exception:" + e.Message);
                //    throw new WaterOneFlowException("Sorry. Your submitted site ID for this getSiteInfo request caused an problem that we failed to catch programmatically: " + e.Message);
                //}

                //// string WaterQualityList = "&parameter_cd=" + variable;
                //string[] StationsList = new string[] { SiteCode };
                string[] StationsList = new string[] { lp.SiteCode };

                //VariableParam vp;
                //try
                //{
                //    vp = new VariableParam(variable);

                //}
                //catch (WaterOneFlowException we)
                //{
                //    log.Info("Bad Variable Request '" + variable + "'");
                //    throw;
                //}
                //catch (Exception e)
                //{
                //    log.Error("uncaught exception duing Variable Request '" + variable + "'");
                //    throw new WaterOneFlowException("Sorry. Your variable parameter caused an exception that we failed to catch:" + e.Message);

                //}

                result = CuahsiBuilder.CreateTimeSeriesObject();

                //// all data are provisional
                //List<note> notes = new List<note>();
                //note urlNote = new note();
                //urlNote.title = "USGS Data Provisional";
                //urlNote.href = "http://waterdata.usgs.gov/nwis/help/?provisional";
                //urlNote.Value = "All data are provisional, and subject to revision";
                //notes.Add(urlNote);
                //result.queryInfo.note = notes.ToArray();

                result.queryInfo.criteria.locationParam = lp.ToString();
                result.queryInfo.criteria.variableParam = vp.ToString();


                // result.queryInfo.criteria.timeParam  = CuahsiBuilder.createQueryInfoTimeCriteria(startDate, endDate);

                // look for siteInfoType in cache, and use if it is there

                /* SiteInfoType sit = (SiteInfoType)appCache[sitCache + SiteCode];
                 * if (sit == null)
                 * {
                 *   // just use the values for now.
                 *   ((SiteInfoType)result.timeSeries.sourceInfo).siteCode[0].Value = SiteCode;
                 *   ((SiteInfoType)result.timeSeries.sourceInfo).siteCode[0].network = "NWIS";
                 *
                 * }
                 * else
                 * {
                 *   // in the cache, use it
                 *   result.timeSeries.sourceInfo = sit;
                 * }
                 * */
                result.timeSeries.sourceInfo = DataInfoService.GetSite(lp);


                // vaiable info
                // result.timeSeries.variable = vp.getVariableSchemaType();
                //result.timeSeries.variable = NwisVariableCatalog.getVariable(vp.Code, variableDataSet);
                //result.timeSeries.variable = ODvariables.getVariable(vp.Code, variableDataSet)[0];

                // not fully correct, but just choose the first one.
                VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp);
                result.timeSeries.variable = vits[0];
                string aURL = GroundWater(startDate, endDate,
                                          StationsList, USGSCommon.option2AgencyCode(lp));

                try
                {
                    // refactor too much abstraction
                    //CreateRealTimeSeriesObject(result, RealTime(StationsList));
                    result.timeSeries.values =
                        CreateGWTimeSeriesObject(vp, aURL);
                }
                catch (WaterOneFlowException e)
                {
                    //log.Error(e.Message + e.StackTrace);
                    throw;
                }
                catch (WaterOneFlowSourceException e)
                {
                    //log.Error(e.Message + e.StackTrace);
                    throw;
                }
                catch (WebException e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("Connecting to External resource failed.", e);
                }
                catch (Exception e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("An External resource failed.", e);
                }

                result.timeSeries.sourceInfo = DataInfoService.GetSite(lp);

                List <NoteType> notes   = new List <NoteType>();
                NoteType        urlNote = new NoteType();

                urlNote.title = "USGS URL";
                urlNote.Value = aURL;
                notes.Add(urlNote);
                result.queryInfo.note = notes.ToArray();

                return(result);
            }
            public override object GetTimeSeries(
                locationParam lp,
                VariableParam vp,
                Nullable <W3CDateTime> startDate,
                Nullable <W3CDateTime> endDate)
            {
                if (lp.isGeometry)
                {
                    throw new WaterOneFlowException("Geometry not supported ");
                }

                TimeSeriesResponseType result = null;

                string[] StationsList = new string[] { lp.SiteCode };

                result = CuahsiBuilder.CreateTimeSeriesObject();

                result.queryInfo.criteria.locationParam = lp.ToString();
                result.queryInfo.criteria.variableParam = vp.ToString();

                result.timeSeries.sourceInfo = DataInfoService.GetSite(lp);

                // not fully correct, but just choose the first one.
                VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp);
                result.timeSeries.variable = vits[0];
                string aURL = InstantaneousData(startDate, endDate,
                                                new string[] { vp.Code }, StationsList, USGSCommon.option2AgencyCode(lp));

                try
                {
                    result.timeSeries.values =
                        CreateWQTimeSeriesObject(vp, aURL);
                }
                catch (WaterOneFlowException e)
                {
                    throw;
                }
                catch (WaterOneFlowSourceException e)
                {
                    throw;
                }
                catch (Exception e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("An External resource failed.", e);
                }

                List <NoteType> notes   = new List <NoteType>();
                NoteType        urlNote = new NoteType();

                urlNote.title = "USGS URL";
                urlNote.Value = aURL;
                notes.Add(urlNote);
                result.queryInfo.note = notes.ToArray();

                return(result);
            }
            private TsValuesSingleVariableType CreateWQTimeSeriesObject(VariableParam vp, string aURL)
            {
                // download the iformation
                String resultFile = USGSCommon.GetHTTPFile(aURL, 10);

                TsValuesSingleVariableType values = new TsValuesSingleVariableType();
                //result.TimeSeries.Values.valueUnits = units; // this needs to be done earlier


                DataTable aTable = NWISDelimitedTextParser.ParseFileIntoDT(resultFile);

                // dwv add code to get the code, and use that to find the correct columns
                // time and date are separate
                int    date = 2; // present location of time column
                int    time = 3;
                String code = vp.Code;
                int    codeCol;
                int    aValue;
                int    qualifier; // there are many qa columns. what do we want to do about them

                /* 20070909
                 * add
                 #  meth_cd                    - Method code
                 #  dqi_cd                     - Data-quality indicator code
                 #  rpt_lev_va                 - Reporting level
                 #  rpt_lev_cd                 - Reporting level type
                 #  lab_std_va                 - Lab standard deviation
                 #  anl_ent_cd                 - Analyzing entity code
                 */
                int method;

                try
                {
                    /* 20070909 - USGS column name changes
                     * parameter_cd to param_cd
                     *     APPSETTING: ConfigurationManager.AppSettings["parameterColumn"];
                     * qualifiers now in val_qual_tx
                     * also:
                     #  meth_cd                    - Method code
                     #  dqi_cd                     - Data-quality indicator code
                     #  rpt_lev_va                 - Reporting level
                     #  rpt_lev_cd                 - Reporting level type
                     #  lab_std_va                 - Lab standard deviation
                     #  anl_ent_cd                 - Analyzing entity code
                     */
                    //codeCol = getVarQualifiersColumn(aTable, "parameter_cd", null);
                    string parmameterColName = (string)Properties.Settings.Default["parameterColumn"];
                    codeCol   = USGSCommon.getVarQualifiersColumn(aTable, parmameterColName, null);
                    aValue    = USGSCommon.getVarColumn(aTable, "result_va", null);
                    qualifier = USGSCommon.getVarQualifiersColumn(aTable, "remark_cd", null); // there are many qa columns. what do we want to do about them
                    // qualifier = getVarColumn(aTable, "val_qual_tx", null); //Do Not use at present
                }
                catch (WaterOneFlowException we)
                {
                    throw new WaterOneFlowException("URL: '" + aURL, we);
                }
                List <ValueSingleVariable> tsTypeList = new List <ValueSingleVariable>();

                foreach (DataRow aRow in aTable.Rows)
                {
                    if (aRow[codeCol].Equals(code))
                    { // only do this if this is the correct value
                        ValueSingleVariable tsTypeValue = new ValueSingleVariable();
                        //tsTypeValue.time= Convert.ToDateTime(aRow[time]);
                        tsTypeValue.dateTime = Convert.ToDateTime(
                            aRow[date].ToString() +
                            " " + aRow[time].ToString()
                            );
                        // tsTypeValue.dateTimeSpecified = true;
                        //tsTypeValue.censored = string.Empty;
                        if (string.IsNullOrEmpty(aRow[aValue].ToString()))
                        {
                            continue;
                        }
                        else
                        {
                            tsTypeValue.Value = Convert.ToDecimal(aRow[aValue]);
                        }

                        USGSCommon.parseQualifiersForCensorCode(tsTypeValue, aRow[qualifier].ToString()); // this will add censored, if appropariate
                        // added for  hydrodesktop
                        tsTypeValue.qualityControlLevel          = QualityControlLevelEnum.Unknown;
                        tsTypeValue.qualityControlLevelSpecified = true;
                        tsTypeValue.methodID          = 0;
                        tsTypeValue.methodIDSpecified = true;
                        tsTypeValue.sourceID          = 1;
                        tsTypeValue.sourceIDSpecified = true;
                        tsTypeList.Add(tsTypeValue);
                    }
                }
                values.count = tsTypeList.Count.ToString();
                values.value = tsTypeList.ToArray();

                // add added qualifiers
                values.source                      = new SourceType[1];
                values.source[0]                   = new SourceType();
                values.source[0].sourceID          = 1;
                values.source[0].sourceIDSpecified = true;
                values.source[0].Organization      = "USGS";
                values.source[0].SourceDescription = "US Geological Survey National Water Information System";
                values.source[0].SourceLink        = "http://waterdata.usgs.gov/";

                values.qualityControlLevel    = new qualityControlLevel[1];
                values.qualityControlLevel[0] = new qualityControlLevel();
                values.qualityControlLevel[0].qualityControlLevelID   = "0";
                values.qualityControlLevel[0].qualityControlLevelCode = "Unknown";

                values.method                      = new MethodType[1];
                values.method[0]                   = new MethodType();
                values.method[0].methodID          = 0;
                values.method[0].methodIDSpecified = true;
                values.method[0].MethodDescription = "Unknown";

                return(values);
            }
Example #10
0
            /*
             * public  TimeSeriesResponseType GetValues(
             *  locationParam Location,
             *   VariableParam Variable,
             *   W3CDateTime? BeginDateTime, W3CDateTime? EndDateTime)
             */



            public override WaterOneFlow.Service.Response.v1_1.TimeSeriesResponseType GetTimeSeries(
                locationParam lp,
                VariableParam vp,
                Nullable <W3CDateTime> startDate,
                Nullable <W3CDateTime> endDate)
            {
                // put the date check up front.
                // a start date can be older than 31 days, as long as the endDate is not older than 31 days.

                if (endDate.HasValue && endDate.Value.DateTime < DateTime.Today.AddDays(-31))
                {
                    throw new WaterOneFlowException("No Data. EndDate must be less than that 31 days from present.");
                }

                TimeSeriesResponseType result = null;

                string[] StationsList = new string[] { lp.SiteCode };

                result = CuahsiBuilder.CreateTimeSeriesObject();


                result.queryInfo.criteria.locationParam = lp.ToString();
                result.queryInfo.criteria.variableParam = vp.ToString();

                // not fully correct, but just choose the first one.
                VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp);
                result.timeSeries.variable = vits[0];

                string aUrl = UnitValues(startDate, endDate,
                                         new string[] { vp.Code }, StationsList);

                try
                {
                    // refactor too much abstraction
                    //CreateRealTimeSeriesObject(result, RealTime(StationsList));
                    result.timeSeries.values    = new TsValuesSingleVariableType[1];
                    result.timeSeries.values[0] =
                        USGSCommon.CreateTimeSeriesValuesElement(vp,
                                                                 aUrl,
                                                                 true // add provisional flag
                                                                 );
                }
                catch (Exception e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("An External resource failed.", e);
                }


                // all data are provisional
                List <NoteType> notes = new List <NoteType>();
                NoteType        pNote = new NoteType();

                pNote.title = "USGS Data Provisional";
                pNote.href  = "http://waterdata.usgs.gov/nwis/help/?provisional";
                pNote.Value = "All data are provisional, and subject to revision";
                notes.Add(pNote);

                NoteType urlNote = new NoteType();

                urlNote.title = "USGS URL";
                urlNote.Value = aUrl;
                notes.Add(urlNote);

                result.queryInfo.note = notes.ToArray();

                return(new WaterOneFlow.Service.v1_1.xsd.TimeSeriesResponse(result));
            }