Ejemplo n.º 1
0
    function db_GetValues_OneSeriesWML2($siteID, $siteCode, $state, $variableCode, $variableID, $methodID, $sourceID, $qcID, $beginTime, $endTime)
    {
        $ci =& get_instance();
        $beginDT = date("Y-m-d", strtotime($beginTime));
        $endDT = date("Y-m-d", strtotime($endTime));
        //generate the URL:
        if (!isset($beginTime) || $beginTime == "" || !isset($endTime) || $endTime == "") {
            $beginDT = 'POR_BEGIN';
            $endDT = 'POR_END';
        }
        $base_url = "http://www.wcc.nrcs.usda.gov/reportGenerator/view_csv/customSingleStationReport/daily/";
        $url = $base_url . $siteCode . ":" . $state . ':SNTL%7Cid=%22%22%7Cname/' . $beginDT . ',' . $endDT . '/' . $variableCode . '::value';
        $retVal = '<om:result><wml2:MeasurementTimeseries gml:id="HIS.TS.1">';
        $beginDateTimeOP = date_create_from_format('Y-m-d H:i:s', $beginTime)->format('c');
        $endDateTimeOP = date_create_from_format('Y-m-d H:i:s', $endTime)->format('c');
        $retVal .= '<wml2:metadata>
					<wml2:MeasurementTimeseriesMetadata>
					  <wml2:temporalExtent>
						  <gml:TimePeriod gml:id="time-period.1">
							  <gml:beginPosition>' . $beginDateTimeOP . '</gml:beginPosition>
							  <gml:endPosition>' . $endDateTimeOP . '</gml:endPosition>
						  </gml:TimePeriod>
					  </wml2:temporalExtent>
				  </wml2:MeasurementTimeseriesMetadata>
				  </wml2:metadata>';
        $methodInfo = db_GetMethodByIDWML2($methodID);
        $variableInfo = db_GetVariableByCodeWML2($variableID, $methodID, 1);
        //Genertaing ISO Time period from HIS Parameters
        $timeInterval = "P";
        if ($variableInfo['TimeUnitsType'] == "Time") {
            $timeInterval .= "T";
        }
        $unitISO = strtoupper($variableInfo['TimeUnitsAbbreviation']);
        $timeInterval .= $variableInfo['TimeSupport'] . $unitISO[0];
        //Define Default Point Metadata
        $retVal .= '<wml2:defaultPointMetadata>
						<wml2:DefaultTVPMeasurementMetadata>
						<wml2:quality xlink:href="http://www.opengis.net/def/waterml/2.0/quality/good" xlink:title="not censored"/>' . '<wml2:qualifier>
							<swe:Text definition="#methodCode--' . $methodID . '">
								<swe:value>
								' . $methodInfo['MethodDescription'] . '
								</swe:value>
							</swe:Text>
						</wml2:qualifier>' . db_GetQualityControlLevelByIDWML2($qcID) . '<wml2:source xlink:href="#' . $sourceID . '"/>' . '<wml2:uom code="' . $variableInfo['VariableUnitsAbbreviation'] . '"/>
						<wml2:interpolationType xlink:href="http://his.cuahsi.org/cv/dataType/' . $variableInfo['DataType'] . '" xlink:title="' . $variableInfo['DataType'] . '"/>
						<wml2:aggregationDuration>' . $timeInterval . '</wml2:aggregationDuration>' . '</wml2:DefaultTVPMeasurementMetadata>
					</wml2:defaultPointMetadata>';
        //Adding censor code data to dictionary
        $dictEntry = '
		<gml:dictionaryEntry>
		<gml:Definition gml:id="censorCode-nc">
		<gml:identifier codeSpace="http://hiscentral.cuahsi.org/wml/censored">nc</gml:identifier>
		<gml:name codeSpace="http://hiscentral.cuahsi.org/wml/censored">not censored</gml:name>
		</gml:Definition>
		</gml:dictionaryEntry>';
        addToLocalDictionaryWML2("censorCode", $dictEntry);
        //Printing Values
        $txt_file = file_get_contents($url);
        $rows = explode("\n", $txt_file);
        array_shift($rows);
        $nr = 0;
        $retVal = '<om:result><wml2:MeasurementTimeseries>';
        $nr = 0;
        foreach ($rows as $row => $data) {
            $nr++;
            if ($nr > 7) {
                $row_data = explode(',', $data);
                if (count($row_data) > 1) {
                    $dat = $row_data[0];
                    $dateOP = date_create_from_format('Y-m-d', $dat)->setTimezone(new DateTimeZone('UTC'))->format('c');
                    $retVal .= '<wml2:point>
							<wml2:MeasurementTVP>
								<wml2:time>' . $dateOP . '</wml2:time>
								<wml2:value>' . to_metric($row_data[1], $variableCode) . '</wml2:value>
						</wml2:MeasurementTVP>
				    </wml2:point>
				    ';
                }
            }
        }
        $retVal .= '</wml2:MeasurementTimeseries></om:result>';
        return $retVal;
    }
