Changeset 3306
- Timestamp:
- 04/02/08 18:20:38 (13 years ago)
- Location:
- DPPP/kml/csml2kml
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
DPPP/kml/csml2kml/python/csml2kml/PointSeriesConvertor.py
r3304 r3306 15 15 self.kmlFilename = kmlFilename 16 16 17 def parseGMLStationsCollection(textGml): 18 ''' 19 Parse the GML returned from GeoServer and yield tuples containing information (gml_id, name, lon, lat) 20 about each station. 21 ''' 22 root = XML(textGml) 23 featureCollectionElement = root 24 for featureMember in featureCollectionElement.getchildren(): 25 stationElement = featureMember.getchildren()[0] 26 (stationNameElement, stationIDElement, locationElement) = stationElement.getchildren() 27 pointElement = locationElement.getchildren()[0] 28 posElement = pointElement.getchildren()[0] 29 (lon,lat) = map(float, posElement.text.split()) 30 yield (stationElement.get('{http://www.opengis.net/gml}id'), stationNameElement.text, lon, lat) 31 32 def convert(self, config, kmlFilename): 17 def convert(self): 33 18 ''' 34 19 Convert GML input from GeoServer (containing the <Station> tags with station information) … … 39 24 ''' 40 25 26 def _parseGMLStationsCollection(textGml): 27 ''' 28 Parse the GML returned from GeoServer and yield tuples containing information (gml_id, name, lon, lat) 29 about each station. 30 ''' 31 root = XML(textGml) 32 featureCollectionElement = root 33 for featureMember in featureCollectionElement.getchildren(): 34 stationElement = featureMember.getchildren()[0] 35 (stationNameElement, stationIDElement, locationElement) = stationElement.getchildren() 36 pointElement = locationElement.getchildren()[0] 37 posElement = pointElement.getchildren()[0] 38 (lon,lat) = map(float, posElement.text.split()) 39 yield (stationElement.get('{http://www.opengis.net/gml}id'), stationNameElement.text, lon, lat) 40 41 41 # Read conversion configuration 42 42 documentName = self.config.find('name').text … … 44 44 balloonTemplate = self.config.find('GeoServerRequest/BalloonTemplate').text 45 45 stationData = {} 46 data = self.config.find All('GeoServerRequest/StationData/Datum')46 data = self.config.findall('GeoServerRequest/StationData/Datum') 47 47 for datum in data: 48 48 datumName = datum.get('name') … … 54 54 placemarkKmlStyle = createDefaultPlacemarKMLStyle(balloonTemplate = balloonTemplate) 55 55 kmlDocument = KMLDocument(documentName, [placemarkKmlStyle]) 56 generator = parseGMLStationsCollection(textGml)56 generator = _parseGMLStationsCollection(textGml) 57 57 for (gml_id, name, lon, lat) in generator: 58 58 kmlStation = KMLPlacemark(gml_id, name, lon, lat, styleID = placemarkKmlStyle.id, data = stationData) -
DPPP/kml/csml2kml/python/csml2kml/tests/testPointSeriesConvertor.py
r3303 r3306 1 import PointSeriesConvertor1 from PointSeriesConvertor import PointSeriesConvertor 2 2 from cElementTree import ElementTree 3 3 4 4 # Load the configuration XML element 5 5 configTree = ElementTree() 6 configTree.parse('../../ testdata/midas.csml2kml.conf.xml')6 configTree.parse('../../../testdata/midas.csml2kml.conf.xml') 7 7 configRoot = configTree.getroot() 8 config = configRoot.find('CSML 2KMLConfig/CSMLStationPointSeries')8 config = configRoot.find('CSMLStationPointSeries') 9 9 10 10 # Do the conversion 11 convertor = PointSeriesConvertor(config, '../../output/exampleps.3.xml') 11 convertor = PointSeriesConvertor(config, '../../../output/exampleps_stations.2.xml') 12 convertor.convert() -
DPPP/kml/csml2kml/testdata/midas.csml2kml.conf.xml
r3305 r3306 1 1 <CSML2KMLConfig> 2 2 <CSMLStationPointSeries> 3 <name>MIDAS stations example</name>3 <name>MIDAS stations (example)</name> 4 4 <GeoServerRequest> 5 5 <URL>http://bond.badc.rl.ac.uk:8089/dummyGeoServer/GetStationCSMLFeatures?gml_id=MIDAS_Stations</URL> 6 <BalloonTemplate> 7 <img src="http://bond.badc.rl.ac.uk:8089/csmlGrapher/plot?feature_id=$[feature_id]"> 8 </BalloonTemplate> 6 <BalloonTemplate><img src="http://bond.badc.rl.ac.uk:8089/csmlGrapher/plot?feature_id=$[feature_id]"></BalloonTemplate> 9 7 <StationData> 10 8 <Datum name="feature_id">#ID#</Datum>
Note: See TracChangeset
for help on using the changeset viewer.