Changeset 8354
- Timestamp:
- 16/06/12 16:58:29 (9 years ago)
- Location:
- mauRepo/HPFos/trunk/src
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/HPFos/trunk/src/HPFos/moles3epb.py
r8353 r8354 1 1 ''' 2 BSD Licence 3 Copyright (c) 2012, Science & Technology Facilities Council (STFC) 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without modification, 7 are 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 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 23 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 2 29 Created on 10 Jan 2012 3 30 4 @author: mnagni31 @author: Maurizio Nagni 5 32 ''' 6 33 from libs.epb import EPB … … 19 46 from ceda_guid import CedaGUID 20 47 from sqlalchemy.orm.util import identity_key 21 48 from ea_model.iso_19115_2006_metadata_corrigendum.extent_information.ex_geographicboundingbox import EX_GeographicBoundingBox 49 50 import logging 51 from logging import StreamHandler 52 from libs.postgisutil import create_st_setSRID, unifyGeometries,\ 53 intersectGeometries 22 54 23 55 class Moles3EPBFactory(EPB): … … 68 100 def __init__(self, session): 69 101 self._session = session 102 self.logging = logging.getLogger('Moles3EPB') 103 self.logging.addHandler(StreamHandler()) 104 self.logging.setLevel(logging.INFO) 70 105 71 106 def close(self): 72 107 return self._session.close() 73 108 74 def getOb servationCollections(self):109 def getObjectsByGE(self, class_type): 75 110 """ 76 111 Checks if a CEDA_Collection contains a given CEDA_Observation. … … 79 114 @return: True if the collection contains the given observation, False otherwise 80 115 """ 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 82 161 83 162 def searchEager(self, clazz, inst_id): -
mauRepo/HPFos/trunk/src/HPFos/osImpl/hpfos_conf.py
r8346 r8354 1 1 ''' 2 BSD Licence 3 Copyright (c) 2012, Science & Technology Facilities Council (STFC) 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without modification, 7 are 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 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 23 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 2 29 Created on 4 May 2012 3 30 4 @author: kusanagi31 @author: Maurizio Nagni 5 32 ''' 6 33 from markup.opensearch.os_request import OpenSearchRequest … … 16 43 os = OpenSearchRequest(query, [atomResponse], os_short_name, \ 17 44 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 1 1 ''' 2 BSD Licence 3 Copyright (c) 2012, Science & Technology Facilities Council (STFC) 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without modification, 7 are 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 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 23 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 2 29 Created on 5 May 2012 3 30 4 @author: kusanagi31 @author: Maurizio Nagni 5 32 ''' 6 33 from xml.etree.ElementTree import tostring, ElementTree … … 20 47 from datetime import datetime 21 48 from markup.opensearch.osquery import OSQuery 49 from libs.postgisutil import create_st_setSRID 22 50 23 51 COLLECTION = 'collection' 24 52 OBSERVATION = 'observation' 25 53 RESULT = 'result' 54 BBOX = 'box' 26 55 27 56 def calculateStep(**kwargs): … … 50 79 @param queries: 51 80 @param ospath: 81 @param kwargs: 52 82 """ 53 83 id = "" … … 60 90 61 91 #configuration level 62 #path = "http://mysite.com/"63 92 step = calculateStep(**kwargs) 64 93 root = ElementTree(atomdoc).getroot() 65 #extracted from result parameter66 94 67 95 #Generate feed's links … … 205 233 param_4 = OSParam("q", "searchTerms") 206 234 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/") 208 236 param_7 = OSParam("start", "start", namespace = "http://a9.com/-/opensearch/extensions/geo/1.0/") 209 237 param_8 = OSParam("stop", "stop", namespace = "http://a9.com/-/opensearch/extensions/time/1.0/") … … 245 273 246 274 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 247 284 if kwargs['params_values'] and kwargs['params_values'].has_key(COLLECTION) and kwargs['params_values'].has_key(OBSERVATION): 248 285 return self.searchObservation(**kwargs) … … 251 288 return self.searchCollection(**kwargs) 252 289 253 results = kwargs['moles3EPB'].getObservationCollections() 290 results = kwargs['moles3EPB'].getObservationCollections(bbox = ibbox) 291 292 293 294 254 295 return self._packResult(results, **kwargs) 255 296
Note: See TracChangeset
for help on using the changeset viewer.