Ejemplo n.º 2
0
    function db_GetValues_OneSeriesWML2($siteID, $variableID, $methodID, $sourceID, $qcID, $beginTime, $endTime)
    {
        $ci =& get_instance();
        $data_values_table = get_table_name('DataValues');
        $samples_table = get_table_name('Samples');
        $ci->db->select("d.LocalDateTime, d.UTCOffset, d.DateTimeUTC, d.DataValue, s.LabSampleCode");
        $ci->db->join($samples_table . " s", "d.SampleID = s.SampleID", "LEFT");
        $ci->db->where("d.SiteID", $siteID);
        $ci->db->where("d.VariableID", $variableID);
        $ci->db->where("d.MethodID", $methodID);
        $ci->db->where("d.SourceID", $sourceID);
        $ci->db->where("d.QualityControlLevelID", $qcID);
        $ci->db->order_by("d.LocalDateTime");
        if (isset($beginTime) && $beginTime != "" && (isset($endTime) && $endTime != "")) {
            $ci->db->where("d.LocalDateTime >=", $beginTime);
            $ci->db->where("d.LocalDateTime <=", $endTime);
        }
        $result = $ci->db->get($data_values_table . " d");
        if (!$result) {
            die("<p>Error in executing the SQL query " . $ci->db->last_query() . ": " . $ci->db->_error_message() . "</p>");
        }
        $retVal = '<om:result><wml2:MeasurementTimeseries gml:id="HIS.TS.1">';
        $beginDateTimeOP = date_create_from_format('Y-m-d H:i:s', $beginTime)->format('c');
        $endDateTimeOP = date_create_from_format('Y-m-d H:i:s', $endTime)->format('c');
        $retVal .= '<wml2:metadata>
					<wml2:MeasurementTimeseriesMetadata>
					  <wml2:temporalExtent>
						  <gml:TimePeriod gml:id="time-period.1">
							  <gml:beginPosition>' . $beginDateTimeOP . '</gml:beginPosition>
							  <gml:endPosition>' . $endDateTimeOP . '</gml:endPosition>
						  </gml:TimePeriod>
					  </wml2:temporalExtent>
				  </wml2:MeasurementTimeseriesMetadata>
				  </wml2:metadata>';
        $methodInfo = db_GetMethodByIDWML2($methodID);
        $variableInfo = db_GetVariableByCodeWML2($variableID, $methodID, 1);
        //Genertaing ISO Time period from HIS Parameters
        $timeInterval = "P";
        if ($variableInfo['TimeUnitsType'] == "Time") {
            $timeInterval .= "T";
        }
        $unitISO = strtoupper($variableInfo['TimeUnitsAbbreviation']);
        $timeInterval .= $variableInfo['TimeSupport'] . $unitISO[0];
        //Define Default Point Metadata
        $retVal .= '<wml2:defaultPointMetadata>
						<wml2:DefaultTVPMeasurementMetadata>
						<wml2:quality xlink:href="http://www.opengis.net/def/waterml/2.0/quality/good" xlink:title="not censored"/>' . '<wml2:qualifier>
							<swe:Text definition="#methodCode--' . $methodID . '">
								<swe:value>
								' . $methodInfo['MethodDescription'] . '
								</swe:value>
							</swe:Text>
						</wml2:qualifier>' . db_GetQualityControlLevelByIDWML2($qcID) . '<wml2:source xlink:href="#' . $sourceID . '"/>' . '<wml2:uom code="' . $variableInfo['VariableUnitsAbbreviation'] . '"/>
						<wml2:interpolationType xlink:href="http://his.cuahsi.org/cv/dataType/' . $variableInfo['DataType'] . '" xlink:title="' . $variableInfo['DataType'] . '"/>
						<wml2:aggregationDuration>' . $timeInterval . '</wml2:aggregationDuration>' . '</wml2:DefaultTVPMeasurementMetadata>
					</wml2:defaultPointMetadata>';
        //Adding censor code data to dictionary
        $dictEntry = '
		<gml:dictionaryEntry>
		<gml:Definition gml:id="censorCode-nc">
		<gml:identifier codeSpace="http://hiscentral.cuahsi.org/wml/censored">nc</gml:identifier>
		<gml:name codeSpace="http://hiscentral.cuahsi.org/wml/censored">not censored</gml:name>
		</gml:Definition>
		</gml:dictionaryEntry>';
        addToLocalDictionaryWML2("censorCode", $dictEntry);
        //Printing Values
        foreach ($result->result_array() as $row) {
            $dateOP = date_create_from_format('Y-m-d H:i:s', $row['DateTimeUTC'])->setTimezone(new DateTimeZone('UTC'))->format('c');
            $retVal .= '<wml2:point>
							<wml2:MeasurementTVP>
								<wml2:time>' . $dateOP . '</wml2:time>
								<wml2:value>' . $row['DataValue'] . '</wml2:value>
						</wml2:MeasurementTVP>
				</wml2:point>
				';
        }
        $retVal .= '</wml2:MeasurementTimeseries></om:result>';
        return $retVal;
    }