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() urmax = upper_right.split() if len(llmin) < 2 or len(urmax) < 2: raise RuntimeError, ('Invalid gml:Envelope geometry. \ gml:lowerCorner and gml:upperCorner must hold at least x and y') if self.crs.axisorder == 'yx': self.wkt = util.bbox2wktpolygon('%s,%s,%s,%s' % (llmin[1], llmin[0], urmax[1], urmax[0])) else: self.wkt = util.bbox2wktpolygon('%s,%s,%s,%s' % (llmin[0], llmin[1], urmax[0], urmax[1]))
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() urmax = upper_right.split() if len(llmin) < 2 or len(urmax) < 2: raise RuntimeError, ('Invalid gml:Envelope geometry. \ gml:lowerCorner and gml:upperCorner must hold at least x and y') if self.crs.axisorder == 'yx': self.wkt = util.bbox2wktpolygon( '%s,%s,%s,%s' % (llmin[1], llmin[0], urmax[1], urmax[0])) else: self.wkt = util.bbox2wktpolygon( '%s,%s,%s,%s' % (llmin[0], llmin[1], urmax[0], urmax[1]))
def _get_spatial_operator(geomattr, element, dbtype, nsmap): ''' return the spatial predicate function ''' property_name = element.find(util.nspath_eval('ogc:PropertyName', nsmap)) distance = element.find(util.nspath_eval('ogc:Distance', nsmap)) distance = 'false' if distance is None else distance.text if property_name is None: raise RuntimeError, \ ('Missing ogc:PropertyName in spatial filter') if (property_name.text.find('BoundingBox') == -1 and property_name.text.find('Envelope') == -1): raise RuntimeError, \ ('Invalid ogc:PropertyName in spatial filter: %s' % property_name.text) geometry = gml.Geometry(element, nsmap) spatial_predicate = util.xmltag_split(element.tag).lower() if dbtype == 'mysql': # adjust spatial query for MySQL if spatial_predicate == 'bbox': spatial_predicate = 'intersects' if spatial_predicate == 'beyond': spatial_query = "ifnull(distance(geomfromtext(%s), \ geomfromtext('%s')) > convert(%s, signed),false)" % \ (geomattr, geometry.wkt, distance) elif spatial_predicate == 'dwithin': spatial_query = "ifnull(distance(geomfromtext(%s), \ geomfromtext('%s')) <= convert(%s, signed),false)" % \ (geomattr, geometry.wkt, distance) else: spatial_query = "ifnull(%s(geomfromtext(%s), \ geomfromtext('%s')),false)" % (spatial_predicate, geomattr, geometry.wkt) elif dbtype == 'postgresql+postgis': # adjust spatial query for PostGIS if spatial_predicate == 'bbox': spatial_predicate = 'intersects' if spatial_predicate == 'beyond': spatial_query = "not st_dwithin(st_geomfromtext(%s), \ st_geomfromtext('%s'), %f)" % (geomattr, geometry.wkt, float(distance)) elif spatial_predicate == 'dwithin': spatial_query = "st_dwithin(st_geomfromtext(%s), \ st_geomfromtext('%s'), %f)" % (geomattr, geometry.wkt, float(distance)) else: spatial_query = "st_%s(st_geomfromtext(%s), \ st_geomfromtext('%s'))" % (spatial_predicate, geomattr, geometry.wkt) else: spatial_query = "query_spatial(%s,'%s','%s','%s')" % \ (geomattr, geometry.wkt, spatial_predicate, distance) return spatial_query
def exceptionreport2diagnostic(self, element): ''' transform a CSW exception into an SRU diagnostic ''' node = etree.Element(util.nspath_eval('zs:searchRetrieveResponse', self.namespaces), nsmap=self.namespaces) etree.SubElement(node, util.nspath_eval( 'zs:version', self.namespaces)).text = self.sru_version diagnostics = etree.SubElement( node, util.nspath_eval('zs:diagnostics', self.namespaces)) diagnostic = etree.SubElement( diagnostics, util.nspath_eval('zs:diagnostic', self.namespaces)) etree.SubElement(diagnostic, util.nspath_eval('zd:diagnostic', self.namespaces)).text = \ 'info:srw/diagnostic/1/7' etree.SubElement(diagnostic, util.nspath_eval('zd:message', self.namespaces)).text = \ element.find(util.nspath_eval('ows:Exception/ows:ExceptionText', self.context.namespaces)).text etree.SubElement(diagnostic, util.nspath_eval('zd:details', self.namespaces)).text = \ element.find(util.nspath_eval('ows:Exception', self.context.namespaces)).attrib.get('exceptionCode') return node
def _get_polygon(self): ''' Parse gml:Polygon''' tmp = self._exml.find( './/%s' % util.nspath_eval('gml:posList', self.nsmap), self.nsmap) if tmp is None: raise RuntimeError, \ ('Invalid gml:LineString geometry. Missing gml:posList') else: self.wkt = 'POLYGON((%s))' % _poslist2wkt(tmp.text, axisorder)
def _get_linestring(self): ''' Parse gml:LineString''' tmp = self._exml.find(util.nspath_eval('gml:LineString/gml:posList', self.nsmap)) if tmp is None: raise RuntimeError, \ ('Invalid gml:LineString geometry. Missing gml:posList') else: self.wkt = 'LINESTRING(%s)' % _poslist2wkt(tmp.text, axisorder)
def _get_linestring(self): ''' Parse gml:LineString''' tmp = self._exml.find( util.nspath_eval('gml:LineString/gml:posList', self.nsmap)) if tmp is None: raise RuntimeError, \ ('Invalid gml:LineString geometry. Missing gml:posList') else: self.wkt = 'LINESTRING(%s)' % _poslist2wkt(tmp.text, axisorder)
def _get_polygon(self): ''' Parse gml:Polygon''' tmp = self._exml.find('.//%s' % util.nspath_eval('gml:posList', self.nsmap), self.nsmap) if tmp is None: raise RuntimeError, \ ('Invalid gml:LineString geometry. Missing gml:posList') else: self.wkt = 'POLYGON((%s))' % _poslist2wkt(tmp.text, axisorder)
def _get_point(self): ''' Parse gml:Point ''' tmp = self._exml.find(util.nspath_eval('gml:Point/gml:pos', self.nsmap)) if tmp is None: raise RuntimeError, ('Invalid gml:Point geometry. Missing gml:pos') else: xypoint = tmp.text.split() if self.crs.axisorder == 'yx': self.wkt = 'POINT(%s %s)' % (xypoint[1], xypoint[0]) else: self.wkt = 'POINT(%s %s)' % (xypoint[0], xypoint[1])
def _get_point(self): ''' Parse gml:Point ''' tmp = self._exml.find(util.nspath_eval('gml:Point/gml:pos', self.nsmap)) if tmp is None: raise RuntimeError, ( 'Invalid gml:Point geometry. Missing gml:pos') else: xypoint = tmp.text.split() if self.crs.axisorder == 'yx': self.wkt = 'POINT(%s %s)' % (xypoint[1], xypoint[0]) else: self.wkt = 'POINT(%s %s)' % (xypoint[0], xypoint[1])
def exceptionreport2diagnostic(self, element): ''' transform a CSW exception into an SRU diagnostic ''' node = etree.Element( util.nspath_eval('zs:searchRetrieveResponse', self.namespaces), nsmap=self.namespaces) etree.SubElement(node, util.nspath_eval('zs:version', self.namespaces)).text = self.sru_version diagnostics = etree.SubElement(node, util.nspath_eval('zs:diagnostics', self.namespaces)) diagnostic = etree.SubElement( diagnostics, util.nspath_eval('zs:diagnostic', self.namespaces)) etree.SubElement(diagnostic, util.nspath_eval('zd:diagnostic', self.namespaces)).text = \ 'info:srw/diagnostic/1/7' etree.SubElement(diagnostic, util.nspath_eval('zd:message', self.namespaces)).text = \ element.find(util.nspath_eval('ows:Exception/ows:ExceptionText', self.context.namespaces)).text etree.SubElement(diagnostic, util.nspath_eval('zd:details', self.namespaces)).text = \ element.find(util.nspath_eval('ows:Exception', self.context.namespaces)).attrib.get('exceptionCode') return node
def response_csw2opensearch(self, element, cfg): ''' transform a CSW response into an OpenSearch response ''' if util.xmltag_split(element.tag) == 'GetRecordsResponse': startindex = int(element.xpath('//@nextRecord')[0]) - int(element.xpath('//@numberOfRecordsReturned')[0]) if startindex < 1: startindex = 1 node = etree.Element(util.nspath_eval('atom:feed', self.context.namespaces), nsmap=self.namespaces) etree.SubElement(node, util.nspath_eval('atom:id', self.context.namespaces)).text = cfg.get('server', 'url') etree.SubElement(node, util.nspath_eval('atom:title', self.context.namespaces)).text = cfg.get('metadata:main', 'identification_title') #etree.SubElement(node, util.nspath_eval('atom:updated', self.context.namespaces)).text = element.xpath('//@timestamp')[0] etree.SubElement(node, util.nspath_eval('opensearch:totalResults', self.context.namespaces)).text = element.xpath('//@numberOfRecordsMatched')[0] etree.SubElement(node, util.nspath_eval('opensearch:startIndex', self.context.namespaces)).text = str(startindex) etree.SubElement(node, util.nspath_eval('opensearch:itemsPerPage', self.context.namespaces)).text = element.xpath('//@numberOfRecordsReturned')[0] for rec in element.xpath('//atom:entry', namespaces=self.context.namespaces): node.append(rec) return node
def parse(element, queryables, dbtype, nsmap): ''' OGC Filter object support ''' boq = None tmp = element.xpath('ogc:And|ogc:Or|ogc:Not', namespaces=nsmap) if len(tmp) > 0: # this is binary logic query boq = ' %s ' % util.xmltag_split(tmp[0].tag).lower() tmp = tmp[0] else: tmp = element queries = [] for child in tmp.xpath('child::*'): com_op = '' boolean_true = '\'true\'' boolean_false = '\'false\'' if dbtype == 'mysql': boolean_true = 'true' boolean_false = 'false' if child.tag == util.nspath_eval('ogc:Not', nsmap): queries.append("%s = %s" % (_get_spatial_operator(queryables['pycsw:BoundingBox'], child.xpath('child::*')[0], dbtype, nsmap), boolean_false)) elif child.tag in \ [util.nspath_eval('ogc:%s' % n, nsmap) for n in \ MODEL['SpatialOperators']['values']]: if boq is not None and boq == ' not ': queries.append("%s = %s" % (_get_spatial_operator(queryables['pycsw:BoundingBox'], child, dbtype, nsmap), boolean_false)) else: queries.append("%s = %s" % (_get_spatial_operator(queryables['pycsw:BoundingBox'], child, dbtype, nsmap), boolean_true)) elif child.tag == util.nspath_eval('ogc:FeatureId', nsmap): queries.append("%s = '%s'" % (queryables['pycsw:Identifier'], child.attrib.get('fid'))) else: fname = None matchcase = child.attrib.get('matchCase') wildcard = child.attrib.get('wildCard') singlechar = child.attrib.get('singleChar') if wildcard is None: wildcard = '%' if singlechar is None: singlechar = '_' if (child.xpath('child::*')[0].tag == util.nspath_eval('ogc:Function', nsmap)): if (child.xpath('child::*')[0].attrib['name'] not in MODEL['Functions'].keys()): raise RuntimeError, ('Invalid ogc:Function: %s' % (child.xpath('child::*')[0].attrib['name'])) fname = child.xpath('child::*')[0].attrib['name'] try: pname = queryables[child.find( util.nspath_eval('ogc:Function/ogc:PropertyName', nsmap)).text]['dbcol'] except Exception, err: raise RuntimeError, ('Invalid PropertyName: %s. %s' % (child.find(util.nspath_eval('ogc:Function/ogc:PropertyName', nsmap)).text, str(err))) else: try: pname = queryables[child.find( util.nspath_eval('ogc:PropertyName', nsmap)).text]['dbcol'] except Exception, err: raise RuntimeError, ('Invalid PropertyName: %s. %s' % (child.find(util.nspath_eval('ogc:PropertyName', nsmap)).text, str(err)))
def response_csw2sru(self, element, environ): ''' transform a CSW response into an SRU response ''' if util.xmltag_split(element.tag) == 'Capabilities': # explain node = etree.Element(util.nspath_eval('sru:explainResponse', self.namespaces), nsmap=self.namespaces) etree.SubElement(node, util.nspath_eval( 'sru:version', self.namespaces)).text = self.sru_version record = etree.SubElement( node, util.nspath_eval('sru:record', self.namespaces)) etree.SubElement( record, util.nspath_eval('sru:recordPacking', self.namespaces)).text = 'XML' etree.SubElement( record, util.nspath_eval('sru:recordSchema', self.namespaces) ).text = 'http://explain.z3950.org/dtd/2.1/' recorddata = etree.SubElement( record, util.nspath_eval('sru:recordData', self.namespaces)) explain = etree.SubElement( recorddata, util.nspath_eval('zr:explain', self.namespaces)) serverinfo = etree.SubElement(explain, util.nspath_eval( 'zr:serverInfo', self.namespaces), protocol='SRU', version=self.sru_version, transport='http', method='GET POST SOAP') etree.SubElement(serverinfo, util.nspath_eval( 'zr:host', self.namespaces)).text = environ.get( 'HTTP_HOST', environ["SERVER_NAME"] ) # WSGI allows for either of these etree.SubElement( serverinfo, util.nspath_eval( 'zr:port', self.namespaces)).text = environ['SERVER_PORT'] etree.SubElement(serverinfo, util.nspath_eval('zr:database', self.namespaces)).text = 'pycsw' databaseinfo = etree.SubElement( explain, util.nspath_eval('zr:databaseInfo', self.namespaces)) etree.SubElement(databaseinfo, util.nspath_eval('zr:title', self.namespaces), lang='en', primary='true').text = element.xpath( '//ows:Title', namespaces=self.context.namespaces)[0].text etree.SubElement(databaseinfo, util.nspath_eval('zr:description', self.namespaces), lang='en', primary='true').text = element.xpath( '//ows:Abstract', namespaces=self.context.namespaces)[0].text indexinfo = etree.SubElement( explain, util.nspath_eval('zr:indexInfo', self.namespaces)) etree.SubElement(indexinfo, util.nspath_eval('zr:set', self.namespaces), name='dc', identifier='info:srw/cql-context-set/1/dc-v1.1') for key, value in self.mappings['csw:Record']['index'].iteritems(): zrindex = etree.SubElement(indexinfo, util.nspath_eval( 'zr:index', self.namespaces), id=value) etree.SubElement(zrindex, util.nspath_eval('zr:title', self.namespaces)).text = key zrmap = etree.SubElement( zrindex, util.nspath_eval('zr:map', self.namespaces)) etree.SubElement(zrmap, util.nspath_eval('zr:map', self.namespaces), set='dc').text = key zrindex = etree.SubElement( indexinfo, util.nspath_eval('zr:index', self.namespaces)) zrmap = etree.SubElement( zrindex, util.nspath_eval('zr:map', self.namespaces)) etree.SubElement(zrmap, util.nspath_eval('zr:name', self.namespaces), set='dc').text = 'title222' schemainfo = etree.SubElement( explain, util.nspath_eval('zr:schemaInfo', self.namespaces)) zrschema = etree.SubElement(schemainfo, util.nspath_eval( 'zr:schema', self.namespaces), name='dc', identifier='info:srw/schema/1/dc-v1.1') etree.SubElement(zrschema, util.nspath_eval( 'zr:title', self.namespaces)).text = 'Simple Dublin Core' configinfo = etree.SubElement( explain, util.nspath_eval('zr:configInfo', self.namespaces)) etree.SubElement(configinfo, util.nspath_eval('zr:default', self.namespaces), type='numberOfRecords').text = '0' elif util.xmltag_split(element.tag) == 'GetRecordsResponse': recpos = int(element.xpath('//@nextRecord')[0]) - int( element.xpath('//@numberOfRecordsReturned')[0]) node = etree.Element(util.nspath_eval('zs:searchRetrieveResponse', self.namespaces), nsmap=self.namespaces) etree.SubElement(node, util.nspath_eval( 'zs:version', self.namespaces)).text = self.sru_version etree.SubElement( node, util.nspath_eval('zs:numberOfRecords', self.namespaces)).text = element.xpath( '//@numberOfRecordsMatched')[0] for rec in element.xpath('//csw:BriefRecord', namespaces=self.context.namespaces): record = etree.SubElement( node, util.nspath_eval('zs:record', self.namespaces)) etree.SubElement( node, util.nspath_eval( 'zs:recordSchema', self.namespaces)).text = 'info:srw/schema/1/dc-v1.1' etree.SubElement( node, util.nspath_eval('zs:recordPacking', self.namespaces)).text = 'xml' recorddata = etree.SubElement( record, util.nspath_eval('zs:recordData', self.namespaces)) rec.tag = util.nspath_eval('srw_dc:srw_dc', self.namespaces) recorddata.append(rec) etree.SubElement( record, util.nspath_eval('zs:recordPosition', self.namespaces)).text = str(recpos) recpos += 1 elif util.xmltag_split(element.tag) == 'ExceptionReport': node = self.exceptionreport2diagnostic(element) return node
def response_csw2sru(self, element, environ): ''' transform a CSW response into an SRU response ''' if util.xmltag_split(element.tag) == 'Capabilities': # explain node = etree.Element(util.nspath_eval('sru:explainResponse', self.namespaces), nsmap=self.namespaces) etree.SubElement(node, util.nspath_eval('sru:version', self.namespaces)).text = self.sru_version record = etree.SubElement(node, util.nspath_eval('sru:record', self.namespaces)) etree.SubElement(record, util.nspath_eval('sru:recordPacking', self.namespaces)).text = 'XML' etree.SubElement(record, util.nspath_eval('sru:recordSchema', self.namespaces)).text = 'http://explain.z3950.org/dtd/2.1/' recorddata = etree.SubElement(record, util.nspath_eval('sru:recordData', self.namespaces)) explain = etree.SubElement(recorddata, util.nspath_eval('zr:explain', self.namespaces)) serverinfo = etree.SubElement(explain, util.nspath_eval('zr:serverInfo', self.namespaces), protocol='SRU', version=self.sru_version, transport='http', method='GET POST SOAP') etree.SubElement(serverinfo, util.nspath_eval('zr:host', self.namespaces)).text = environ.get('HTTP_HOST', environ["SERVER_NAME"]) # WSGI allows for either of these etree.SubElement(serverinfo, util.nspath_eval('zr:port', self.namespaces)).text = environ['SERVER_PORT'] etree.SubElement(serverinfo, util.nspath_eval('zr:database', self.namespaces)).text = 'pycsw' databaseinfo = etree.SubElement(explain, util.nspath_eval('zr:databaseInfo', self.namespaces)) etree.SubElement(databaseinfo, util.nspath_eval('zr:title', self.namespaces), lang='en', primary='true').text = element.xpath('//ows:Title', namespaces=self.context.namespaces)[0].text etree.SubElement(databaseinfo, util.nspath_eval('zr:description', self.namespaces), lang='en', primary='true').text = element.xpath('//ows:Abstract', namespaces=self.context.namespaces)[0].text indexinfo = etree.SubElement(explain, util.nspath_eval('zr:indexInfo', self.namespaces)) etree.SubElement(indexinfo, util.nspath_eval('zr:set', self.namespaces), name='dc', identifier='info:srw/cql-context-set/1/dc-v1.1') for key, value in self.mappings['csw:Record']['index'].iteritems(): zrindex = etree.SubElement(indexinfo, util.nspath_eval('zr:index', self.namespaces), id=value) etree.SubElement(zrindex, util.nspath_eval('zr:title', self.namespaces)).text = key zrmap = etree.SubElement(zrindex, util.nspath_eval('zr:map', self.namespaces)) etree.SubElement(zrmap, util.nspath_eval('zr:map', self.namespaces), set='dc').text = key zrindex = etree.SubElement(indexinfo, util.nspath_eval('zr:index', self.namespaces)) zrmap = etree.SubElement(zrindex, util.nspath_eval('zr:map', self.namespaces)) etree.SubElement(zrmap, util.nspath_eval('zr:name', self.namespaces), set='dc').text = 'title222' schemainfo = etree.SubElement(explain, util.nspath_eval('zr:schemaInfo', self.namespaces)) zrschema = etree.SubElement(schemainfo, util.nspath_eval('zr:schema', self.namespaces), name='dc', identifier='info:srw/schema/1/dc-v1.1') etree.SubElement(zrschema, util.nspath_eval('zr:title', self.namespaces)).text = 'Simple Dublin Core' configinfo = etree.SubElement(explain, util.nspath_eval('zr:configInfo', self.namespaces)) etree.SubElement(configinfo, util.nspath_eval('zr:default', self.namespaces), type='numberOfRecords').text = '0' elif util.xmltag_split(element.tag) == 'GetRecordsResponse': recpos = int(element.xpath('//@nextRecord')[0]) - int(element.xpath('//@numberOfRecordsReturned')[0]) node = etree.Element(util.nspath_eval('zs:searchRetrieveResponse', self.namespaces), nsmap=self.namespaces) etree.SubElement(node, util.nspath_eval('zs:version', self.namespaces)).text = self.sru_version etree.SubElement(node, util.nspath_eval('zs:numberOfRecords', self.namespaces)).text = element.xpath('//@numberOfRecordsMatched')[0] for rec in element.xpath('//csw:BriefRecord', namespaces=self.context.namespaces): record = etree.SubElement(node, util.nspath_eval('zs:record', self.namespaces)) etree.SubElement(node, util.nspath_eval('zs:recordSchema', self.namespaces)).text = 'info:srw/schema/1/dc-v1.1' etree.SubElement(node, util.nspath_eval('zs:recordPacking', self.namespaces)).text = 'xml' recorddata = etree.SubElement(record, util.nspath_eval('zs:recordData', self.namespaces)) rec.tag = util.nspath_eval('srw_dc:srw_dc', self.namespaces) recorddata.append(rec) etree.SubElement(record, util.nspath_eval('zs:recordPosition', self.namespaces)).text = str(recpos) recpos += 1 elif util.xmltag_split(element.tag) == 'ExceptionReport': node = self.exceptionreport2diagnostic(element) return node
def parse(element, queryables, dbtype, nsmap): ''' OGC Filter object support ''' boq = None tmp = element.xpath('ogc:And|ogc:Or|ogc:Not', namespaces=nsmap) if len(tmp) > 0: # this is binary logic query boq = ' %s ' % util.xmltag_split(tmp[0].tag).lower() tmp = tmp[0] else: tmp = element queries = [] for child in tmp.xpath('child::*'): com_op = '' boolean_true = '\'true\'' boolean_false = '\'false\'' if dbtype == 'mysql': boolean_true = 'true' boolean_false = 'false' if child.tag == util.nspath_eval('ogc:Not', nsmap): queries.append("%s = %s" % (_get_spatial_operator( queryables['pycsw:BoundingBox'], child.xpath('child::*')[0], dbtype, nsmap), boolean_false)) elif child.tag in \ [util.nspath_eval('ogc:%s' % n, nsmap) for n in \ MODEL['SpatialOperators']['values']]: if boq is not None and boq == ' not ': # for ogc:Not spatial queries in PostGIS we must explictly # test that pycsw:BoundingBox is null as well if dbtype == 'postgresql+postgis': queries.append( "%s = %s or %s is null" % (_get_spatial_operator(queryables['pycsw:BoundingBox'], child, dbtype, nsmap), boolean_false, queryables['pycsw:BoundingBox'])) else: queries.append("%s = %s" % (_get_spatial_operator( queryables['pycsw:BoundingBox'], child, dbtype, nsmap), boolean_false)) else: queries.append("%s = %s" % (_get_spatial_operator( queryables['pycsw:BoundingBox'], child, dbtype, nsmap), boolean_true)) elif child.tag == util.nspath_eval('ogc:FeatureId', nsmap): queries.append( "%s = '%s'" % (queryables['pycsw:Identifier'], child.attrib.get('fid'))) else: fname = None matchcase = child.attrib.get('matchCase') wildcard = child.attrib.get('wildCard') singlechar = child.attrib.get('singleChar') if wildcard is None: wildcard = '%' if singlechar is None: singlechar = '_' if (child.xpath('child::*')[0].tag == util.nspath_eval( 'ogc:Function', nsmap)): if (child.xpath('child::*')[0].attrib['name'] not in MODEL['Functions'].keys()): raise RuntimeError, ( 'Invalid ogc:Function: %s' % (child.xpath('child::*')[0].attrib['name'])) fname = child.xpath('child::*')[0].attrib['name'] try: pname = queryables[child.find( util.nspath_eval('ogc:Function/ogc:PropertyName', nsmap)).text]['dbcol'] except Exception, err: raise RuntimeError, ( 'Invalid PropertyName: %s. %s' % (child.find( util.nspath_eval('ogc:Function/ogc:PropertyName', nsmap)).text, str(err))) else: try: pname = queryables[child.find( util.nspath_eval('ogc:PropertyName', nsmap)).text]['dbcol'] except Exception, err: raise RuntimeError, ( 'Invalid PropertyName: %s. %s' % (child.find(util.nspath_eval('ogc:PropertyName', nsmap)).text, str(err)))
'Invalid PropertyName: %s. %s' % (child.find( util.nspath_eval('ogc:Function/ogc:PropertyName', nsmap)).text, str(err))) else: try: pname = queryables[child.find( util.nspath_eval('ogc:PropertyName', nsmap)).text]['dbcol'] except Exception, err: raise RuntimeError, ( 'Invalid PropertyName: %s. %s' % (child.find(util.nspath_eval('ogc:PropertyName', nsmap)).text, str(err))) if (child.tag != util.nspath_eval('ogc:PropertyIsBetween', nsmap)): pval = child.find(util.nspath_eval('ogc:Literal', nsmap)).text pvalue = pval.replace(wildcard, '%').replace(singlechar, '_') com_op = _get_comparison_operator(child) # if this is a case insensitive search # then set the DB-specific LIKE comparison operator if ((matchcase is not None and matchcase == 'false') or pname == 'anytext'): com_op = 'ilike' if dbtype in [ 'postgresql', 'postgresql+postgis' ] else 'like' if (child.tag == util.nspath_eval('ogc:PropertyIsBetween', nsmap)): com_op = 'between'
raise RuntimeError, ('Invalid PropertyName: %s. %s' % (child.find(util.nspath_eval('ogc:Function/ogc:PropertyName', nsmap)).text, str(err))) else: try: pname = queryables[child.find( util.nspath_eval('ogc:PropertyName', nsmap)).text]['dbcol'] except Exception, err: raise RuntimeError, ('Invalid PropertyName: %s. %s' % (child.find(util.nspath_eval('ogc:PropertyName', nsmap)).text, str(err))) if (child.tag != util.nspath_eval('ogc:PropertyIsBetween', nsmap)): pval = child.find(util.nspath_eval('ogc:Literal', nsmap)).text pvalue = pval.replace(wildcard,'%').replace(singlechar,'_') com_op = _get_comparison_operator(child) # if this is a case insensitive search # then set the DB-specific LIKE comparison operator if ((matchcase is not None and matchcase == 'false') or pname == 'anytext'): com_op = 'ilike' if dbtype == 'postgresql' else 'like' if (child.tag == util.nspath_eval('ogc:PropertyIsBetween', nsmap)): com_op = 'between' lower_boundary = child.find( util.nspath_eval('ogc:LowerBoundary/ogc:Literal',