source: TI02-CSML/trunk/csml/API/ @ 1555

Subversion URL:
Revision 1555, 3.2 KB checked in by domlowe, 15 years ago (diff)

some changes to allow cdml to be used as data source, not working properly yet though

1import csml.parser
2import csml.parser_extra
4class Container(object):
5    '''CSMLContainer object is used to hold features before generating a CSML document. This is useful because it allows you to subset several features sequentially then build a single CSML document containing all the subsetted features '''
7    def __init__(self,csmlpath='myfile.xml',docID='none',metadata='unspecified'):
8        self.csmlpath=csmlpath
9        ''' Initialise CSML Dataset and FeatureCollection and populate with basic Metadata'''
10        '''
11        docID = gml:id of Dataset element
12        docMetaDataProperty = gml:metaDataProperty of Dataset element  #hmm may need to allow a list here.
13        '''
14        #initialise a new document
15        #Create an Empty Dataset & FeatureCollection
16        self.ds = csml.parser.Dataset()
17        self.fc=csml.parser.FeatureCollection()
18        #Set attributes of dataset
19        #if 'metadata' is a URI, set it as href attribute if MetaDataProperty instance,
20        #else set it as a text attribute of a MetaDataProperty instance.
21        mdp=csml.parser.MetaDataProperty()
22        if csml.parser_extra.isURI(metadata):
23            mdp.href=metadata
24        else: 
25            mdp.text = [metadata]
26        self.ds.metaDataProperty= [mdp]
27        #set the id
29[] #empty list to hold definition members (e.g. UnitDefinitions)
30[] #empty list to hold feature members (e.g. GridFeatures, PointFeatures)
31[] #empty list to hold array descriptors (e.g. NetCDFExtract)
32        #the dataset is now initialised. now you can add features/defintions/arraydescriptors
33        #using the methods supplied.
34        #when finished building CSML objects call the getContents method to return the document.       
36        '''containerContents contains the CSML Document (first item) and then any NetCDF files that are to be delivered with the document '''
37        self.containerContents=[]
38        self.ncfiles=[]
40    def appendFileExtract(self, fileextract):
41        ''' Append File Extract to Dataset '''
42        #append to Dataset instance
43        pass
45    def appendFeature(self, feature):
46        ''' Append feature to FeatureCollection'''
47        #append to FeatureCollection instance
50    def attachNetCDFFile(self, ncfile):
51        ''' Attach a NetCDF file to the container object. Multiple NetCDF files can be referenced from multiple features and returned with the CSML document'''
52        #append NetCDF file object to containerContents
53        #need to think about whether it is best to append the file object or just a path to the file
54        self.ncfiles.append(ncfile)
57    def getContents(self):
59        self.ds.featureCollection=csml.parser.FeatureCollection(
60        print
61        csmlout=self.ds.toXML()
62        #parse and pretty print the result
63        strCSML=csml.parser_extra.PrettyPrint(csmlout)
64        strCSML=csml.parser_extra.removeInlineNS(strCSML)
65        self.containerContents.append(strCSML)
66        for ncfile in self.ncfiles:
67            self.containerContents.append(ncfile)
68        return self.containerContents
Note: See TracBrowser for help on using the repository browser.