source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_api.py @ 2494

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_api.py@2494
Revision 2494, 904 bytes checked in by spascoe, 12 years ago (diff)

Created a trivial CSML reading app based on Dom's code. Just shows the
featureIds for now.

Line 
1from ows_server.lib.base import *
2import csml.parser
3import os
4
5def get_csml_doc(file):
6    """
7    A trivial document retrieval function.
8
9    This could be replaced with a proper csml server object that supports
10    multiple stores (filesystem, exist) and cache's the results for
11    performance.
12
13    """
14    csml_dir = request.environ['paste.config']['app_conf']['csml_dir']
15    path = os.path.join(csml_dir, file)
16    if os.path.exists(path+'.csml'):
17        f = path+'.csml'
18    elif os.path.exists(path+'.xml'):
19        f = path +'.xml'
20    else:
21        raise ValueError("Cannot find CSML file %s" % file)
22   
23    d = csml.parser.Dataset()
24    d.parse(f)
25       
26    return d
27
28
29class CsmlApiController(BaseController):
30    def index(self, file):
31        d = get_csml_doc(file)
32        return Response('Dataset: %s\nFeatures: %s' % (file,
33                        ' '.join(d.getFeatureList())))
34
Note: See TracBrowser for help on using the repository browser.