Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
val = util.getqattr(result, queryables['dif:Data_Presentation_Form']['dbcol'])
etree.SubElement(citation, util.nspath_eval('dif:Data_Presentation_Form', self.namespaces)).text = val
# iso topic category
val = util.getqattr(result, queryables['dif:ISO_Topic_Category']['dbcol'])
etree.SubElement(node, util.nspath_eval('dif:ISO_Topic_Category', self.namespaces)).text = val
# keywords
val = util.getqattr(result, queryables['dif:Keyword']['dbcol'])
if val:
for kw in val.split(','):
etree.SubElement(node, util.nspath_eval('dif:Keyword', self.namespaces)).text = kw
# temporal
temporal = etree.SubElement(node, util.nspath_eval('dif:Temporal_Coverage', self.namespaces))
val = util.getqattr(result, queryables['dif:Start_Date']['dbcol'])
val2 = util.getqattr(result, queryables['dif:Stop_Date']['dbcol'])
etree.SubElement(temporal, util.nspath_eval('dif:Start_Date', self.namespaces)).text = val
etree.SubElement(temporal, util.nspath_eval('dif:End_Date', self.namespaces)).text = val2
# bbox extent
val = util.getqattr(result, queryables['dif:Spatial_Coverage']['dbcol'])
bboxel = write_extent(val, self.namespaces)
if bboxel is not None:
node.append(bboxel)
# access constraints
val = util.getqattr(result, queryables['dif:Access_Constraints']['dbcol'])
etree.SubElement(node, util.nspath_eval('dif:Access_Constraints', self.namespaces)).text = val
# language
def write_extent(bbox, nsmap):
''' Generate BBOX extent '''
from shapely.wkt import loads
if bbox is not None:
if bbox.find('SRID') != -1: # it's EWKT; chop off 'SRID=\d+;'
bbox2 = loads(bbox.split(';')[-1])
else:
bbox2 = loads(bbox)
where = etree.Element(util.nspath_eval('georss:where', nsmap))
polygon = etree.SubElement(where, util.nspath_eval('gml:Polygon', nsmap), srsName='urn:x-ogc:def:crs:EPSG:6.11:4326')
exterior = etree.SubElement(polygon, util.nspath_eval('gml:exterior', nsmap))
lring = etree.SubElement(exterior, util.nspath_eval('gml:LinearRing', nsmap))
poslist = etree.SubElement(lring, util.nspath_eval('gml:posList', nsmap)).text = \
' '.join(['%s %s' % (str(i[1]), str(i[0])) for i in list(bbox2.exterior.coords)])
return where
return None
def _get_envelope(self):
"""Parse gml:Envelope"""
tmp = self._exml.find(util.nspath_eval('gml:Envelope/gml:lowerCorner',
self.nsmap))
if tmp is None:
raise RuntimeError('Invalid gml:Envelope geometry.\
Missing gml:lowerCorner')
else:
lower_left = tmp.text
tmp = self._exml.find(util.nspath_eval('gml:Envelope/gml:upperCorner',
self.nsmap))
if tmp is None:
raise RuntimeError('Invalid gml:Envelope geometry.\
Missing gml:upperCorner')
else:
upper_right = tmp.text
llmin = lower_left.split()
def write_extent(bbox, nsmap):
''' Generate BBOX extent '''
from shapely.wkt import loads
if bbox is not None:
if bbox.find('SRID') != -1: # it's EWKT; chop off 'SRID=\d+;'
bbox2 = loads(bbox.split(';')[-1])
else:
bbox2 = loads(bbox)
where = etree.Element(util.nspath_eval('georss:where', nsmap))
polygon = etree.SubElement(where, util.nspath_eval('gml:Polygon', nsmap), srsName='urn:x-ogc:def:crs:EPSG:6.11:4326')
exterior = etree.SubElement(polygon, util.nspath_eval('gml:exterior', nsmap))
lring = etree.SubElement(exterior, util.nspath_eval('gml:LinearRing', nsmap))
poslist = etree.SubElement(lring, util.nspath_eval('gml:posList', nsmap)).text = \
' '.join(['%s %s' % (str(i[1]), str(i[0])) for i in list(bbox2.exterior.coords)])
return where
return None
# creator
val = util.getqattr(result, queryables['dif:Dataset_Creator']['dbcol'])
etree.SubElement(citation, util.nspath_eval('dif:Dataset_Creator', self.namespaces)).text = val
# date
val = util.getqattr(result, queryables['dif:Dataset_Release_Date']['dbcol'])
etree.SubElement(citation, util.nspath_eval('dif:Dataset_Release_Date', self.namespaces)).text = val
# publisher
val = util.getqattr(result, queryables['dif:Dataset_Publisher']['dbcol'])
etree.SubElement(citation, util.nspath_eval('dif:Dataset_Publisher', self.namespaces)).text = val
# format
val = util.getqattr(result, queryables['dif:Data_Presentation_Form']['dbcol'])
etree.SubElement(citation, util.nspath_eval('dif:Data_Presentation_Form', self.namespaces)).text = val
# iso topic category
val = util.getqattr(result, queryables['dif:ISO_Topic_Category']['dbcol'])
etree.SubElement(node, util.nspath_eval('dif:ISO_Topic_Category', self.namespaces)).text = val
# keywords
val = util.getqattr(result, queryables['dif:Keyword']['dbcol'])
if val:
for kw in val.split(','):
etree.SubElement(node, util.nspath_eval('dif:Keyword', self.namespaces)).text = kw
# temporal
temporal = etree.SubElement(node, util.nspath_eval('dif:Temporal_Coverage', self.namespaces))
val = util.getqattr(result, queryables['dif:Start_Date']['dbcol'])
val2 = util.getqattr(result, queryables['dif:Stop_Date']['dbcol'])
def write_extent(bbox, nsmap):
''' Generate BBOX extent '''
from shapely.wkt import loads
if bbox is not None:
if bbox.find('SRID') != -1: # it's EWKT; chop off 'SRID=\d+;'
bbox2 = loads(bbox.split(';')[-1])
else:
bbox2 = loads(bbox)
where = etree.Element(util.nspath_eval('georss:where', nsmap))
polygon = etree.SubElement(where, util.nspath_eval('gml:Polygon', nsmap), srsName='urn:x-ogc:def:crs:EPSG:6.11:4326')
exterior = etree.SubElement(polygon, util.nspath_eval('gml:exterior', nsmap))
lring = etree.SubElement(exterior, util.nspath_eval('gml:LinearRing', nsmap))
poslist = etree.SubElement(lring, util.nspath_eval('gml:posList', nsmap)).text = \
' '.join(['%s %s' % (str(i[1]), str(i[0])) for i in list(bbox2.exterior.coords)])
return where
return None
def write_extent(bbox, nsmap):
''' Generate BBOX extent '''
from shapely.wkt import loads
if bbox is not None:
if bbox.find('SRID') != -1: # it's EWKT; chop off 'SRID=\d+;'
bbox2 = loads(bbox.split(';')[-1]).envelope.bounds
else:
bbox2 = loads(bbox).envelope.bounds
extent = etree.Element(util.nspath_eval('dif:Spatial_Coverage', nsmap))
etree.SubElement(extent, util.nspath_eval('dif:Southernmost_Latitude', nsmap)).text = str(bbox2[1])
etree.SubElement(extent, util.nspath_eval('dif:Northernmost_Latitude', nsmap)).text = str(bbox2[3])
etree.SubElement(extent, util.nspath_eval('dif:Westernmost_Longitude', nsmap)).text = str(bbox2[0])
etree.SubElement(extent, util.nspath_eval('dif:Easternmost_Longitude', nsmap)).text = str(bbox2[2])
return extent
return None
def write_record(self, recobj, esn, outputschema, queryables):
''' Return csw:SearchResults child as lxml.etree.Element '''
typename = util.getqattr(recobj, self.context.md_core_model['mappings']['pycsw:Typename'])
if esn == 'full' and typename == 'fgdc:metadata':
# dump record as is and exit
return etree.fromstring(util.getqattr(recobj, self.context.md_core_model['mappings']['pycsw:XML']))
if typename == 'csw:Record':
# transform csw:Record -> fgdc:metadata model mappings
util.transform_mappings(queryables,
self.repository['mappings']['csw:Record'])
node = etree.Element('metadata')
node.attrib[util.nspath_eval('xsi:noNamespaceSchemaLocation', self.context.namespaces)] = \
'http://www.fgdc.gov/metadata/fgdc-std-001-1998.xsd'
idinfo = etree.SubElement(node, 'idinfo')
# identifier
etree.SubElement(idinfo, 'datasetid').text = util.getqattr(recobj, queryables['fgdc:Identifier']['dbcol'])
citation = etree.SubElement(idinfo, 'citation')
citeinfo = etree.SubElement(citation, 'citeinfo')
# title
val = util.getqattr(recobj, queryables['fgdc:Title']['dbcol'])
etree.SubElement(citeinfo, 'title').text = val
# publisher
publinfo = etree.SubElement(citeinfo, 'publinfo')
val = util.getqattr(recobj, queryables['fgdc:Publisher']['dbcol']) or ''
if tmp_list:
LOGGER.debug('Logical operator found (AND/OR)')
else:
tmp_list.append(cql)
for t in tmp_list:
filters.append(_parse_condition(t))
root = etree.Element(util.nspath_eval('ogc:Filter', namespaces))
if logical_op is not None:
root.append(logical_op)
for flt in filters:
condition = etree.Element(util.nspath_eval(flt[0], namespaces))
etree.SubElement(
condition,
util.nspath_eval('ogc:PropertyName', namespaces)).text = flt[1]
etree.SubElement(
condition,
util.nspath_eval('ogc:Literal', namespaces)).text = flt[2]
if logical_op is not None:
logical_op.append(condition)
else:
root.append(condition)
LOGGER.debug('Resulting OGC Filter: %s',
etree.tostring(root, pretty_print=1))
root = etree.Element(util.nspath_eval('ogc:Filter', namespaces))
if logical_op is not None:
root.append(logical_op)
for flt in filters:
condition = etree.Element(util.nspath_eval(flt[0], namespaces))
etree.SubElement(
condition,
util.nspath_eval('ogc:PropertyName', namespaces)).text = flt[1]
etree.SubElement(
condition,
util.nspath_eval('ogc:Literal', namespaces)).text = flt[2]
if logical_op is not None:
logical_op.append(condition)
else:
root.append(condition)
LOGGER.debug('Resulting OGC Filter: %s',
etree.tostring(root, pretty_print=1))
return root