wiki:TutorialPegelOnline
Last modified 4 years ago Last modified on 07/30/2009 11:57:51 AM

Get current water levels

This tutorial is written for our programming class, which makes use of annotations in KML to retrieve current water levels of German rivers, using the PegelOnline Service. The two KML files attached to this document include geometries of navigable German rivers and points which represent destinations and/or gauge stations. For each point, we have the following extended metadata, encoded as untyped name/value pairs:

 <Placemark>
    <name>Minden</name>
    <ExtendedData>
      <Data name="river">
        <value>Weser</value>
      </Data>
      <Data name="type">
        <value>Gauge</value>
      </Data>
    </ExtendedData>
    <Point>
      <coordinates>8.922667033065519,52.28782810337908,0</coordinates>
    </Point>
 </Placemark>

Dependencies

For using values of Pegelonline service, you need the library for providing the access to this service.

If you use maven, you are basically add the following lines to your POM-file.

<dependency>
  <groupId>de.ifgi.geosoft1</groupId>
  <artifactId>PegelOnline</artifactId>
  <version>0.5_SNAPSHOT</version>
</dependency>

If you don't want to use maven, you need the following library on your classpath

Getting the current water level

Following the tutorial Reading Annotations in the Feature Model, the following line of code will read the name of feature represented by the placemark and checks if it is valid Gauge. If yes, we use the PegelOnline Service to retrieve the current water level. Note: only features which have the gauge parameter have a valid entry in the PegelOnline service, querying others will result in an exception.

// Get the name of the feature
Name harborName = feature.getAnnotation(Name.class);

// list all name/value pairs (keyvalueproperty in our annotation model)
for(KeyValueProperty kvp : f.listAnnotations(KeyValueProperty.class)) {
  if("Gauge".equalsIgnoreCase(kvp.getValue().toString()) {

    // get the current water level
    double val = PegelOnline.getCurrentLevel(harborName.toString());
  }
}

Written by: Henry, pat

Attachments