Changeset 8354 for mauRepo


Ignore:
Timestamp:
16/06/12 16:58:29 (7 years ago)
Author:
mnagni
Message:

Implemented the bbox query URL (at least for the CEDA_ObservationCollection)

Location:
mauRepo/HPFos/trunk/src
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/HPFos/trunk/src/HPFos/moles3epb.py

    r8353 r8354  
    11''' 
     2BSD Licence 
     3Copyright (c) 2012, Science & Technology Facilities Council (STFC) 
     4All rights reserved. 
     5 
     6Redistribution and use in source and binary forms, with or without modification,  
     7are permitted provided that the following conditions are met: 
     8 
     9    * Redistributions of source code must retain the above copyright notice,  
     10        this list of conditions and the following disclaimer. 
     11    * Redistributions in binary form must reproduce the above copyright notice, 
     12        this list of conditions and the following disclaimer in the documentation 
     13        and/or other materials provided with the distribution. 
     14    * Neither the name of the Science & Technology Facilities Council (STFC)  
     15        nor the names of its contributors may be used to endorse or promote  
     16        products derived from this software without specific prior written permission. 
     17 
     18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
     19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  
     20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR  
     21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
     22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
     23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  
     24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
     25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
     26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  
     27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     28 
    229Created on 10 Jan 2012 
    330 
    4 @author: mnagni 
     31@author: Maurizio Nagni 
    532''' 
    633from libs.epb import EPB 
     
    1946from ceda_guid import CedaGUID 
    2047from sqlalchemy.orm.util import identity_key 
    21  
     48from ea_model.iso_19115_2006_metadata_corrigendum.extent_information.ex_geographicboundingbox import EX_GeographicBoundingBox 
     49 
     50import logging 
     51from logging import StreamHandler 
     52from libs.postgisutil import create_st_setSRID, unifyGeometries,\ 
     53    intersectGeometries 
    2254 
    2355class Moles3EPBFactory(EPB): 
     
    68100    def __init__(self, session): 
    69101        self._session = session 
     102        self.logging = logging.getLogger('Moles3EPB') 
     103        self.logging.addHandler(StreamHandler()) 
     104        self.logging.setLevel(logging.INFO) 
    70105         
    71106    def close(self): 
    72107        return self._session.close()         
    73108         
    74     def getObservationCollections(self): 
     109    def getObjectsByGE(self, class_type): 
    75110        """ 
    76111            Checks if a CEDA_Collection contains a given CEDA_Observation. 
     
    79114            @return: True if the collection contains the given observation, False otherwise   
    80115        """ 
    81         return self._session.query(CEDA_ObservationCollection).all()                 
     116        if isinstance(class_type, type(CEDA_ObservationCollection)) or isinstance(class_type, type(CEDA_Observation)): 
     117            return self._session.query(class_type).all() 
     118        return None 
     119     
     120    def getGeograpicExtentGeometry(self, ge): 
     121        ''' 
     122            Creates the appropriate postgis geometry from a EX_GeographicExtent 
     123            @param ge: an EX_GeographicExtent instance 
     124            @return: a postgix text geometry 
     125        ''' 
     126        if isinstance(ge, EX_GeographicBoundingBox): 
     127            return create_st_setSRID(ge.westBoundLongitude, ge.southBoundLatitude, \ 
     128                           ge.eastBoundLongitude, ge.northBoundLatitude) 
     129        return None 
     130     
     131     
     132     
     133    def getUnifyObservationCollectionGE(self, collection): 
     134        """ 
     135            Returns the union of the collections.member'a  GeographicExtension(s) 
     136            @param collection: an CEDA_ObservationColleciton instance   
     137        """ 
     138        bboxes = [] 
     139        for member in collection.member: 
     140            for ge in member.geographicExtent: 
     141                bboxes.append(self.getGeograpicExtentGeometry(ge)) 
     142         
     143        return unifyGeometries(bboxes, self)                         
     144         
     145    def getObservationCollections(self, bbox = None): 
     146        """ 
     147            Returns the stored CEDA_ObservationCollection eventually filtering them against a postgis goemetry 
     148            @param bbox: a postgis geometry 
     149            @return: a list of CEDA_ObservationCollections or None if empty   
     150        """ 
     151        collections = self._session.query(CEDA_ObservationCollection).all() 
     152        if bbox == None: 
     153            return collections 
     154         
     155        res = [] 
     156        for collection in collections: 
     157            collection_geometry = self.getUnifyObservationCollectionGE(collection) 
     158            if collection_geometry and intersectGeometries([collection_geometry, bbox], self): 
     159                res.append(collection) 
     160        return res 
    82161         
    83162    def searchEager(self, clazz, inst_id): 
  • mauRepo/HPFos/trunk/src/HPFos/osImpl/hpfos_conf.py

    r8346 r8354  
    11''' 
     2BSD Licence 
     3Copyright (c) 2012, Science & Technology Facilities Council (STFC) 
     4All rights reserved. 
     5 
     6Redistribution and use in source and binary forms, with or without modification,  
     7are permitted provided that the following conditions are met: 
     8 
     9    * Redistributions of source code must retain the above copyright notice,  
     10        this list of conditions and the following disclaimer. 
     11    * Redistributions in binary form must reproduce the above copyright notice, 
     12        this list of conditions and the following disclaimer in the documentation 
     13        and/or other materials provided with the distribution. 
     14    * Neither the name of the Science & Technology Facilities Council (STFC)  
     15        nor the names of its contributors may be used to endorse or promote  
     16        products derived from this software without specific prior written permission. 
     17 
     18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
     19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  
     20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR  
     21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
     22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
     23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  
     24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
     25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
     26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  
     27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     28 
    229Created on 4 May 2012 
    330 
    4 @author: kusanagi 
     31@author: Maurizio Nagni 
    532''' 
    633from markup.opensearch.os_request import OpenSearchRequest 
     
    1643    os = OpenSearchRequest(query, [atomResponse], os_short_name, \ 
    1744                           os_description) 
    18     #return OSEngine(os, 'http://eo-virtual-archive4.esa.int') 
    19     return OSEngine(os, 'http://localhost:8000') 
    20  
    21  
    22   
    23 ''' 
    24     def testGetDescription(self):                        
    25         print self.osEngine.getDescription() 
    26  
    27     def testDoQuery(self): 
    28         params = {'q': ['ice', 'snow']}                         
    29         #mimetype = "text/html" 
    30         #print self.os.doSearch(mimetype, params) 
    31         format = "atom" 
    32         response = self.osEngine.doSearch(format, params) 
    33         print response 
    34  
    35  
    36 if __name__ == "__main__": 
    37     #import sys;sys.argv = ['', 'Test.testName'] 
    38     unittest.main() 
    39 '''     
     45    return OSEngine(os, 'http://localhost:8000')    
  • mauRepo/HPFos/trunk/src/HPFos/osImpl/myimpl.py

    r8353 r8354  
    11''' 
     2BSD Licence 
     3Copyright (c) 2012, Science & Technology Facilities Council (STFC) 
     4All rights reserved. 
     5 
     6Redistribution and use in source and binary forms, with or without modification,  
     7are permitted provided that the following conditions are met: 
     8 
     9    * Redistributions of source code must retain the above copyright notice,  
     10        this list of conditions and the following disclaimer. 
     11    * Redistributions in binary form must reproduce the above copyright notice, 
     12        this list of conditions and the following disclaimer in the documentation 
     13        and/or other materials provided with the distribution. 
     14    * Neither the name of the Science & Technology Facilities Council (STFC)  
     15        nor the names of its contributors may be used to endorse or promote  
     16        products derived from this software without specific prior written permission. 
     17 
     18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
     19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  
     20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR  
     21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
     22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
     23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  
     24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
     25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
     26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  
     27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     28 
    229Created on 5 May 2012 
    330 
    4 @author: kusanagi 
     31@author: Maurizio Nagni 
    532''' 
    633from xml.etree.ElementTree import tostring, ElementTree 
     
    2047from datetime import datetime 
    2148from markup.opensearch.osquery import OSQuery 
     49from libs.postgisutil import create_st_setSRID 
    2250  
    2351COLLECTION = 'collection' 
    2452OBSERVATION = 'observation' 
    2553RESULT = 'result' 
     54BBOX = 'box' 
    2655 
    2756def calculateStep(**kwargs): 
     
    5079            @param queries: 
    5180            @param ospath:   
     81            @param kwargs:  
    5282        """ 
    5383        id = "" 
     
    6090         
    6191        #configuration level 
    62         #path = "http://mysite.com/" 
    6392        step = calculateStep(**kwargs) 
    6493        root = ElementTree(atomdoc).getroot() 
    65         #extracted from result parameter 
    6694 
    6795        #Generate feed's links 
     
    205233        param_4 = OSParam("q", "searchTerms")            
    206234        param_5 = OSParam("uid", "uid", namespace = "http://a9.com/-/opensearch/extensions/geo/1.0/")         
    207         param_6 = OSParam("box", "box", namespace = "http://a9.com/-/opensearch/extensions/geo/1.0/")         
     235        param_6 = OSParam(BBOX, BBOX, namespace = "http://a9.com/-/opensearch/extensions/geo/1.0/")         
    208236        param_7 = OSParam("start", "start", namespace = "http://a9.com/-/opensearch/extensions/geo/1.0/")         
    209237        param_8 = OSParam("stop", "stop", namespace = "http://a9.com/-/opensearch/extensions/time/1.0/")         
     
    245273         
    246274    def doSearch(self, **kwargs): 
     275        ibbox = None 
     276        if kwargs['params_values'] and kwargs['params_values'].has_key(BBOX): 
     277            coords = kwargs['params_values'][BBOX].split(',') 
     278            try: 
     279                if len(coords) == 4: 
     280                    ibbox = create_st_setSRID(int(coords[0]),int(coords[1]),int(coords[2]),int(coords[3])) 
     281            except Exception as e: 
     282                pass 
     283         
    247284        if kwargs['params_values'] and kwargs['params_values'].has_key(COLLECTION) and kwargs['params_values'].has_key(OBSERVATION): 
    248285            return self.searchObservation(**kwargs)         
     
    251288            return self.searchCollection(**kwargs)         
    252289             
    253         results = kwargs['moles3EPB'].getObservationCollections() 
     290        results = kwargs['moles3EPB'].getObservationCollections(bbox = ibbox) 
     291 
     292                                   
     293                 
     294         
    254295        return self._packResult(results, **kwargs) 
    255296 
Note: See TracChangeset for help on using the changeset viewer.