Changeset 1297
- Timestamp:
- 13/07/06 12:44:48 (15 years ago)
- Location:
- TI02-CSML/trunk/parser
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/parser/API/CSMLDocument.py
r1086 r1297 1 1 ''' CSMLDocument.py - simple implementation to return a CSML document containing a single type of feature''' 2 2 from API import * 3 from Parser import * 4 import parser_extra 3 5 4 6 class CSMLDocument: 5 def makeGridSeries(self,domain,rangeSet,datasetID=None,featureID=None): 7 def __init__(self,docID, docMetaDataProperty): 8 ''' 9 docID = gml:id of Dataset element 10 docMetaDataProperty = gml:metaDataProperty of Dataset element #hmm may need to allow a list here. 11 ''' 12 #initialise a new document 13 #Create an Empty Dataset & FeatureCollection 14 self.ds = Dataset() 15 self.fc=FeatureCollection() 16 #Set attributes of dataset 17 #if docMetaDataProperty is a URI, set it as href attribute if MetaDataProperty instance, 18 #else set it as a text attribute of a MetaDataProperty instance. 19 mdp=MetaDataProperty() 20 if parser_extra.isURI(docMetaDataProperty): 21 mdp.href=docMetaDataProperty 22 else: 23 mdp.text = [docMetaDataProperty] 24 self.ds.metaDataProperty= [mdp] 25 #set the id 26 self.ds.id=docID 27 self.dm=[] #empty list to hold definition members (e.g. UnitDefinitions) 28 self.fm=[] #empty list to hold feature members (e.g. GridFeatures, PointFeatures) 29 self.ad=[] #empty list to hold array descriptors (e.g. NetCDFExtract) 30 #the dataset is now initialised. now you can add features/defintions/arraydescriptors 31 #using the methods supplied. 32 #when finished building CSML objects call the consolidate method to return the document. 33 34 #separate build classes for each feature type 35 def addPointFeature(self, id, description,domainReference,rangeSet, parameter): 36 #TO DO- this needs revising in line with addGridSeriesFeature 37 """ addPointFeature 38 domainReference = Position type 39 rangeSet = quantityList type, 40 parameter = Phenomenon type 41 """ 42 feat=PointFeature() 43 feat.id=id 44 feat.description=Description(description) 45 46 #Add the domain to the feature 47 p=Position() 48 p.srsName =domainReference[0] 49 p.axisLabels=domainReference[1] 50 p.uomLabels = domainReference[2] 51 p.location=domainReference[3] 52 p.time=domainReference[4] 53 ptd=PointDomain() 54 ptd.domainReference=p 55 feat.domain=ptd 56 57 #Add the rangeSet to the feature 58 rs=RangeSet() 59 rs.quantityList=MeasureOrNullList(uom=rangeSet[0],val = rangeSet[1]) 60 feat.rangeSet=rs 61 62 #Add the parameter to the feature 63 feat.parameter=Phenomenon(href=parameter) 64 65 self.fm.append(feat) 66 def addProfileFeature(self): 67 pass 68 69 def addGridFeature(self): 70 pass 71 72 def addPointSeriesFeature(self): 73 pass 74 75 def addProfileSeriesFeature(self): 76 pass 77 78 def addGridSeriesFeature(self,domain,rangeSet,datasetID=None,featureID=None,description=None): 6 79 fms=[] #empty featureMembers list 7 80 feat=Parser.GridSeriesFeature() … … 9 82 feat.id= featureID 10 83 else: 11 feat.id='testfeature' 12 feat.description=Parser.Description('???') 84 feat.id='No ID' 85 if description: 86 feat.description=Parser.Description(description) 87 else: 88 feat.description=Parser.Description('No Description') 13 89 feat.domain=domain 14 90 feat.rangeSet=rangeSet 15 fms.append(feat) 16 fc=Parser.FeatureCollection(members=fms) 17 #Create an Empty Dataset 18 ds = Parser.Dataset() 19 #Set objects as attributes of dataset 20 if datasetID: 21 ds.id=datasetID 22 else: 23 ds.id='testdataset' 24 ds.featureCollection=fc 25 #call the toXML method of the Dataset object: 26 csml = ds.toXML() 91 self.fm.append(feat) 92 93 def addTrajectoryFeature(self): 94 pass 95 96 def addFileExtract(self,extractType, id, variableName=None,arraySize=None,fileName=None): 97 #handles the addition of file extract classes (can probably get away with one method for all types of extracts for now) 98 if extractType=='NetCDFExtract': 99 ex=NetCDFExtract() 100 if extractType=='NASAAmesExtract': 101 ex=NASAAmesExtract() 102 if extractType=='GRIBExtract': 103 ex=GRIBExtract() 104 if extractType=='PPExtract': 105 ex=PPExtract() 106 ex.id =id 107 if arraySize: 108 ex.arraySize=[arraySize] 109 if fileName: 110 ex.fileName=fileName 111 if variableName: 112 ex.variableName=variableName 113 self.ad.append(ex) 114 115 116 def removeFileExtract(self): 117 #not implemented yet 118 pass 119 120 def removeFeature(self,featureID): 121 #not implemented yet. 122 pass 123 def addDefintion(self): 124 #not implemented yet. - may need separate methods for different defintion types? 125 pass 126 127 def removeDefintion(self): 128 #not implemented yet. 129 pass 130 131 def setBoundingEnvelope(self,lowerCorner,upperCorner,timePosition1,timePosition2): 132 #set the bounding box envelope of the feature collection. 133 etp = EnvelopeWithTimePeriod() 134 etp.lowerCorner=lowerCorner 135 etp.upperCorner=upperCorner 136 etp.timePosition=timePosition1 137 etp.timePosition2=timePosition2 138 self.fc.boundedBy=etp 139 140 141 142 def consolidate(self): 143 #when you have finished building the document, need to consolidate it and return a CSML document (string) 144 self.ds.arrayDescriptors=self.ad 145 self.ds.featureCollection=FeatureCollection(members=self.fm) 146 csml=self.ds.toXML() 147 #parse and pretty print the result 27 148 strCSML=parser_extra.PrettyPrint(csml) 28 149 strCSML=parser_extra.removeInlineNS(strCSML) -
TI02-CSML/trunk/parser/API/ops_GridSeriesFeature.py
r1196 r1297 135 135 136 136 #### write csml document ##### -move this to the csmldocument module? 137 subsetCSML=CSMLDocument() 138 subsetCSML=subsetCSML.makeGridSeries(domain,rangeSet) 137 csmldoc=CSMLDocument("mydoc", "mymetadata") 138 csmldoc.addGridSeriesFeature(domain,rangeSet,datasetID="A",featureID="B",description="C") 139 csmldoc=csmldoc.consolidate() 139 140 output=open(pathToSubsetCSML,'w') 140 output.write( subsetCSML)141 output.write(csmldoc) 141 142 output.close() 142 143 -
TI02-CSML/trunk/parser/parser_extra.py
r1147 r1297 9 9 import sys 10 10 import elementtree.ElementTree as etree 11 11 import string 12 12 13 13 #some xml/string manipulation functions. may as well go in this file for now: … … 64 64 csmlstring=csmlstring.replace('ns1:', '') #the rest of the ns1s are CSML namespaces... due to the way it has been parsed. 65 65 return csmlstring 66 67 68 def isURI(uri): 69 """ a very simple function to test if a string is a uri 70 if ;// appears in the first 12 characters it is probably a uri """ 71 #TODO - a decent uri check! 72 result = False 73 if string.find(uri[:12], '://') != -1: 74 result = True 75 return result 66 76 67 77
Note: See TracChangeset
for help on using the changeset viewer.