def __init__(self, element, wqx_ns): self._root = element self.id = testXMLValue( self._root.find(nsp("OrganizationIdentifier", wqx_ns))) self.name = testXMLValue( self._root.find(nsp("OrganizationFormalName", wqx_ns)))
def __init__(self, element, wqx_ns): self._root = element self.id = testXMLValue( self._root.find(nsp("OrganizationIdentifier", wqx_ns)) ) self.name = testXMLValue( self._root.find(nsp("OrganizationFormalName", wqx_ns)) )
def __init__(self, **kwargs): super(SweTimeSeries,self).__init__(**kwargs) # Parse out GML point. Defaults to 0 depth if none specified self.geo_srs = Crs(testXMLAttribute(self._location.find(nsp("Point", self.GML_NS)), 'srsName')) geo = [float(v) for v in testXMLValue(self._location.find(nsp("Point/pos", self.GML_NS))).split(" ")] if self.geo_srs.axisorder == "yx": self.geo = sPoint(geo[1], geo[0]) else: self.geo = sPoint(geo[0], geo[1]) try: self.geo.z = geo[2] except: pass pc = PointCollection() for row in self.results.data: p = Point() time = None z = None lat = None lon = None for field in row: if field.axis == "time": t = dateutil.parser.parse(field.value) p.time = t.astimezone(dateutil.tz.tzutc()) elif field.axis == "Long": lon = field elif field.axis == "Lat": lat = field elif field.axis == "h": z = field else: m = Member(value=field.value, unit=field.units, units_definition=field.units_url, name=field.name, definition=field.definition, standard=field.definition) p.add_member(m) # Set the spatial point if lon.srs != lat.srs: raise ValueError("Longitude and Latitude need to have the same SRS/CRS!") p.location = sPoint(float(lon.value), float(lat.value), float(z.value)) pc.add_element(p) self.data = pc
def __init__(self, element, swe_ns): self._root = element self._data_choices = {} for item in self._root.findall(nsp("item", swe_ns)): name = testXMLAttribute(item, "name") self._data_choices[name] = [] for child in item.find(nsp("DataRecord", swe_ns)): # Create an array of possible columns x = get_field_object(child, swe_ns) if x is not None: self._data_choices[name].append(x)
def __init__(self, element, swe_ns): self._root = element # Gets whatever the first child is. # swe:Quantity = value ob = self._root[0] self.name = testXMLAttribute(self._root, "name") self.definition = testXMLAttribute(ob, "definition") self.units = testXMLAttribute(ob.find(nsp("uom", swe_ns)), "code") self.units_url = testXMLAttribute(ob.find(nsp("uom", swe_ns)), nspv("xlink:href")) self.value = testXMLValue(ob.find(nsp("value", swe_ns))) self.axis = testXMLAttribute(ob, "axisID")
def __init__(self, element, wqx_ns): self._root = element self.description = WqxOrganizationDescription(self._root.find(nsp("OrganizationDescription", wqx_ns)), wqx_ns) self.locations = [] mls = self._root.findall(nsp("MonitoringLocation", wqx_ns)) for loc in mls: if loc is not None: self.locations.append(WqxMonitoringLocation(loc, wqx_ns)) self.activities = [] for act in self._root.findall(nsp("Activity", wqx_ns)): self.activities.append(WqxActivity(act, wqx_ns))
def __init__(self, element, swe_ns): self._root = element self.swe_ns = swe_ns self.fields = [] encoding = SweEncoding(self._root.find(nsp("*/encoding", self.swe_ns)), self.swe_ns) csv = SweValues(self._root.find(nsp("*/values", self.swe_ns)), encoding).csv self.data = self.parse_fields_and_csv(csv) for child in self._root.find(nsp("DataStream", self.swe_ns)): # Create an array of possible columns x = get_field_object(child, self.swe_ns) if x is not None: self.fields.append(x)
def __init__(self, element, wqx_ns): self._root = element self.description = WqxOrganizationDescription(self._root.find(nsp("OrganizationDescription",wqx_ns)), wqx_ns) self.locations = [] mls = self._root.findall(nsp("MonitoringLocation",wqx_ns)) for loc in mls: if loc is not None: self.locations.append(WqxMonitoringLocation(loc, wqx_ns)) self.activities = [] for act in self._root.findall(nsp("Activity", wqx_ns)): self.activities.append(WqxActivity(act, wqx_ns))
def __init__(self, element, swe_ns): self._root = element self._fields = [] self.definition = testXMLAttribute(self._root, "definition") self.srs = testXMLAttribute(self._root, "referenceFrame") for coord in self._root.findall(nsp("coordinate", swe_ns)): self._fields.append(SweCoordinate(coord, swe_ns, self.srs, self.definition))
def get_field_object(element, swe_ns): field_tag = nsp("field", swe_ns) data_choice_tag = nsp("DataChoice", swe_ns) if element.tag == field_tag: name = testXMLAttribute(element, "name") if name == "location": return SweVector(element.find(nsp("Vector", swe_ns)), swe_ns) elif name == "time": return SweTime(element.find(nsp("Time", swe_ns)), swe_ns) else: return SweField(element, swe_ns) elif element.tag == data_choice_tag: return SweDataChoice(element, swe_ns) else: return None
def __init__(self, element, swe_ns): self._root = element self._fields = [] self.definition = testXMLAttribute(self._root, "definition") self.srs = testXMLAttribute(self._root, "referenceFrame") for coord in self._root.findall(nsp("coordinate", swe_ns)): self._fields.append( SweCoordinate(coord, swe_ns, self.srs, self.definition))
def __init__(self, **kwargs): self.GML_NS = kwargs.pop('GML_NS') self.OM_NS = kwargs.pop('OM_NS') self.SWE_NS = kwargs.pop('SWE_NS') self._foi = kwargs.pop('feature_of_interest') self._result = kwargs.pop('result') self._location = self._foi.find(nsp("FeatureCollection/location", self.GML_NS)) self.results = OmResult(self._result, self.SWE_NS)
def __init__(self, **kwargs): self.GML_NS = kwargs.pop('GML_NS') self.OM_NS = kwargs.pop('OM_NS') self.SWE_NS = kwargs.pop('SWE_NS') self._foi = kwargs.pop('feature_of_interest') self._result = kwargs.pop('result') self._location = self._foi.find( nsp("FeatureCollection/location", self.GML_NS)) self.results = OmResult(self._result, self.SWE_NS)
def __init__(self, element, swe_ns): self._root = element # Only supporting Text Encoding tx = self._root.find(nsp("TextEncoding", swe_ns)) if tx is not None: self.type = "text" self.decimal_separator = testXMLAttribute(tx,'decimalSeparator') or "." self.token_separator = testXMLAttribute(tx,'tokenSeparator') or "," self.block_separator = testXMLAttribute(tx,'blockSeparator') # ignored, we use newlines else: raise TypeError("Only swe:TextEncoding is supported at this time")
def __init__(self, element): if isinstance(element, str): self._root = etree.fromstring(element) else: self._root = element if hasattr(self._root, 'getroot'): self._root = self._root.getroot() # Get individual om:Observations self.observations = {} for ob in self._root.findall(nsp("member/Observation", ns.get_versioned_namespace('om','1.0'))): ob_ele = OmObservation(ob) self.observations[ob_ele.name] = ob_ele
def __init__(self, element, swe_ns): self._root = element # Only supporting Text Encoding tx = self._root.find(nsp("TextEncoding", swe_ns)) if tx is not None: self.type = "text" self.decimal_separator = testXMLAttribute( tx, 'decimalSeparator') or "." self.token_separator = testXMLAttribute(tx, 'tokenSeparator') or "," self.block_separator = testXMLAttribute( tx, 'blockSeparator') # ignored, we use newlines else: raise TypeError("Only swe:TextEncoding is supported at this time")
def __init__(self, element): if isinstance(element, str): self._root = etree.fromstring(element) else: self._root = element if hasattr(self._root, 'getroot'): self._root = self._root.getroot() # Get individual om:Observations self.observations = {} for ob in self._root.findall( nsp("member/Observation", ns.get_versioned_namespace('om', '1.0'))): ob_ele = OmObservation(ob) self.observations[ob_ele.name] = ob_ele
def __init__(self, element): wqx_ns = "http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" if isinstance(element, text_type): try: self._root = etree.fromstring(element) except ValueError: # Strip out the XML header due to UTF8 encoding declaration self._root = etree.fromstring(element[38:]) else: self._root = element if hasattr(self._root, "getroot"): self._root = self._root.getroot() self.failed = False self.organizations = [] orgs = self._root.findall(nsp("Organization", wqx_ns)) if orgs is None: self.failed = True else: for org in orgs: self.organizations.append(WqxOrganization(org, wqx_ns))
def __init__(self, element, wqx_ns): self._root = element des = self._root.find(nsp("ResultDescription", wqx_ns)) self.name = None self.short_name = None self.status = None self.stastistical_base_code = None self.value_type = None self.weight_basis = None self.time_basis = None self.temperature_basis = None if des is not None: self.name = testXMLValue( des.find(nsp("CharacteristicName", wqx_ns)) ) self.short_name = testXMLValue( des.find(nsp("ResultSampleFractionText", wqx_ns)) ) self.status = testXMLValue( des.find(nsp("ResultStatusIdentifier", wqx_ns)) ) self.stastistical_base_code = testXMLValue( des.find(nsp("StatisticalBaseCode", wqx_ns)) ) self.value_type = testXMLValue( des.find(nsp("ResultValueTypeName", wqx_ns)) ) self.weight_basis = testXMLValue( des.find(nsp("ResultWeightBasisText", wqx_ns)) ) self.time_basis = testXMLValue( des.find(nsp("ResultTimeBasisText", wqx_ns)) ) self.temperature_basis = testXMLValue( des.find(nsp("ResultTemperatureBasisText", wqx_ns)) ) rm = des.find(nsp("ResultMeasure", wqx_ns)) self.value = None self.units = None if rm is not None: self.value = testXMLValue( rm.find(nsp("ResultMeasureValue", wqx_ns)) ) self.units = testXMLValue(rm.find(nsp("MeasureUnitCode", wqx_ns))) qu = des.find(nsp("DataQuality", wqx_ns)) self.quality = None if qu is not None: self.quality = testXMLValue(qu.find(nsp("PrecisionValue", wqx_ns))) am = self._root.find(nsp("ResultAnalyticalMethod", wqx_ns)) self.analytical_method_id = None self.analytical_method_id_context = None if am is not None: self.analytical_method_id = testXMLValue( am.find(nsp("MethodIdentifier", wqx_ns)) ) self.analytical_method_id_context = testXMLValue( am.find(nsp("MethodIdentifierContext", wqx_ns)) )
def __init__(self, element, wqx_ns): self._root = element des = self._root.find(nsp("ActivityDescription", wqx_ns)) if des is not None: self.id = testXMLValue(des.find(nsp("ActivityIdentifier", wqx_ns))) self.type = testXMLValue(des.find(nsp("ActivityTypeCode", wqx_ns))) self.media = testXMLValue( des.find(nsp("ActivityMediaName", wqx_ns)) ) # Date/Time sd = testXMLValue( des.find(nsp("ActivityStartDate", wqx_ns)) ) # YYYY-MM-DD parse_string = "%s" % sd st = des.find(nsp("ActivityStartTime", wqx_ns)) # If no time is defined, skip trying to pull it out and just use the date if st is not None: t = testXMLValue(st.find(nsp("Time", wqx_ns))) tz = testXMLValue(st.find(nsp("TimeZoneCode", wqx_ns))) parse_string = "%s %s" % (parse_string, t) if tz is not None: parse_string = "%s %s" % (parse_string, tz) self.start_time = AsaTime.parse(parse_string) if self.start_time.tzinfo is None: self.start_time = self.start_time.replace(tzinfo=pytz.utc) self.project = testXMLValue(des.find(nsp("ProjectIdentifier", wqx_ns))) self.location_id = testXMLValue( des.find(nsp("MonitoringLocationIdentifier", wqx_ns)) ) self.comment = testXMLValue( des.find(nsp("ActivityCommentText", wqx_ns)) ) self.method_id = None self.method_name = None self.method_context = None # Method smpl = self._root.find(nsp("SampleDescription", wqx_ns)) if smpl is not None: self.sample_collection_equipment_name = testXMLValue( smpl.find(nsp("SampleCollectionEquipmentName", wqx_ns)) ) smplcol = smpl.find(nsp("SampleCollectionMethod", wqx_ns)) if smplcol is not None: self.method_id = testXMLValue( smplcol.find(nsp("MethodIdentifier", wqx_ns)) ) self.method_context = testXMLValue( smplcol.find(nsp("MethodIdentifierContext", wqx_ns)) ) self.method_name = testXMLValue( smplcol.find(nsp("MethodName", wqx_ns)) ) self.results = [] for res in self._root.findall(nsp("Result", wqx_ns)): self.results.append(WqxResult(res, wqx_ns))
def __init__(self, element): self._root = element OM_NS = ns.get_versioned_namespace('om', '1.0') GML_NS = ns.get_versioned_namespace('gml', '3.1.1') SWE_NS = ns.get_versioned_namespace('swe', '1.0') self.name = testXMLValue(self._root.find(nsp("name", GML_NS))) self.description = testXMLValue( self._root.find(nsp("description", GML_NS))) self.observedProperties = [] for op in self._root.findall(nsp('observedProperty', OM_NS)): self.observedProperties.append( testXMLAttribute(op, nspv('xlink:href'))) # BBOX try: envelope = self._root.find(nsp('boundedBy/Envelope', GML_NS)) lower_left_corner = testXMLValue( envelope.find(nsp('lowerCorner', GML_NS))).split(" ") upper_right_corner = testXMLValue( envelope.find(nsp('upperCorner', GML_NS))).split(" ") self.bbox_srs = Crs(testXMLAttribute(envelope, 'srsName')) # Always keep the BBOX as minx, miny, maxx, maxy if self.bbox_srs.axisorder == "yx": self.bbox = box(float(lower_left_corner[1]), float(lower_left_corner[0]), float(upper_right_corner[1]), float(upper_right_corner[0])) else: self.bbox = box(float(lower_left_corner[0]), float(lower_left_corner[1]), float(upper_right_corner[0]), float(upper_right_corner[1])) except Exception: self.bbox = None self.bbox_srs = None # Time range fp = nsp('samplingTime', OM_NS) mp = nsp('TimePeriod', GML_NS) lp = nsp('beginPosition', GML_NS) begin_position_element = self._root.find('%s/%s/%s' % (fp, mp, lp)) self.begin_position = extract_time(begin_position_element) ep = nsp('endPosition', GML_NS) end_position_element = self._root.find('%s/%s/%s' % (fp, mp, ep)) self.end_position = extract_time(end_position_element) feature_of_interest_element = self._root.find( nsp("featureOfInterest", OM_NS)) self.feature_type = testXMLValue( feature_of_interest_element.find( nsp("FeatureCollection/metaDataProperty/name", GML_NS))) # Now the fields change depending on the FeatureType result_element = self._root.find(nsp("result", OM_NS)) #TODO: This should be implemented as a Factory self.feature = None if self.feature_type == 'timeSeries': self.feature = SweTimeSeries( feature_of_interest=feature_of_interest_element, result=result_element, GML_NS=GML_NS, OM_NS=OM_NS, SWE_NS=SWE_NS) elif self.feature_type == 'trajectoryProfile': self.feature = SweTrajectoryProfile( feature_of_interest=feature_of_interest_element, result=result_element, GML_NS=GML_NS, OM_NS=OM_NS, SWE_NS=SWE_NS) elif self.feature_type == 'timeSeriesProfile': self.feature = SweTimeseriesProfile( feature_of_interest=feature_of_interest_element, result=result_element, GML_NS=GML_NS, OM_NS=OM_NS, SWE_NS=SWE_NS)
def __init__(self, **kwargs): super(SweTimeSeries, self).__init__(**kwargs) # Parse out GML point. Defaults to 0 depth if none specified self.geo_srs = Crs( testXMLAttribute(self._location.find(nsp("Point", self.GML_NS)), 'srsName')) geo = [ float(v) for v in testXMLValue( self._location.find(nsp("Point/pos", self.GML_NS))).split(" ") ] if self.geo_srs.axisorder == "yx": self.geo = sPoint(geo[1], geo[0]) else: self.geo = sPoint(geo[0], geo[1]) try: self.geo.z = geo[2] except: pass pc = PointCollection() for row in self.results.data: p = Point() time = None z = None lat = None lon = None for field in row: if field.axis == "time": t = dateutil.parser.parse(field.value) p.time = t.astimezone(dateutil.tz.tzutc()) elif field.axis == "Long": lon = field elif field.axis == "Lat": lat = field elif field.axis == "h": z = field else: m = Member(value=field.value, unit=field.units, units_definition=field.units_url, name=field.name, definition=field.definition, standard=field.definition) p.add_member(m) # Set the spatial point if lon.srs != lat.srs: raise ValueError( "Longitude and Latitude need to have the same SRS/CRS!") p.location = sPoint(float(lon.value), float(lat.value), float(z.value)) pc.add_element(p) self.data = pc
def __init__(self, element): self._root = element OM_NS = ns.get_versioned_namespace('om','1.0') GML_NS = ns.get_versioned_namespace('gml','3.1.1') SWE_NS = ns.get_versioned_namespace('swe','1.0') XLINK_NS = ns.get_namespace("xlink") self.name = testXMLValue(self._root.find(nsp("name", GML_NS))) self.description = testXMLValue(self._root.find(nsp("description", GML_NS))) self.observedProperties = [] for op in self._root.findall(nsp('observedProperty', OM_NS)): self.observedProperties.append(testXMLAttribute(op,nsp('href', XLINK_NS))) # BBOX try: envelope = self._root.find(nsp('boundedBy/Envelope', GML_NS)) lower_left_corner = testXMLValue(envelope.find(nsp('lowerCorner', GML_NS))).split(" ") upper_right_corner = testXMLValue(envelope.find(nsp('upperCorner', GML_NS))).split(" ") self.bbox_srs = Crs(testXMLAttribute(envelope,'srsName')) # Always keep the BBOX as minx, miny, maxx, maxy if self.bbox_srs.axisorder == "yx": self.bbox = box(float(lower_left_corner[1]), float(lower_left_corner[0]), float(upper_right_corner[1]), float(upper_right_corner[0])) else: self.bbox = box(float(lower_left_corner[0]), float(lower_left_corner[1]), float(upper_right_corner[0]), float(upper_right_corner[1])) except Exception: self.bbox = None self.bbox_srs = None # Time range fp = nsp('samplingTime', OM_NS) mp = nsp('TimePeriod', GML_NS) lp = nsp('beginPosition', GML_NS) begin_position_element = self._root.find('%s/%s/%s' % (fp, mp, lp)) self.begin_position = extract_time(begin_position_element) ep = nsp('endPosition', GML_NS) end_position_element = self._root.find('%s/%s/%s' % (fp, mp, ep)) self.end_position = extract_time(end_position_element) feature_of_interest_element = self._root.find(nsp("featureOfInterest", OM_NS)) self.feature_type = testXMLValue(feature_of_interest_element.find(nsp("FeatureCollection/metaDataProperty/name", GML_NS))) # Now the fields change depending on the FeatureType result_element = self._root.find(nsp("result", OM_NS)) #TODO: This should be implemented as a Factory self.feature = None if self.feature_type == 'timeSeries': self.feature = SweTimeSeries(feature_of_interest=feature_of_interest_element, result=result_element, GML_NS=GML_NS, OM_NS=OM_NS, SWE_NS=SWE_NS) elif self.feature_type == 'trajectoryProfile': self.feature = SweTrajectoryProfile(feature_of_interest=feature_of_interest_element, result=result_element, GML_NS=GML_NS, OM_NS=OM_NS, SWE_NS=SWE_NS) elif self.feature_type == 'timeSeriesProfile': self.feature = SweTimeseriesProfile(feature_of_interest=feature_of_interest_element, result=result_element, GML_NS=GML_NS, OM_NS=OM_NS, SWE_NS=SWE_NS)
def __init__(self, element, wqx_ns): self._root = element self.id = None self.name = None self.type = None self.description = None self.huc = None identity = self._root.find(nsp("MonitoringLocationIdentity", wqx_ns)) if identity is not None: self.id = testXMLValue( identity.find(nsp("MonitoringLocationIdentifier", wqx_ns))) self.name = testXMLValue( identity.find(nsp("MonitoringLocationName", wqx_ns))) self.type = testXMLValue( identity.find(nsp("MonitoringLocationTypeName", wqx_ns))) self.description = testXMLValue( identity.find(nsp("MonitoringLocationDescriptionText", wqx_ns))) self.huc = testXMLValue( identity.find(nsp("HUCEightDigitCode", wqx_ns))) self.latitude = None self.longitude = None self.map_scale = None self.horizontal_collection_method = None self.horizontal_crs_name = None self.horizontal_crs = None self.vertical_crs_name = None self.vertical_crs = None geo = self._root.find(nsp("MonitoringLocationGeospatial", wqx_ns)) if geo is not None: self.latitude = testXMLValue( geo.find(nsp("LatitudeMeasure", wqx_ns))) self.longitude = testXMLValue( geo.find(nsp("LongitudeMeasure", wqx_ns))) self.map_scale = testXMLValue( geo.find(nsp("SourceMapScaleNumeric", wqx_ns))) self.horizontal_collection_method = testXMLValue( geo.find(nsp("HorizontalCollectionMethodName", wqx_ns))) self.horizontal_crs_name = testXMLValue( geo.find( nsp("HorizontalCoordinateReferenceSystemDatumName", wqx_ns))) # self.horizontal_crs = Crs("EPSG:" + testXMLValue(geo.find(nsp("HorizontalCoordinateReferenceSystemDatumName", wqx_ns)))) self.vertical_crs_name = testXMLValue( geo.find(nsp("VerticalCollectionMethodName", wqx_ns))) # self.vertical_crs = Crs(testXMLValue("EPSG:" + geo.find(nsp("VerticalCoordinateReferenceSystemDatumName", wqx_ns)))) self.vertical_measure_value = None self.vertical_measure_units = None vm = geo.find(nsp("VerticalMeasure", wqx_ns)) if vm is not None: self.vertical_measure_value = testXMLValue( vm.find(nsp("MeasureValue", wqx_ns))) self.vertical_measure_units = testXMLValue( vm.find(nsp("MeasureUnitCode", wqx_ns))) self.country = testXMLValue(geo.find(nsp("CountryCode", wqx_ns))) self.state = testXMLValue(geo.find(nsp("StateCode", wqx_ns))) self.county = testXMLValue(geo.find(nsp("CountyCode", wqx_ns)))
def __init__(self, element, wqx_ns): self._root = element des = self._root.find(nsp("ResultDescription", wqx_ns)) self.name = None self.short_name = None self.status = None self.stastistical_base_code = None self.value_type = None self.weight_basis = None self.time_basis = None self.temperature_basis = None if des is not None: self.name = testXMLValue( des.find(nsp("CharacteristicName", wqx_ns))) self.short_name = testXMLValue( des.find(nsp("ResultSampleFractionText", wqx_ns))) self.status = testXMLValue( des.find(nsp("ResultStatusIdentifier", wqx_ns))) self.stastistical_base_code = testXMLValue( des.find(nsp("StatisticalBaseCode", wqx_ns))) self.value_type = testXMLValue( des.find(nsp("ResultValueTypeName", wqx_ns))) self.weight_basis = testXMLValue( des.find(nsp("ResultWeightBasisText", wqx_ns))) self.time_basis = testXMLValue( des.find(nsp("ResultTimeBasisText", wqx_ns))) self.temperature_basis = testXMLValue( des.find(nsp("ResultTemperatureBasisText", wqx_ns))) rm = des.find(nsp("ResultMeasure", wqx_ns)) self.value = None self.units = None if rm is not None: self.value = testXMLValue( rm.find(nsp("ResultMeasureValue", wqx_ns))) self.units = testXMLValue(rm.find(nsp("MeasureUnitCode", wqx_ns))) qu = des.find(nsp("DataQuality", wqx_ns)) self.quality = None if qu is not None: self.quality = testXMLValue(qu.find(nsp("PrecisionValue", wqx_ns))) am = self._root.find(nsp("ResultAnalyticalMethod", wqx_ns)) self.analytical_method_id = None self.analytical_method_id_context = None if am is not None: self.analytical_method_id = testXMLValue( am.find(nsp("MethodIdentifier", wqx_ns))) self.analytical_method_id_context = testXMLValue( am.find(nsp("MethodIdentifierContext", wqx_ns)))
def __init__(self, element, wqx_ns): self._root = element self.id = None self.name = None self.type = None self.description = None self.huc = None identity = self._root.find(nsp("MonitoringLocationIdentity", wqx_ns)) if identity is not None: self.id = testXMLValue( identity.find(nsp("MonitoringLocationIdentifier", wqx_ns)) ) self.name = testXMLValue( identity.find(nsp("MonitoringLocationName", wqx_ns)) ) self.type = testXMLValue( identity.find(nsp("MonitoringLocationTypeName", wqx_ns)) ) self.description = testXMLValue( identity.find(nsp("MonitoringLocationDescriptionText", wqx_ns)) ) self.huc = testXMLValue( identity.find(nsp("HUCEightDigitCode", wqx_ns)) ) self.latitude = None self.longitude = None self.map_scale = None self.horizontal_collection_method = None self.horizontal_crs_name = None self.horizontal_crs = None self.vertical_crs_name = None self.vertical_crs = None geo = self._root.find(nsp("MonitoringLocationGeospatial", wqx_ns)) if geo is not None: self.latitude = testXMLValue( geo.find(nsp("LatitudeMeasure", wqx_ns)) ) self.longitude = testXMLValue( geo.find(nsp("LongitudeMeasure", wqx_ns)) ) self.map_scale = testXMLValue( geo.find(nsp("SourceMapScaleNumeric", wqx_ns)) ) self.horizontal_collection_method = testXMLValue( geo.find(nsp("HorizontalCollectionMethodName", wqx_ns)) ) self.horizontal_crs_name = testXMLValue( geo.find( nsp("HorizontalCoordinateReferenceSystemDatumName", wqx_ns) ) ) # self.horizontal_crs = Crs("EPSG:" + testXMLValue(geo.find(nsp("HorizontalCoordinateReferenceSystemDatumName", wqx_ns)))) self.vertical_crs_name = testXMLValue( geo.find(nsp("VerticalCollectionMethodName", wqx_ns)) ) # self.vertical_crs = Crs(testXMLValue("EPSG:" + geo.find(nsp("VerticalCoordinateReferenceSystemDatumName", wqx_ns)))) self.vertical_measure_value = None self.vertical_measure_units = None vm = geo.find(nsp("VerticalMeasure", wqx_ns)) if vm is not None: self.vertical_measure_value = testXMLValue( vm.find(nsp("MeasureValue", wqx_ns)) ) self.vertical_measure_units = testXMLValue( vm.find(nsp("MeasureUnitCode", wqx_ns)) ) self.country = testXMLValue(geo.find(nsp("CountryCode", wqx_ns))) self.state = testXMLValue(geo.find(nsp("StateCode", wqx_ns))) self.county = testXMLValue(geo.find(nsp("CountyCode", wqx_ns)))
def __init__(self, element, wqx_ns): self._root = element des = self._root.find(nsp("ActivityDescription", wqx_ns)) if des is not None: self.id = testXMLValue(des.find(nsp("ActivityIdentifier", wqx_ns))) self.type = testXMLValue(des.find(nsp("ActivityTypeCode", wqx_ns))) self.media = testXMLValue( des.find(nsp("ActivityMediaName", wqx_ns))) # Date/Time sd = testXMLValue(des.find(nsp("ActivityStartDate", wqx_ns))) # YYYY-MM-DD parse_string = "%s" % sd st = des.find(nsp("ActivityStartTime", wqx_ns)) # If no time is defined, skip trying to pull it out and just use the date if st is not None: t = testXMLValue(st.find(nsp("Time", wqx_ns))) tz = testXMLValue(st.find(nsp("TimeZoneCode", wqx_ns))) parse_string = "%s %s" % (parse_string, t) if tz is not None: parse_string = "%s %s" % (parse_string, tz) self.start_time = AsaTime.parse(parse_string) if self.start_time.tzinfo is None: self.start_time = self.start_time.replace(tzinfo=pytz.utc) self.project = testXMLValue(des.find(nsp("ProjectIdentifier", wqx_ns))) self.location_id = testXMLValue( des.find(nsp("MonitoringLocationIdentifier", wqx_ns))) self.comment = testXMLValue( des.find(nsp("ActivityCommentText", wqx_ns))) self.method_id = None self.method_name = None self.method_context = None # Method smpl = self._root.find(nsp("SampleDescription", wqx_ns)) if smpl is not None: self.sample_collection_equipment_name = testXMLValue( smpl.find(nsp("SampleCollectionEquipmentName", wqx_ns))) smplcol = smpl.find(nsp("SampleCollectionMethod", wqx_ns)) if smplcol is not None: self.method_id = testXMLValue( smplcol.find(nsp("MethodIdentifier", wqx_ns))) self.method_context = testXMLValue( smplcol.find(nsp("MethodIdentifierContext", wqx_ns))) self.method_name = testXMLValue( smplcol.find(nsp("MethodName", wqx_ns))) self.results = [] for res in self._root.findall(nsp("Result", wqx_ns)): self.results.append(WqxResult(res, wqx_ns))