Changeset 2782
- Timestamp:
- 08/08/07 11:48:30 (14 years ago)
- Location:
- TI05-delivery/ows_framework/trunk/ows_server/ows_server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_wcs.py
r2780 r2782 234 234 def GetCoverage(self, uri, version, format, identifier, boundingbox, timesequence, store=False, status=False): 235 235 # Retrieve dataset and selected feature 236 try: 237 rstatus,dataset=interface.GetParsedCSML(uri) 238 if not rstatus: raise ValueError(dataset) 239 feature = dataset.getFeature(identifier) 240 if feature is None: 241 raise OWS_E.InvalidParameterValue('Coverage not found', 'identifier') 236 #try: 237 rstatus,dataset=interface.GetParsedCSML(uri) 238 if not rstatus: raise ValueError(dataset) 239 feature = dataset.getFeature(identifier) 240 if feature is None: 241 raise OWS_E.InvalidParameterValue('Coverage not found', 'identifier') 242 243 244 #set bounding box 245 246 lon=feature.getLongitudeAxis() 247 lat=feature.getLatitudeAxis() 248 t=feature.getTimeAxis() 249 if None in [lon, lat, time]: 250 #TODO need to return a suitable wcs error. 251 print 'warning, could not get correct axis info' 252 253 #create selection dictionary: 254 sel={} 255 sel[lat]=(boundingbox[1], boundingbox[3]) 256 sel[lon]=(boundingbox[0], boundingbox[2]) 257 sel[t]=timesequence 258 #z is the 4th axis (eg height or pressure). 259 #NOTE, need to decide whether bounding box is of form: x1,y1,z1,x2,y2,z2 or x1,y1,x2,y2,z1,z2 260 #currently the latter is implemented. 261 262 if len(boundingbox) == 6: 263 for ax in feature.getAxisLabels(): 264 if ax not in [lat, lon, t]: 265 #must be Z 266 z=str(ax) 267 sel[z]=(boundingbox[4], boundingbox[5]) 268 269 270 axisNames=feature.getAxisLabels() 271 272 273 # Extract via CSML.subsetToGridSeries() 274 if store: 275 #need to farm off to WPS 276 #but for now... 277 filename = extractToNetCDF(feature, sel, publish = True) 278 else: 279 filename = extractToNetCDF(feature, sel) 280 242 281 243 244 #set bounding box TODO 245 sel = dict(latitude=(boundingbox[1], boundingbox[3]), longitude=(boundingbox[0], boundingbox[2])) 246 sel['time']=timesequence 247 248 lon=feature.getLongitudeAxis() 249 lat=feature.getLatitudeAxis() 250 t=feature.getTimeAxis() 251 252 if None in [lon, lat, time]: 253 #TODO need to return a suitable wcs error. 254 pass 255 256 #create selection dictionary: 257 sel={} 258 sel[lat]=(boundingbox[1], boundingbox[3]) 259 sel[lon]=(boundingbox[0], boundingbox[2]) 260 sel[t]=timesequence 261 262 #z is the 4th axis (eg height or pressure). 263 #NOTE, need to decide whether bounding box is of form: x1,y1,z1,x2,y2,z2 or x1,y1,x2,y2,z1,z2 264 #currently the latter is implemented. 265 266 if len(boundingbox) == 6: 267 for ax in feature.getAxisLabels(): 268 if ax not in [lat, lon, t]: 269 #must be Z 270 z=str(ax) 271 sel[z]=(boundingbox[4], boundingbox[5]) 272 273 274 axisNames=feature.getAxisLabels() 275 276 277 # Extract via CSML.subsetToGridSeries() 278 if store: 279 #need to farm off to WPS 280 #but for now... 281 filename = extractToNetCDF(feature, sel, publish = True) 282 #use the randomly allocated filename as a basis for an identifier 283 f=os.path.basename(filename) 284 c.fileID=os.path.splitext(f)[0] 285 286 #Depending on if the 'store' parameter is set, either return the netcdf file + coverage xml as a multipart mime or return a coverage document containing a link. 287 288 if store: 289 if status: 290 #STORE = true, STATUS = true: 291 #hand off file "id" to StatusController to determine correct ExectuteResponse type response. 292 status=StatusController() 293 jobID=os.path.splitext(os.path.basename(filename)[9:])[0] #remove the 'csml_wxs_' prefix and file extension to create a jobID 294 return status.getStatus(jobID) 282 295 else: 283 filename = extractToNetCDF(feature, sel) 284 285 286 #use the randomly allocated filename as a basis for an identifier 287 f=os.path.basename(filename) 288 c.fileID=os.path.splitext(f)[0] 289 290 #Depending on if the 'store' parameter is set, either return the netcdf file + coverage xml as a multipart mime or return a coverage document containing a link. 291 292 if store: 293 if status: 294 #STORE = true, STATUS = true: 295 #hand off file "id" to StatusController to determine correct ExectuteResponse type response. 296 status=StatusController() 297 jobID=os.path.splitext(os.path.basename(filename)[9:])[0] #remove the 'csml_wxs_' prefix and file extension to create a jobID 298 return status.getStatus(jobID) 296 #STORE=true, STATUS = false: Return Coverage XML document with link to file. 297 #use the temp file name (minus extension) as an ID 298 c.hyperlink = 'http://'+request.environ['HTTP_HOST']+'/'+os.path.basename(request.environ['paste.config']['app_conf']['publish_dir'])+'/'+os.path.basename(filename) 299 r=render_response('wcs_getCoverageResponse', format='xml') 300 r.headers['content-type'] = 'text/xml' 301 #write ndgSec to text file and store with coverage file: 302 textName=request.environ['paste.config']['app_conf']['publish_dir']+'/'+os.path.splitext(os.path.basename(filename))[0]+'.txt' 303 secText=open(textName, 'w') 304 if 'ndgSec' in session: 305 securityinfo=str(session['ndgSec']) 299 306 else: 300 #STORE=true, STATUS = false: Return Coverage XML document with link to file. 301 #use the temp file name (minus extension) as an ID 302 c.hyperlink = 'http://'+request.environ['HTTP_HOST']+'/'+os.path.basename(request.environ['paste.config']['app_conf']['publish_dir'])+'/'+os.path.basename(filename) 303 r=render_response('wcs_getCoverageResponse', format='xml') 304 r.headers['content-type'] = 'text/xml' 305 #write ndgSec to text file and store with coverage file: 306 if 'ndgSec' in session: 307 textName=request.environ['paste.config']['app_conf']['publish_dir']+'/'+os.path.splitext(os.path.basename(filename))[0]+'.txt' 308 secText=open(textName, 'w') 309 310 securityinfo=str(session['ndgSec']) 311 secText.write(securityinfo) 312 secText.close() 313 return r 314 else: 315 #STORE = FALSE, STATUS therefore irrelevant, return Multipart Mime. 316 netcdfFile=open(filename, 'r') 317 c.hyperlink="cid:coverage.nc" 318 xmlfile=render_response('wcs_getCoverageResponse', format='xml') 319 xmlfile.headers['content-type'] = 'text/xml' 320 multipart=self._createMultipartMime(xmlfile, netcdfFile) 321 msg=multipart 322 #msg=open(multipart, 'r').readlines() 323 return Response(content=msg, mimetype='multipart') 307 securityinfo='No Security' 308 secText.write(securityinfo) 309 secText.close() 310 return r 311 else: 312 #STORE = FALSE, STATUS therefore irrelevant, return Multipart Mime. 313 netcdfFile=open(filename, 'r') 314 c.hyperlink="cid:coverage.nc" 315 xmlfile=render_response('wcs_getCoverageResponse', format='xml') 316 xmlfile.headers['content-type'] = 'text/xml' 317 multipart=self._createMultipartMime(xmlfile, netcdfFile) 318 msg=multipart 319 #msg=open(multipart, 'r').readlines() 320 return Response(content=msg, mimetype='multipart') 324 321 325 except Exception, e: 326 if isinstance(e, OWS_E.OwsError): 327 raise e 328 elif isinstance(e, ValueError): 329 if e.message == '<p> Access Denied </p><p>Not Logged in</p>': 330 c.msg=e.message 331 #h.redirect_to('/login') 332 return render_response('wcs_accessDenied', mimetype ='text/html') 333 else: 334 raise OWS_E.NoApplicableCode(e) 335 else: 336 raise OWS_E.NoApplicableCode(e) 337 338 322 #comment out for now while testing 323 #except Exception, e: 324 #if isinstance(e, OWS_E.OwsError): 325 #raise e 326 #elif isinstance(e, ValueError): 327 #if e.message == '<p> Access Denied </p><p>Not Logged in</p>': 328 #c.msg=e.message 329 ##h.redirect_to('/login') 330 #return render_response('wcs_accessDenied', mimetype ='text/html') 331 #else: 332 #raise OWS_E.NoApplicableCode(e) 333 #else: 334 #raise OWS_E.NoApplicableCode(e) 335 336 -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/fetch.py
r2740 r2782 25 25 #if they match, return the file 26 26 #TODO, check this properly 27 if 'ndgSec' in session: 27 if sec=='No Security': 28 match=True #allow 29 elif 'ndgSec' in session: 28 30 if sec == str(session['ndgSec']): 29 match=True 31 match=True #allow 30 32 else: 31 match=False 33 match=False #deny 32 34 else: 33 match=False 35 match=False #deny 34 36 if match: 35 37 #return the file (netcdf) -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/csml_util.py
r2689 r2782 86 86 publish flag is used to indicate that the netcdf file should be made available to the webserver (for asynchronous delivery) 87 87 """ 88 89 88 90 89 if publish: … … 94 93 else: 95 94 extract_dir = request.environ['paste.config']['app_conf']['tmp_dir'] 96 97 95 98 96 # Subset the feature 99 97 (fd, filename) = tempfile.mkstemp('.nc', 'csml_wxs_', extract_dir); os.close(fd) 100 feature.subsetToGridSeries(ncname=os.path.basename(filename), outputdir=os.path.dirname(filename) ,**sel) 101 98 if type(feature) is csml.parser.GridSeriesFeature: 99 feature.subsetToGridSeries(ncname=os.path.basename(filename), outputdir=os.path.dirname(filename) ,**sel) 100 elif type(feature) is csml.parser.TrajectoryFeature: 101 feature.subsetToTrajectory(ncname=os.path.basename(filename), outputdir=os.path.dirname(filename) ,**sel) 102 102 103 return filename 103 104
Note: See TracChangeset
for help on using the changeset viewer.