[Dive4elements-commits] [PATCH 3 of 3] Merged

Wald Commits scm-commit at wald.intevation.org
Tue Apr 2 08:50:45 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1364885904 -7200
# Node ID 33d735f5433e087e1909bf26230e4bc0d487a2c3
# Parent  6dbc111e9aec00be855f9216d672d2a9f7af2af9
# Parent  fcf28185ca30c699c195b03d3fd374033f67feb8
Merged.

diff -r 6dbc111e9aec -r 33d735f5433e .hgtags
--- a/.hgtags	Thu Mar 28 12:11:13 2013 +0100
+++ b/.hgtags	Tue Apr 02 08:58:24 2013 +0200
@@ -37,3 +37,4 @@
 88e3473a38467e8b5bb7d99e92c3f1a795515bf5 2.9.12
 7fa94b793cbe0133503741e142832c8f2ff1aa4b 2.9.13
 a5f5599f6fd5e37975d71b8a323aadfeb8d017e6 2.9.14
+437109b3cf49ce83d5bd4d005c71509e966b8cf7 2.9.15
diff -r 6dbc111e9aec -r 33d735f5433e contrib/make_flys_release/bin/make-importer-package.sh
--- a/contrib/make_flys_release/bin/make-importer-package.sh	Thu Mar 28 12:11:13 2013 +0100
+++ b/contrib/make_flys_release/bin/make-importer-package.sh	Tue Apr 02 08:58:24 2013 +0200
@@ -4,11 +4,9 @@
 # See README for more information
 
 # The working directory. Resulting tarball will be placed in the directory above.
-PKG_DIR=/tmp/flys-importer
-# Default conf
-CONF_DIR=/path/to/conf/dir
+PKG_DIR=~/tmp/flys-importer
 # Path to the flys checkout
-FLYS_DIR=/path/to/flys/root
+FLYS_DIR=~/flys/flys/
 # Tarball that will be extracted into flys-imprter/opt
 EXTRAS=$1
 
@@ -48,7 +46,10 @@
 fi
 
 cp ${FLYS_DIR}/flys-backend/doc/schema/*.sql $PKG_DIR/schema
-cp ${FLYS_DIR}/flys-backend/doc/documentation/de/importer-manual.pdf $PKG_DIR
+
+cd ${FLYS_DIR}/flys-backend/doc/documentation/de/
+make importer-manual.pdf
+cp importer-manual.pdf $PKG_DIR
 
 sed -i 's/shpimporter\/shp/geodaesie\/shp/' $PKG_DIR/run_geo.sh
 
diff -r 6dbc111e9aec -r 33d735f5433e contrib/make_flys_release/make_release.sh
--- a/contrib/make_flys_release/make_release.sh	Thu Mar 28 12:11:13 2013 +0100
+++ b/contrib/make_flys_release/make_release.sh	Tue Apr 02 08:58:24 2013 +0200
@@ -50,7 +50,7 @@
                                    Default: $DEFAULT_WD
    -t                              Tag the current default branch as "VERSION"
    -o, --oracle                    Release is for oracle.
-   VERSION must be in the format MAYOR.MINOR.PATCH
+   VERSION must be in the format MAYOR.MINOR.PATCH or default
 EOF
 exit 0
 }
@@ -80,7 +80,7 @@
 # Backend configuration
 BACKENDURL=${BACKENDURL:-czech-republic.atlas.intevation.de}
 BACKENDPORT=${BACKENDPORT:-5432}
-BACKENDBACK=${BACKENDBACK:-flys_2913}
+BACKENDBACK=${BACKENDBACK:-flys_devel}
 BACKENDUSER=${BACKENDUSER:-flys_dami}
 BACKENDPASS=${BACKENDPASS:-flys_dami}
 INITSQLS=${INITSQLS:-}
@@ -119,7 +119,11 @@
 fi
 
 VERSION=$1
-ARTIFACT_PORT=${ARTIFACT_PORT:-`echo 1$VERSION | sed 's/\.//g'`}
+if [ "$VERSION" = "default" ]; then
+    ARTIFACT_PORT=${ARTIFACT_PORT:-29999}
+else
+    ARTIFACT_PORT=${ARTIFACT_PORT:-`echo 1$VERSION | sed 's/\.//g'`}
+fi
 
 if [ -z $WORK_DIR ]; then
   WORK_DIR=$DEFAULT_WD
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/contrib/inline-dc-attribute.xsl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/contrib/inline-dc-attribute.xsl	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    inline-dc-attribute.xsl
+    =======================
+    Transforms datacage templates from:
+
+        <foo>
+          <dc:element name="bar" value="${baz}"/>
+          <dc:element name="bla" value="${blub}-${urgs}"/>
+        </foo>
+
+    to:
+
+        <foo bar="{$bar} bla="{$blub}-{$urgs}/>
+-->
+<xsl:stylesheet version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:dc="http://www.intevation.org/2011/Datacage">
+
+  <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
+
+  <xsl:template name="string-replace-all">
+    <xsl:param name="text"/>
+    <xsl:param name="replace"/>
+    <xsl:param name="by"/>
+    <xsl:choose>
+      <xsl:when test="contains($text, $replace)">
+        <xsl:value-of select="substring-before($text,$replace)"/>
+        <xsl:value-of select="$by"/>
+        <xsl:call-template name="string-replace-all">
+          <xsl:with-param name="text" select="substring-after($text,$replace)"/>
+          <xsl:with-param name="replace" select="$replace"/>
+          <xsl:with-param name="by" select="$by"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$text"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template
+    match="node()[count(dc:attribute) > 0 and namespace-uri() != 'http://www.intevation.org/2011/Datacage']">
+    <xsl:copy>
+      <xsl:for-each select="./dc:attribute">
+        <xsl:attribute name="{@name}">
+          <xsl:call-template name="string-replace-all">
+            <xsl:with-param name="text" select="@value"/>
+            <xsl:with-param name="replace">${</xsl:with-param>
+            <xsl:with-param name="by">{$</xsl:with-param>
+          </xsl:call-template>
+        </xsl:attribute>
+      </xsl:for-each>
+      <xsl:apply-templates select="@*|node()" mode="ignore-text"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="dc:attribute|text()" mode="ignore-text"/>
+  <xsl:template match="@*|node()" mode="ignore-text">
+    <xsl:copy>
+      <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="@*|node()">
+    <xsl:copy>
+      <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+  </xsl:template>
+
+</xsl:stylesheet>
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/doc/conf/artifacts/sqrelation.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/doc/conf/artifacts/sqrelation.xml	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<artifact name="staticsqrelation">
+    <states>
+         <state id="state.sqrelation.static" description="state.sqrelation.static" state="de.intevation.flys.artifacts.states.sq.SQStaticState">
+            <data name="river" type="String" />
+            <data name="station" type="String" />
+            <outputmodes>
+                <outputmode name="sq_relation_a" description="output.sq_relation" type="chart">
+                    <facets>
+                        <facet name="sq_a_curve" description="A facet for sq curve"/>
+                        <facet name="sq_relation_a.manualpoints" />
+                    </facets>
+                </outputmode>
+                <outputmode name="sq_relation_b" description="output.sq_relation" type="chart">
+                    <facets>
+                        <facet name="sq_b_curve" description="A facet for sq curve"/>
+                        <facet name="sq_relation_b.manualpoints" />
+                    </facets>
+                </outputmode>
+                <outputmode name="sq_relation_c" description="output.sq_relation" type="chart">
+                    <facets>
+                        <facet name="sq_c_curve" description="A facet for sq curve"/>
+                        <facet name="sq_relation_c.manualpoints" />
+                    </facets>
+                </outputmode>
+                <outputmode name="sq_relation_d" description="output.sq_relation" type="chart">
+                    <facets>
+                        <facet name="sq_d_curve" description="A facet for sq curve"/>
+                        <facet name="sq_relation_d.manualpoints" />
+                    </facets>
+                </outputmode>
+                <outputmode name="sq_relation_e" description="output.sq_relation" type="chart">
+                    <facets>
+                        <facet name="sq_e_curve" description="A facet for sq curve"/>
+                        <facet name="sq_relation_e.manualpoints" />
+                    </facets>
+                </outputmode>
+                <outputmode name="sq_relation_f" description="output.sq_relation" type="chart">
+                    <facets>
+                        <facet name="sq_relation_f.manualpoints" />
+                        <facet name="sq_f_curve" description="A facet for sq curve"/>
+                    </facets>
+                </outputmode>
+                <outputmode name="sq_overview" description="output.sq_overview" type="overview">
+                    <facets>
+                        <facet name="sq_chart_overview" description="A facet for sq chart overview"/>
+                    </facets>
+                </outputmode>
+                <outputmode name="sqrelation_export" description="output.sqrelation_export" mime-type="text/plain" type="export">
+                    <facets>
+                        <facet name="csv" description="facet.sqrelation_export.csv" />
+                        <facet name="pdf" description="facet.sqrelation_export.pdf" />
+                    </facets>
+                </outputmode>
+            </outputmodes>
+         </state>
+    </states>
+</artifact>
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/doc/conf/conf.xml
--- a/flys-artifacts/doc/conf/conf.xml	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/doc/conf/conf.xml	Tue Apr 02 08:58:24 2013 +0200
@@ -122,6 +122,9 @@
             <artifact-factory name="bedheight" description="Factory to create an artifact used in minfo datacage."
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.BedHeightsArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+            <artifact-factory name="staticsqrelation" description="Factory to create an artifact that generates sq relations from db."
+                ttl="3600000"
+                artifact="de.intevation.flys.artifacts.SQRelationArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
 
             <artifact-factory name="gaugedischargecurve" description="Factory to create an artifact to show a discharge curve for a gauge."
                 ttl="3600000"
@@ -251,6 +254,7 @@
         <artifact name="gaugedischarge" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/gaugedischarge.xml" />
         <artifact name="gaugedischargecurve" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/gaugedischargecurve.xml" />
         <artifact name="qsector" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/qsector.xml" />
+        <artifact name="staticsqrelation" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/sqrelation.xml" />
     </artifacts>
 
     <modules>
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/doc/conf/meta-data.xml
--- a/flys-artifacts/doc/conf/meta-data.xml	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/doc/conf/meta-data.xml	Tue Apr 02 08:58:24 2013 +0200
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <dc:template xmlns:dc="http://www.intevation.org/2011/Datacage">
 <datacage>
   <dc:comment>
@@ -36,13 +36,13 @@
                  COALESCE(ld_from, '')      AS ldf,
                  COALESCE(ld_to, '')        AS ldt
           FROM master_artifacts_range
-          WHERE gid = CAST(${artifact-id} as uuid)
+          WHERE gid = CAST(${artifact-id} AS uuid)
         </dc:statement>
-        <dc:elements>
+        <dc:for-each>
           <dc:variable name="fromkm" type="number" expr="dc:fromValue($ldm, $ldl, $ldf)"/>
           <dc:variable name="tokm" type="number" expr="dc:toValue($ldm, $ldl, $ldt)"/>
           <dc:macro-body/>
-        </dc:elements>
+        </dc:for-each>
         </dc:context>
       </dc:when>
       <dc:otherwise>
@@ -59,10 +59,10 @@
   <dc:macro name="load-system">
     <dc:context connection="system">
       <dc:statement>
-        SELECT id AS river_id, name as river_name FROM rivers
+        SELECT id AS river_id, name AS river_name FROM rivers
         WHERE lower(name) LIKE lower(${river})
       </dc:statement>
-      <dc:elements>
+      <dc:for-each>
 
         <dc:comment>
           Base-data macros (mostly data imported from wst-files).
@@ -77,22 +77,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 0 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <basedata>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <basedata name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="base_data-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="base_data-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </basedata>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </basedata>
           </dc:call-macro>
@@ -108,22 +105,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 0 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <basedata>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <basedata name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="base_data-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="wqinterpol"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="base_data-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </basedata>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </basedata>
           </dc:call-macro>
@@ -139,22 +133,18 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <additional>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <additional name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="additionalsmarks-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
-                    </dc:context>
-                  </additional>
-                </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="additionalsmarks-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
+                    </dc:context></additional>
+                </dc:for-each>
               </dc:context>
             </additionals>
           </dc:call-macro>
@@ -170,22 +160,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <additional>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <additional name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="additionals-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="additionals-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </additional>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </additionals>
           </dc:call-macro>
@@ -201,22 +188,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <relativepoint name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="additionals-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="additionals-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </relativepoint>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </additionals>
           </dc:call-macro>
@@ -231,23 +215,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <fixation>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <!--dc:attribute name="ids" value="fixations-wstv-A-${prot_id}"/-->
-                    <dc:context>
+                <dc:for-each>
+                  <fixation name="{$prot_description}">
+                    <!--dc:attribute name="ids" value="fixations-wstv-A-${prot_id}"/--><dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="wqinterpol"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </fixation>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </fixations>
           </dc:call-macro>
@@ -262,22 +242,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <fixation>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <fixation name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="wqinterpol"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </fixation>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </fixations>
           </dc:call-macro>
@@ -292,22 +269,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <fixation>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <fixation name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </fixation>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </fixations>
           </dc:call-macro>
@@ -322,22 +296,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <relativepoint name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </relativepoint>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </fixations>
           </dc:call-macro>
@@ -353,22 +324,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 3 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <official>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <official name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="additionals-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwqkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="additionals-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwqkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </official>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </officiallines>
           </dc:call-macro>
@@ -383,22 +351,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <relativepoint name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="heightmarks_points-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="heightmarks_points-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </relativepoint>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </heightmarks>
           </dc:call-macro>
@@ -413,22 +378,19 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <heightmark>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                <dc:for-each>
+                  <heightmark name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="heightmarks_points-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="heightmarks_points-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </heightmark>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </heightmarks>
           </dc:call-macro>
@@ -443,22 +405,18 @@
                          description AS prot_description
                   FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <heightmark>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:context>
+                <dc:for-each>
+                  <heightmark name="{$prot_description}"><dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="heightmarks_annotations-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="wqinterpol"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="heightmarks_annotations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </heightmark>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </heightmarks>
           </dc:call-macro>
@@ -466,129 +424,98 @@
 
         <dc:macro name="basedata_5_flood-protections_relative_points">
           <dc:call-macro name="user-range">
-            <flood_protections>
-              <dc:attribute name="id" value="flood-protections-${river_id}"/>
+            <flood_protections id="flood-protections-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT id          AS prot_id,
                          description AS prot_description
                   FROM wsts WHERE kind = 5 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:attribute name="db-id" value="${prot_id}"/>
-                    <dc:attribute name="factory" value="staticwkms"/>
-                    <columns>
+                <dc:for-each>
+                  <relativepoint name="{$prot_description}"
+                                 db-id="{$prot_id}"
+                                 factory="staticwkms">
+                  <columns>
                       <dc:context>
                         <dc:call-macro name="SQL-wst_columns_statement"/>
-                        <dc:elements>
-                          <column>
-                            <dc:attribute name="name" value="${prot_column_name}"/>
-                            <dc:attribute name="ids" value="flood_protection-wstv-${prot_rel_pos}-${prot_id}"/>
-                            <dc:attribute name="factory" value="staticwkms"/>
-                            <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                          </column>
-                        </dc:elements>
+                        <dc:for-each>
+                          <column name="{$prot_column_name}"
+                                  ids="flood_protection-wstv-{$prot_rel_pos}-{$prot_id}"
+                                  factory="staticwkms"
+                                  info="{$info} [km {$deffrom} - {$defto}]"/>
+                        </dc:for-each>
                       </dc:context>
                     </columns>
                   </relativepoint>
-                </dc:elements>
-              </dc:context>
-            </flood_protections>
+                </dc:for-each>
+              </dc:context></flood_protections>
           </dc:call-macro>
         </dc:macro>
 
         <dc:macro name="basedata_5_flood-protections">
           <dc:call-macro name="user-range">
-            <flood_protections>
-              <dc:attribute name="id" value="flood-protections-${river_id}"/>
+            <flood_protections id="flood-protections-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT id          AS prot_id,
                          description AS prot_description
                   FROM wsts WHERE kind = 5 AND river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <flood_protection>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:attribute name="db-id" value="${prot_id}"/>
-                    <dc:attribute name="factory" value="staticwkms"/>
+                <dc:for-each>
+                  <flood_protection name="{$prot_description}"
+                                    db-id="{$prot_id}"
+                                    factory="staticwkms">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
-                      <dc:elements>
-                        <column>
-                          <dc:attribute name="name" value="${prot_column_name}"/>
-                          <dc:attribute name="ids" value="flood_protection-wstv-${prot_rel_pos}-${prot_id}"/>
-                          <dc:attribute name="factory" value="staticwkms"/>
-                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
-                        </column>
-                      </dc:elements>
+                      <dc:for-each>
+                        <column name="{$prot_column_name}"
+                                ids="flood_protection-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
+                      </dc:for-each>
                     </dc:context>
                   </flood_protection>
-                </dc:elements>
+                </dc:for-each>
               </dc:context>
             </flood_protections>
           </dc:call-macro>
         </dc:macro>
 
         <dc:macro name="mainvalues">
-          <mainvalue>
-            <dc:attribute name="factory" value="mainvalue"/>
-            <dc:attribute name="ids"     value="${river_id}"/>
-          </mainvalue>
-          <wmainvalue>
-            <dc:attribute name="factory" value="mainvalue"/>
-            <dc:attribute name="ids"     value="${river_id}:w"/>
-          </wmainvalue>
-          <qmainvalue>
-            <dc:attribute name="factory" value="mainvalue"/>
-            <dc:attribute name="ids"     value="${river_id}:q"/>
-          </qmainvalue>
+          <mainvalue factory="mainvalue" ids="{$river_id}"/>
+          <wmainvalue factory="mainvalue" ids="{$river_id}:w"/>
+          <qmainvalue factory="mainvalue" ids="{$river_id}:q"/>
         </dc:macro>
 
         <dc:macro name="qsectors">
-          <qsector>
-            <dc:attribute name="factory" value="qsectors"/>
-            <dc:attribute name="ids"     value="${river_id}"/>
-          </qsector>
+          <qsector factory="qsectors" ids="{$river_id}"/>
         </dc:macro>
 
         <dc:macro name="annotations">
-          <annotation>
-            <dc:attribute name="factory" value="annotations"/>
-            <dc:attribute name="ids"     value="${river_id}"/>
-          </annotation>
+          <annotation factory="annotations" ids="{$river_id}"/>
         </dc:macro>
 
         <dc:macro name="annotations_per_type">
           <annotations>
             <dc:context>
-              <annotation>
-                <dc:attribute name="name"    value="all_annotations"/>
-                <dc:attribute name="factory" value="annotations"/>
-                <dc:attribute name="ids"     value="${river_id}"/>
-              </annotation>
+              <annotation name="all_annotations" factory="annotations" ids="{$river_id}"/>
               <dc:statement>
                 SELECT id          AS anno_id,
                        name AS anno_description
                 FROM annotation_types
               </dc:statement>
-              <dc:elements>
-                <annotation>
-                  <dc:attribute name="name"    value="${anno_description}"/>
-                  <dc:attribute name="factory" value="annotations"/>
-                  <dc:attribute name="ids"     value="${river_id}:${anno_description}"/>
-                </annotation>
-             </dc:elements>
+              <dc:for-each>
+                <annotation name="{$anno_description}"
+                            factory="annotations"
+                            ids="{$river_id}:{$anno_description}"/>
+             </dc:for-each>
             </dc:context>
           </annotations>
         </dc:macro>
 
         <dc:macro name="cross_sections">
           <dc:call-macro name="user-range">
-            <cross_sections>
-              <dc:attribute name="id" value="flood-protections-${river_id}"/>
+            <cross_sections id="flood-protections-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT DISTINCT
@@ -599,13 +526,11 @@
                   WHERE cs.river_id = ${river_id}
                     AND csl.km BETWEEN ${fromkm} AND ${tokm}
                 </dc:statement>
-                <dc:elements>
-                  <cross_section>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:attribute name="ids" value="${prot_id}"/>
-                    <dc:attribute name="factory" value="crosssections"/>
-                  </cross_section>
-                </dc:elements>
+                <dc:for-each>
+                  <cross_section name="{$prot_description}"
+                                 ids="{$prot_id}"
+                                 factory="crosssections"/>
+                </dc:for-each>
               </dc:context>
             </cross_sections>
           </dc:call-macro>
@@ -613,8 +538,7 @@
 
         <dc:macro name="hyks">
           <dc:call-macro name="user-range">
-            <hyks>
-              <dc:attribute name="id" value="hyk-${river_id}"/>
+            <hyks id="hyk-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT DISTINCT
@@ -625,52 +549,44 @@
                   WHERE river_id = ${river_id}
                     AND he.km BETWEEN ${fromkm} AND ${tokm}
                 </dc:statement>
-                <dc:elements>
-                  <hyk>
-                    <dc:attribute name="name" value="${hyk_description}"/>
-                    <dc:attribute name="ids" value="${hyk_id}"/>
-                    <dc:attribute name="factory" value="hyk"/>
-                  </hyk>
-                </dc:elements>
-              </dc:context>
-            </hyks>
+                <dc:for-each>
+                  <hyk name="{$hyk_description}" ids="{$hyk_id}" factory="hyk"/>
+                </dc:for-each>
+              </dc:context></hyks>
           </dc:call-macro>
         </dc:macro>
 
         <dc:macro name="flow_velocity_measurements">
           <dc:call-macro name="user-range">
             <flowvelocitymeasurement>
-            <dc:context connection="system">
+              <dc:context connection="system">
                 <dc:statement>
                   SELECT id          AS fvmid,
                          description AS fvmd
                   FROM flow_velocity_measurements WHERE river_id = ${river_id}
                 </dc:statement>
-                <dc:elements>
-                  <flow_velocity_measurement>
-                    <dc:attribute name="name" value="${fvmd}"/>
-                    <dc:attribute name="ids" value="${fvmid}"/>
-                    <dc:attribute name="factory" value="flowvelocity"/>
+                <dc:for-each>
+                  <flow_velocity_measurement name="{$fvmd}"
+                                             ids="{$fvmid}"
+                                             factory="flowvelocity">
                     <dc:context>
-                        <dc:statement>
-                                SELECT id, description, station, datetime, v, w, q
-                                FROM flow_velocity_measure_values
-                                WHERE measurements_id = ${fvmid}
-                                  AND station BETWEEN ${fromkm} AND ${tokm}
-                        </dc:statement>
-                        <dc:elements>
-                           <measurement_value>
-                             <dc:attribute name="name" value="${id}-${description}-${station}-${datetime}"/>
-                             <dc:attribute name="ids" value="${id}"/>
-                             <dc:attribute name="factory" value="flowvelocity"/>
-                           </measurement_value>
-                         </dc:elements>
+                      <dc:statement>
+                        SELECT id, description, station, datetime, v, w, q
+                        FROM flow_velocity_measure_values
+                        WHERE measurements_id = ${fvmid}
+                          AND station BETWEEN ${fromkm} AND ${tokm}
+                      </dc:statement>
+                      <dc:for-each>
+                        <measurement_value name="{$id}-{$description}-{$station}-{$datetime}"
+                                           ids="{$id}"
+                                           factory="flowvelocity"/>
+                      </dc:for-each>
                     </dc:context>
                   </flow_velocity_measurement>
-              </dc:elements>
-          </dc:context>
-          </flowvelocitymeasurement>
-        </dc:call-macro>
+                </dc:for-each>
+              </dc:context>
+            </flowvelocitymeasurement>
+          </dc:call-macro>
         </dc:macro>
 
         <dc:macro name="sounding-width">
@@ -682,13 +598,11 @@
                          description AS bedh_descr
                   FROM bed_height_single WHERE river_id = ${river_id}
               </dc:statement>
-              <dc:elements>
-                <height>
-                  <dc:attribute name="factory" value="bedheight"/>
-                  <dc:attribute name="ids" value="bedheight-singlevalues-${bedh_id}-${bedh_year}"/>
-                  <dc:attribute name="description" value="${bedh_descr}"/>
-                </height>
-              </dc:elements>
+              <dc:for-each>
+                <height factory="bedheight"
+                        ids="bedheight-singlevalues-{$bedh_id}-{$bedh_year}"
+                        description="{$bedh_descr}"/>
+              </dc:for-each>
             </dc:context>
           </soundings_width>
         </dc:macro>
@@ -824,7 +738,6 @@
           </dc:otherwise>
         </dc:choose>
 
-
         <dc:if test="dc:contains($artifact-outs, 'waterlevels')">
 
           <!-- base data -->
@@ -843,28 +756,31 @@
           <dc:call-macro name="basedata_5_flood-protections"/>
 
         </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve') and (dc:contains($parameters, 'recommended'))">
-              <!--dc:call-macro name="basedata_2_fixations_wst"/-->
-        </dc:if>
+
+        <dc:comment><!-- XXX: Why is this taken out?
+          <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve') and (dc:contains($parameters, 'recommended'))">
+             <dc:call-macro name="basedata_2_fixations_wst"/>
+           </dc:if>
+           -->
+        </dc:comment>
 
         <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve') and not (dc:contains($parameters, 'recommended'))">
-            <discharge_table_nn>
-              <discharge_table_gauge>
-                <dc:context>
-                  <dc:statement>
-                    SELECT id   AS gauge_id,
-                           name AS gauge_name
-                    FROM gauges WHERE river_id = ${river_id}
-                  </dc:statement>
-                  <dc:elements>
-                    <gauge>
-                      <dc:attribute name="name" value="${gauge_name}"/>
-                      <dc:attribute name="db-id" value="${gauge_id}"/>
-                      <dc:attribute name="factory" value="gaugedischarge"/>
-                      <dc:attribute name="from" value="${g_start}"/>
-                      <dc:attribute name="to" value="${g_stop}"/>
-                      <dc:attribute name="ids" value="${gauge_name}"/>
-                    </gauge>
+          <discharge_table_nn>
+            <discharge_table_gauge>
+              <dc:context>
+                <dc:statement>
+                  SELECT id   AS gauge_id,
+                         name AS gauge_name
+                  FROM gauges WHERE river_id = ${river_id}
+                </dc:statement>
+                <dc:for-each>
+                  <gauge name="{$gauge_name}"
+                         db-id="{$gauge_id}"
+                         factory="gaugedischarge"
+                         from="{$g_start}"
+                         to="{$g_stop}"
+                         ids="{$gauge_name}"/>
+                  <dc:comment>
                     <!--
                     <gauge>
                       <dc:attribute name="name" value="${gauge_name}"/>
@@ -879,7 +795,7 @@
                           ON d.time_interval_id = ti.id
                           WHERE d.gauge_id = ${gauge_id} AND d.kind = 1
                         </dc:statement>
-                        <dc:elements>
+                        <dc:for-each>
                           <historical>
                             <dc:attribute name="name" value="${gauge_desc}"/>
                             <dc:attribute name="factory" value="gaugedischarge"/>
@@ -887,15 +803,15 @@
                             <dc:attribute name="to" value="${g_stop}"/>
                             <dc:attribute name="ids" value="${discharge_id}-${g_start}-${g_stop}"/>
                           </historical>
-                        </dc:elements>
+                        </dc:for-each>
                       </dc:context>
                     </gauge>
-                    -->
-                  </dc:elements>
-                </dc:context>
-              </discharge_table_gauge>
-
-            </discharge_table_nn>
+                  -->
+                  </dc:comment>
+                </dc:for-each>
+              </dc:context>
+            </discharge_table_gauge>
+          </discharge_table_nn>
 
           <dc:call-macro name="basedata_2_fixations_wst"/>
 
@@ -914,680 +830,671 @@
         </dc:if>
 
         <dc:if test="dc:contains($artifact-outs, 'fix_wq_curve') and not (dc:contains($parameters, 'recommended'))">
-            <discharge_table_nn>
-              <discharge_table_gauge>
-                <dc:context>
-                  <dc:statement>
-                    SELECT id   AS gauge_id,
-                           name AS gauge_name
-                    FROM gauges WHERE river_id = ${river_id}
-                  </dc:statement>
-                  <dc:elements>
-                    <gauge>
-                      <dc:attribute name="name" value="${gauge_name}"/>
-                      <dc:attribute name="db-id" value="${gauge_id}"/>
-                      <dc:attribute name="factory" value="gaugedischarge"/>
-                      <dc:attribute name="from" value="${g_start}"/>
-                      <dc:attribute name="to" value="${g_stop}"/>
-                      <dc:attribute name="ids" value="${gauge_name}"/>
-                    </gauge>
-                  </dc:elements>
-                </dc:context>
-              </discharge_table_gauge>
-            </discharge_table_nn>
+          <discharge_table_nn>
+            <discharge_table_gauge>
+              <dc:context>
+                <dc:statement>
+                  SELECT id   AS gauge_id,
+                         name AS gauge_name
+                  FROM gauges WHERE river_id = ${river_id}
+                </dc:statement>
+                <dc:for-each>
+                  <gauge name="{$gauge_name}"
+                         db-id="{$gauge_id}"
+                         factory="gaugedischarge"
+                         from="{$g_start}"
+                         to="{$g_stop}"
+                         ids="{$gauge_name}"/>
+                </dc:for-each>
+              </dc:context>
+            </discharge_table_gauge>
+          </discharge_table_nn>
         </dc:if>
 
         <dc:if test="dc:contains($artifact-outs, 'floodmap') or dc:contains($artifact-outs, 'floodmap-hws')">
-            <floodmap>
+          <floodmap>
             <dc:choose>
-                <dc:when test="dc:contains($parameters, 'recommended')">
-                  <dc:call-macro name="flood-map-recommended"/>
-                </dc:when>
-                <dc:when test="dc:contains($parameters, 'dem')">
-                  <dc:call-macro name="flood-map-dem"/>
-                </dc:when>
-                <dc:otherwise>
-                  <dc:call-macro name="flood-map-complete"/>
-                </dc:otherwise>
+              <dc:when test="dc:contains($parameters, 'recommended')">
+                <dc:call-macro name="flood-map-recommended"/>
+              </dc:when>
+              <dc:when test="dc:contains($parameters, 'dem')">
+                <dc:call-macro name="flood-map-dem"/>
+              </dc:when>
+              <dc:otherwise>
+                <dc:call-macro name="flood-map-complete"/>
+              </dc:otherwise>
             </dc:choose>
-            </floodmap>
-            <dc:if test="dc:contains($parameters, 'hws')">
-              <hws>
-                <dc:call-macro name="flood-map-hws-lines" />
-                <dc:call-macro name="flood-map-hws-points" />
-              </hws>
-            </dc:if>
+          </floodmap>
 
-            <dc:macro name="flood-map-recommended">
-              <dc:comment>
-                 FIXME: Following two macros look identical to me.
-              </dc:comment>
-                <kilometrage>
-                    <riveraxis>
-                        <dc:attribute name="factory" value="riveraxis"/>
-                        <dc:attribute name="ids" value="${river_id}"/>
-                    </riveraxis>
-                </kilometrage>
-                <rastermap>
-                    <background>
-                        <dc:attribute name="factory" value="wmsbackground"/>
-                        <dc:attribute name="ids" value="${river_id}"/>
-                    </background>
-                </rastermap>
+          <dc:if test="dc:contains($parameters, 'hws')">
+            <hws>
+              <dc:call-macro name="flood-map-hws-lines"/>
+              <dc:call-macro name="flood-map-hws-points"/>
+            </hws>
+          </dc:if>
+
+          <dc:macro name="flood-map-recommended">
+            <dc:comment>
+               FIXME: Following two macros look identical to me.
+            </dc:comment>
+            <kilometrage>
+              <riveraxis factory="riveraxis" ids="{$river_id}"/>
+            </kilometrage>
+            <rastermap>
+              <background factory="wmsbackground" ids="{$river_id}"/>
+            </rastermap>
+          </dc:macro>
+
+          <dc:macro name="flood-map-dem">
+            <dems>
+              <dc:context>
+                <dc:statement>
+                  SELECT d.id    AS dem_id,
+                         r.a     AS dem_lower,
+                         r.b     AS dem_upper,
+                         d.name  AS name,
+                         d.projection || ' | ' || t.start_time || ' - ' || t.stop_time AS info
+                         FROM dem d
+                         JOIN ranges r ON d.range_id = r.id
+                         JOIN time_intervals t ON d.time_interval_id = t.id
+                         WHERE d.river_id = ${river_id}
+                </dc:statement>
+                <dc:for-each>
+                    <dem factory="demfactory" ids="{$dem_id}" name="{$name}" info="{$info}"/>
+                </dc:for-each>
+              </dc:context>
+            </dems>
+          </dc:macro>
+
+          <dc:macro name="filter_hws_ddg">
+            <dc:macro name="durchlass_damm_graben">
+              <dc:macro name="ddg_factory">
+                <dc:for-each>
+                  <hws factory="hwsfactory" name="{$hws_name}"/>
+                </dc:for-each>
+              </dc:macro>
+
+              <dc:filter expr="$kws_kind=1">
+                <dc:if test="dc:has-result()">
+                  <Durchlass><dc:call-macro name="ddg_factory"/></Durchlass>
+                </dc:if>
+              </dc:filter>
+
+              <dc:filter expr="$kws_kind=2">
+                <dc:if test="dc:has-result()">
+                  <Damm><dc:call-macro name="ddg_factory"/></Damm>
+                </dc:if>
+              </dc:filter>
+
+              <dc:filter expr="$kws_kind=3">
+                <dc:if test="dc:has-result()">
+                  <Graben><dc:call-macro name="ddg_factory"/></Graben>
+                </dc:if>
+              </dc:filter>
             </dc:macro>
-            <dc:macro name="flood-map-dem">
-              <dems>
+
+            <dc:filter expr="$hws_official=1">
+              <dc:if test="dc:has-result()">
+                <official>
+                  <dc:call-macro name="durchlass_damm_graben"/>
+                </official>
+              </dc:if>
+            </dc:filter>
+
+            <dc:filter expr="$hws_official=0">
+              <dc:if test="dc:has-result()">
+                <inofficial>
+                  <dc:call-macro name="durchlass_damm_graben"/>
+                </inofficial>
+              </dc:if>
+            </dc:filter>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hws-lines">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                       name     AS hws_name,
+                       official AS hws_official,
+                       kind_id  AS hws_kind
+                FROM hws_lines
+                WHERE river_id = ${river_id}
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <lines>
+                  <dc:call-macro name="filter_hws_ddg"/>
+                </lines>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hws-points">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                       name     AS hws_name,
+                       official AS hws_official,
+                       kind_id  AS hws_kind
+                FROM hws_points
+                WHERE river_id = ${river_id}
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <points>
+                  <dc:call-macro name="filter_hws_ddg"/>
+                </points>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-km">
+            <dc:context>
+              <dc:statement>
+                SELECT count(*) AS km_exists
+                FROM river_axes_km WHERE river_id = ${river_id}
+              </dc:statement>
+               <dc:for-each>
+                <dc:if test="$km_exists>0">
+                  <kilometrage factory="wmskmfactory" ids="{$river_id}"/>
+                </dc:if>
+              </dc:for-each>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-qps">
+            <dc:context>
+              <dc:comment>Grab only the actual first</dc:comment>
+              <dc:statement>
+                SELECT DISTINCT
+                cs.kind_id AS kind_id,
+                ck.name AS kind_name
+                FROM cross_section_tracks cs
+                JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
+                WHERE river_id = ${river_id}
+                AND kind_id=1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <dc:for-each>
+                  <actual description="{$kind_name}"
+                          factory="wmsqpsfactory"
+                          ids="{$river_id};{$kind_name};{$kind_id}"/>
+                </dc:for-each>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:comment>Now the other tracks</dc:comment>
+              <dc:statement>
+                SELECT DISTINCT
+                cs.kind_id AS kind_id,
+                ck.name AS kind_name,
+                cs.name AS layer_name
+                FROM cross_section_tracks cs
+                JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
+                WHERE river_id = ${river_id}
+                AND kind_id=0
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <other>
+                  <dc:for-each>
+                    <misc-qps description="{$layer_name}"
+                              factory="wmsqpsfactory"
+                              ids="{$river_id};{$layer_name};{$kind_id}"/>
+                  </dc:for-each>
+                </other>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-riveraxis">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                ax.kind_id AS kind_id,
+                ak.name AS kind_name
+                FROM river_axes ax
+                JOIN axis_kinds ak on ax.kind_id = ak.id
+                WHERE river_id = ${river_id}
+                AND kind_id=1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <dc:for-each>
+                  <actual description="{$kind_name}"
+                          ids="{$river_id};{$kind_name};{$kind_id}"
+                          factory="riveraxis"/>
+                </dc:for-each>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                ak.name AS kind_name,
+                ax.kind_id AS kind_id,
+                ax.name AS layer_name
+                FROM river_axes ax
+                JOIN axis_kinds ak on ax.kind_id = ak.id
+                WHERE river_id = ${river_id}
+                AND kind_id <> 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <other>
+                  <dc:for-each>
+                    <misc-axis description="{$layer_name}"
+                               ids="{$river_id};{$layer_name};{$kind_id}"
+                               factory="riveraxis"/>
+                  </dc:for-each>
+                </other>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries-state">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                name
+                FROM hydr_boundaries
+                WHERE river_id = ${river_id}
+                AND kind = 2
+              </dc:statement>
+              <dc:for-each>
+                <line factory="wmshydrboundariesfactory" 
+                      ids="{$river_id};{$name};2"
+                      name="{$name}"/>
+              </dc:for-each>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                name
+                FROM hydr_boundaries_poly
+                WHERE river_id = ${river_id}
+                AND kind = 2
+              </dc:statement>
+              <dc:for-each>
+                <line factory="wmshydrboundariespolyfactory"
+                      ids="{$river_id};{$name};2"
+                      name="{$name}"/>
+              </dc:for-each>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries-lines">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                name
+                FROM hydr_boundaries
+                WHERE river_id = ${river_id}
+                AND kind = 1
+              </dc:statement>
+              <dc:comment> What about all other line kinds?</dc:comment>
+              <dc:if test="dc:has-result()">
+                <lines>
+                  <dc:for-each>
+                    <line factory="wmshydrboundariesfactory"
+                          ids="{$river_id};{$name};1"
+                          name="{$name}"/>
+                  </dc:for-each>
+                </lines>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries-poly">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                b.sectie AS sectie_id,
+                sk.name AS sectie
+                FROM hydr_boundaries_poly b
+                JOIN sectie_kinds sk ON b.sectie = sk.id
+                WHERE b.river_id = ${river_id}
+                AND b.kind = 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <sobek_areas>
+                  <dc:for-each>
+                    <boundary name="{$sectie}"
+                              factory="wmshydrboundariespolyfactory"
+                              ids="{$river_id};{$sectie};1;{$sectie_id};-1"/>
+                  </dc:for-each>
+                </sobek_areas>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                b.sobek AS sobek_id,
+                sk.name AS sobek
+                FROM hydr_boundaries_poly b
+                JOIN sobek_kinds sk ON b.sobek = sk.id
+                WHERE b.river_id = ${river_id}
+                AND b.kind = 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <sobek_flooded>
+                  <dc:for-each>
+                    <boundary name="{$sobek}"
+                              factory="wmshydrboundariespolyfactory"
+                              ids="{$river_id};{$sobek};1;-1;{$sobek_id}"/>
+                  </dc:for-each>
+                </sobek_flooded>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries">
+            <bfg_model>
+              <areas>
+                <dc:call-macro name="flood-map-hydr-boundaries-poly"/>
+              </areas>
+              <dc:call-macro name="flood-map-hydr-boundaries-lines"/>
+            </bfg_model>
+            <federal>
+              <dc:call-macro name="flood-map-hydr-boundaries-state"/>
+            </federal>
+          </dc:macro>
+
+          <dc:macro name="flood-map-floodplain">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                fp.kind_id AS kind_id,
+                flk.name AS kind_name
+                FROM floodplain fp
+                JOIN floodplain_kinds flk on fp.kind_id = flk.id
+                WHERE river_id = ${river_id}
+                AND kind_id=1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <dc:for-each>
+                  <floody factory="wmsfloodplainfactory"
+                          description="{$kind_name}"
+                          ids="{$river_id};{$kind_name};{$kind_id}"/>
+                </dc:for-each>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                flk.name AS kind_name,
+                fp.kind_id AS kind_id,
+                fp.name AS layer_name
+                FROM floodplain fp
+                JOIN floodplain_kinds flk on fp.kind_id = flk.id
+                WHERE river_id = ${river_id}
+                AND kind_id <> 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <other>
+                  <dc:for-each>
+                    <floody factory="wmsfloodplainfactory"
+                            description="{$layer_name}"
+                            ids="{$river_id};{$layer_name};{$kind_id}"/>
+                  </dc:for-each>
+                </other>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="hwslines_by_kind">
+            <dc:comment>
+              Call from a context where fed_name hws_kind hws_name and river_id is
+              availble
+            </dc:comment>
+
+            <dc:macro name="hwslines_by_kind_factory">
+              <dc:for-each>
+                <hws factory="wmshwslinesfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
+            </dc:macro>
+
+            <dc:filter expr="$hws_kind=1">
+              <dc:if test="dc:has-result()">
+                <Durchlass>
+                  <dc:call-macro name="hwslines_by_kind_factory"/>
+                </Durchlass>
+              </dc:if>
+            </dc:filter>
+
+            <dc:filter expr="$hws_kind=2">
+              <dc:if test="dc:has-result()">
+                <Damm>
+                  <dc:call-macro name="hwslines_by_kind_factory"/>
+                </Damm>
+              </dc:if>
+            </dc:filter>
+
+            <dc:filter expr="$hws_kind=3">
+              <dc:if test="dc:has-result()">
+                <Graben>
+                  <dc:call-macro name="hwslines_by_kind_factory"/>
+                </Graben>
+              </dc:if>
+            </dc:filter>
+          </dc:macro>
+
+          <dc:macro name="hwslines">
+            <hws_lines>
+              <official>
                 <dc:context>
                   <dc:statement>
-                    SELECT d.id    AS dem_id,
-                           r.a     AS dem_lower,
-                           r.b     AS dem_upper,
-                           d.name  AS name,
-                           d.projection || ' | ' || t.start_time || ' - ' || t.stop_time AS info
-                           FROM dem d
-                           JOIN ranges r ON d.range_id = r.id
-                           JOIN time_intervals t ON d.time_interval_id = t.id
-                           WHERE d.river_id = ${river_id}
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_lines hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=1
                   </dc:statement>
-                  <dc:elements>
-                      <dem>
-                        <dc:attribute name="factory" value="demfactory"/>
-                        <dc:attribute name="ids" value="${dem_id}"/>
-                        <dc:attribute name="name" value="${name}"/>
-                        <dc:attribute name="info" value="${info}"/>
-                      </dem>
-                  </dc:elements>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_lines
+                        WHERE river_id = ${river_id}
+                        AND official=1
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwslines_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
                 </dc:context>
-              </dems>
-            </dc:macro>
-            <dc:macro name="flood-map-hws-lines">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                         name AS hws_name,
-                         official AS hws_official,
-                         kind_id AS hws_kind
-                  FROM hws_lines
-                  WHERE river_id = ${river_id}
-                </dc:statement>
-                <lines>
-                  <official>
-                    <Durchlass>
-                      <dc:elements filter="$hws_kind=1 and $hws_official=1">
-                          <hws>
-                            <dc:attribute name="factory" value="hwsfactory"/>
-                            <dc:attribute name="name" value="${hws_name}"/>
-                          </hws>
-                      </dc:elements>
-                    </Durchlass>
-                    <Damm>
-                      <dc:elements filter="$hws_kind=2 and $hws_official=1">
-                          <hws>
-                            <dc:attribute name="factory" value="hwsfactory"/>
-                            <dc:attribute name="name" value="${hws_name}"/>
-                          </hws>
-                      </dc:elements>
-                    </Damm>
-                    <Graben>
-                      <dc:elements filter="$hws_kind=3 and $hws_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Graben>
-                  </official>
-                  <inofficial>
-                    <Durchlass>
-                      <dc:elements filter="$hws_kind=1 and $hws_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Durchlass>
-                    <Damm>
-                      <dc:elements filter="$hws_kind=2 and $hws_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Damm>
-                    <Graben>
-                      <dc:elements filter="$hws_kind=3 and $hws_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Graben>
-                  </inofficial>
-                </lines>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-hws-points">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                         name AS hws_points_name,
-                         official AS hws_points_official,
-                         kind_id AS hws_points_kind
-                  FROM hws_points
-                  WHERE river_id = ${river_id}
-                </dc:statement>
-                <points>
-                  <official>
-                    <Durchlass>
-                      <dc:elements filter="$hws_points_kind=1 and $hws_points_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Durchlass>
-                    <Damm>
-                      <dc:elements filter="$hws_points_kind=2 and $hws_points_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Damm>
-                    <Graben>
-                      <dc:elements filter="$hws_kind=3 and $hws_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Graben>
-                  </official>
-                  <inofficial>
-                    <Durchlass>
-                      <dc:elements filter="$hws_points_kind=1 and $hws_points_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Durchlass>
-                    <Damm>
-                      <dc:elements filter="$hws_points_kind=2 and $hws_points_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Damm>
-                    <Graben>
-                      <dc:elements filter="$hws_points_kind=3 and $hws_points_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:elements>
-                    </Graben>
-                  </inofficial>
-                </points>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-km">
-              <dc:context>
-                <dc:statement>
-                  SELECT count(*) as km_exists
-                  FROM river_axes_km WHERE river_id = ${river_id}
-                </dc:statement>
-                 <dc:elements>
-                  <dc:if test="$km_exists>0">
-                    <kilometrage>
-                      <dc:attribute name="factory" value="wmskmfactory"/>
-                      <dc:attribute name="ids" value="${river_id}"/>
-                    </kilometrage>
-                  </dc:if>
-                </dc:elements>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-qps">
-              <dc:context>
-                <dc:comment>Grab only the actual first</dc:comment>
-                <dc:statement>
-                  SELECT DISTINCT
-                  cs.kind_id as kind_id,
-                  ck.name as kind_name
-                  FROM cross_section_tracks cs
-                  JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id=1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <dc:elements>
-                    <actual>
-                      <dc:attribute name="description" value="${kind_name}"/>
-                      <dc:attribute name="factory" value="wmsqpsfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${kind_name};${kind_id}"/>
-                    </actual>
-                  </dc:elements>
-                </dc:if>
-              </dc:context>
-              <dc:context>
-                <dc:comment>Now the other tracks</dc:comment>
-                <dc:statement>
-                  SELECT DISTINCT
-                  cs.kind_id as kind_id,
-                  ck.name as kind_name,
-                  cs.name as layer_name
-                  FROM cross_section_tracks cs
-                  JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id=0
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <other>
-                    <dc:elements>
-                      <misc-qps>
-                        <dc:attribute name="description" value="${layer_name}"/>
-                        <dc:attribute name="factory" value="wmsqpsfactory"/>
-                        <dc:attribute name="ids" value="${river_id};${layer_name};${kind_id}"/>
-                      </misc-qps>
-                    </dc:elements>
-                  </other>
-                </dc:if>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-riveraxis">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  ax.kind_id as kind_id,
-                  ak.name as kind_name
-                  FROM river_axes ax
-                  JOIN axis_kinds ak on ax.kind_id = ak.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id=1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <dc:elements>
-                    <actual factory="riveraxis">
-                      <dc:attribute name="description" value="${kind_name}"/>
-                      <dc:attribute name="ids" value="${river_id};${kind_name};${kind_id}"/>
-                    </actual>
-                  </dc:elements>
-                </dc:if>
-              </dc:context>
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  ak.name as kind_name,
-                  ax.kind_id as kind_id,
-                  ax.name as layer_name
-                  FROM river_axes ax
-                  JOIN axis_kinds ak on ax.kind_id = ak.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id <> 1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <other>
-                    <dc:elements>
-                      <misc-axis factory="riveraxis">
-                        <dc:attribute name="description" value="${layer_name}"/>
-                        <dc:attribute name="ids" value="${river_id};${layer_name};${kind_id}"/>
-                      </misc-axis>
-                    </dc:elements>
-                  </other>
-                </dc:if>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-hydr-boundaries">
-              <hydr_boundaries_lines>
-                <dc:call-macro name="flood-map-hydr-boundaries-lines"/>
-              </hydr_boundaries_lines>
-              <hydr_boundaries_polygons>
-                <dc:call-macro name="flood-map-hydr-boundaries-poly"/>
-              </hydr_boundaries_polygons>
-            </dc:macro>
-            <dc:macro name="flood-map-hydr-boundaries-lines">
-              <bfg>
                 <dc:context>
                   <dc:statement>
-                    SELECT count(*) as km_exists, name as name
-                    FROM hydr_boundaries WHERE river_id = ${river_id} AND kind = 1 GROUP BY name
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_lines
+                    WHERE river_id = ${river_id}
+                    AND official=1
+                    AND fed_state_id IS NULL
+                    ORDER BY name
                   </dc:statement>
-                   <dc:elements>
-                    <dc:if test="$km_exists>0">
-                      <hydrboundary>
-                        <dc:attribute name="factory" value="wmshydrboundariesfactory"/>
-                        <dc:attribute name="ids" value="${river_id};${name}"/>
-                        <dc:attribute name="name" value="${name}"/>
-                      </hydrboundary>
-                    </dc:if>
-                  </dc:elements>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwslines_by_kind"/>
+                  </hws_fed_unknown>
                 </dc:context>
-              </bfg>
-              <land>
+              </official>
+              <inofficial>
                 <dc:context>
                   <dc:statement>
-                    SELECT count(*) as km_exists, name as name
-                    FROM hydr_boundaries WHERE river_id = ${river_id} AND kind = 2 GROUP BY name
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_lines hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=0
                   </dc:statement>
-                   <dc:elements>
-                    <dc:if test="$km_exists>0">
-                      <hydrboundary>
-                        <dc:attribute name="factory" value="wmshydrboundariesfactory"/>
-                        <dc:attribute name="ids" value="${river_id};${name}"/>
-                        <dc:attribute name="name" value="${name}"/>
-                      </hydrboundary>
-                    </dc:if>
-                  </dc:elements>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_lines
+                        WHERE river_id = ${river_id}
+                        AND official=0
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwslines_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
                 </dc:context>
-              </land>
-            </dc:macro>
-            <dc:macro name="flood-map-hydr-boundaries-poly">
-              <bfg>
                 <dc:context>
                   <dc:statement>
-                    SELECT count(*) as km_exists, name as name
-                    FROM hydr_boundaries_poly WHERE river_id = ${river_id} AND kind = 1 GROUP BY name
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_lines
+                    WHERE river_id = ${river_id}
+                    AND official=0
+                    AND fed_state_id IS NULL ORDER BY name
                   </dc:statement>
-                   <dc:elements>
-                    <dc:if test="$km_exists>0">
-                      <hws>
-                        <dc:attribute name="factory" value="wmshydrboundariespolyfactory"/>
-                        <dc:attribute name="ids" value="${river_id};${name}"/>
-                        <dc:attribute name="name" value="${name}"/>
-                      </hws>
-                    </dc:if>
-                  </dc:elements>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwslines_by_kind"/>
+                  </hws_fed_unknown>
                 </dc:context>
-              </bfg>
-              <land>
-                <dc:context>
-                  <dc:statement>
-                    SELECT count(*) as km_exists, name as name
-                    FROM hydr_boundaries_poly WHERE river_id = ${river_id} AND kind = 2 GROUP BY name
-                  </dc:statement>
-                   <dc:elements>
-                    <dc:if test="$km_exists>0">
-                      <hws>
-                        <dc:attribute name="factory" value="wmshydrboundariespolyfactory"/>
-                        <dc:attribute name="ids" value="${river_id};${name}"/>
-                        <dc:attribute name="name" value="${name}"/>
-                      </hws>
-                    </dc:if>
-                  </dc:elements>
-                </dc:context>
-              </land>
-            </dc:macro>
-            <dc:macro name="flood-map-floodplain">
-              <dc:context>
-                <dc:statement>
-                  SELECT count(*) as km_exists
-                  FROM floodplain WHERE river_id = ${river_id}
-                </dc:statement>
-                 <dc:elements>
-                  <dc:if test="$km_exists>0">
-                    <floodplain>
-                      <dc:attribute name="factory" value="wmsfloodplainfactory"/>
-                      <dc:attribute name="ids" value="${river_id}"/>
-                    </floodplain>
-                  </dc:if>
-                </dc:elements>
-              </dc:context>
-            </dc:macro>
-
-            <dc:macro name="hwslines_by_kind">
-              <dc:comment>
-                Call from a context where fed_name hws_kind hws_name and river_id is
-                availble
-              </dc:comment>
-              <Durchlass>
-                <dc:elements filter="$hws_kind=1">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwslinesfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:elements>
-              </Durchlass>
-              <Damm>
-                <dc:elements filter="$hws_kind=2">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwslinesfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:elements>
-              </Damm>
-              <Graben>
-                <dc:elements filter="$hws_kind=3">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwslinesfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:elements>
-              </Graben>
-            </dc:macro>
-
-            <dc:macro name="hwslines">
-              <hws_lines>
-                <official>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_lines hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=1
-                    </dc:statement>
-                    <dc:elements>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_lines
-                          WHERE river_id = ${river_id}
-                          AND official=1
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwslines_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:elements>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_lines
-                      WHERE river_id = ${river_id}
-                      AND official=1
-                      AND fed_state_id IS NULL
-                      ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwslines_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </official>
-                <inofficial>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_lines hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=0
-                    </dc:statement>
-                    <dc:elements>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_lines
-                          WHERE river_id = ${river_id}
-                          AND official=0
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwslines_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:elements>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_lines
-                      WHERE river_id = ${river_id}
-                      AND official=0
-                      AND fed_state_id IS NULL ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwslines_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </inofficial>
+              </inofficial>
             </hws_lines>
           </dc:macro>
 
-            <dc:macro name="hwspoints_by_kind">
-              <dc:comment>
-                Call from a context where fed_name hws_kind hws_name and river_id is
-                availble
-              </dc:comment>
-              <Durchlass>
-                <dc:elements filter="$hws_kind=1">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwspointsfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:elements>
-              </Durchlass>
-              <Damm>
-                <dc:elements filter="$hws_kind=2">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwspointsfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:elements>
-              </Damm>
-              <Graben>
-                <dc:elements filter="$hws_kind=3">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwspointsfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:elements>
-              </Graben>
+          <dc:macro name="hwspoints_by_kind">
+            <dc:comment>
+              Call from a context where fed_name hws_kind hws_name and river_id is
+              availble
+            </dc:comment>
+
+            <dc:macro name="hwspoints_by_kind_factory">
+              <dc:for-each>
+                <hws factory="wmshwspointsfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
             </dc:macro>
 
-            <dc:macro name="hwspoints">
-              <hws_points>
-                <official>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_points hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=1
-                    </dc:statement>
-                    <dc:elements>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_points
-                          WHERE river_id = ${river_id}
-                          AND official=1
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwspoints_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:elements>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_points
-                      WHERE river_id = ${river_id}
-                      AND official=1
-                      AND fed_state_id IS NULL
-                      ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwspoints_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </official>
-                <inofficial>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_points hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=0
-                    </dc:statement>
-                    <dc:elements>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_points
-                          WHERE river_id = ${river_id}
-                          AND official=0
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwspoints_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:elements>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_points
-                      WHERE river_id = ${river_id}
-                      AND official=0
-                      AND fed_state_id IS NULL ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwspoints_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </inofficial>
+            <dc:filter expr="$hws_kind=1">
+              <dc:if test="dc:has-result()">
+                <Durchlass>
+                  <dc:call-macro name="hwspoints_by_kind_factory"/>
+                </Durchlass>
+              </dc:if>
+            </dc:filter>
+
+            <dc:filter expr="$hws_kind=2">
+              <dc:if test="dc:has-result()">
+                <Damm>
+                  <dc:call-macro name="hwspoints_by_kind_factory"/>
+                </Damm>
+              </dc:if>
+            </dc:filter>
+
+            <dc:filter expr="$hws_kind=3">
+              <dc:if test="dc:has-result()">
+                <Graben>
+                  <dc:call-macro name="hwspoints_by_kind_factory"/>
+                </Graben>
+              </dc:if>
+            </dc:filter>
+          </dc:macro>
+
+          <dc:macro name="hwspoints">
+            <hws_points>
+              <official>
+                <dc:context>
+                  <dc:statement>
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_points hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=1
+                  </dc:statement>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_points
+                        WHERE river_id = ${river_id}
+                        AND official=1
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwspoints_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
+                </dc:context>
+                <dc:context>
+                  <dc:statement>
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_points
+                    WHERE river_id = ${river_id}
+                    AND official=1
+                    AND fed_state_id IS NULL
+                    ORDER BY name
+                  </dc:statement>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwspoints_by_kind"/>
+                  </hws_fed_unknown>
+                </dc:context>
+              </official>
+              <inofficial>
+                <dc:context>
+                  <dc:statement>
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_points hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=0
+                  </dc:statement>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_points
+                        WHERE river_id = ${river_id}
+                        AND official=0
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwspoints_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
+                </dc:context>
+                <dc:context>
+                  <dc:statement>
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_points
+                    WHERE river_id = ${river_id}
+                    AND official=0
+                    AND fed_state_id IS NULL ORDER BY name
+                  </dc:statement>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwspoints_by_kind"/>
+                  </hws_fed_unknown>
+                </dc:context>
+              </inofficial>
             </hws_points>
           </dc:macro>
 
@@ -1602,13 +1509,11 @@
                 WHERE b.river_id = ${river_id}
                 AND b.kind_id <> 0
               </dc:statement>
-              <dc:elements>
-                <buildings>
-                  <dc:attribute name="description" value="${building_kind}"/>
-                  <dc:attribute name="factory" value="wmsbuildingsfactory"/>
-                  <dc:attribute name="ids" value="${river_id};${building_kind};${building_kind_id}"/>
-                </buildings>
-              </dc:elements>
+              <dc:for-each>
+                <buildings description="{$building_kind}"
+                           factory="wmsbuildingsfactory"
+                           ids="{$river_id};{$building_kind};{$building_kind_id}"/>
+              </dc:for-each>
             </dc:context>
             <dc:context>
               <dc:statement>
@@ -1622,17 +1527,15 @@
                 AND kind_id = 0 OR
                 kind_id IS NULL
               </dc:statement>
-              <dc:elements>
+              <dc:for-each>
                 <dc:element name="${building_kind}">
-                  <dc:elements>
-                    <buildings>
-                      <dc:attribute name="description" value="${building_name}"/>
-                      <dc:attribute name="factory" value="wmsbuildingsfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${building_name}"/>
-                    </buildings>
-                  </dc:elements>
+                  <dc:for-each>
+                    <buildings description="{$building_name}"
+                               factory="wmsbuildingsfactory"
+                               ids="{$river_id};{$building_name}"/>
+                  </dc:for-each>
                 </dc:element>
-              </dc:elements>
+              </dc:for-each>
             </dc:context>
             <dc:context>
               <dc:statement>
@@ -1645,183 +1548,160 @@
               </dc:statement>
               <dc:if test="dc:has-result()">
                 <jetties>
-                  <dc:elements>
-                    <jetty>
-                      <dc:attribute name="description" value="${jetty_kind}"/>
-                      <dc:attribute name="factory" value="wmsjettiesfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${jetty_kind};${jetty_kind_id}"/>
-                    </jetty>
-                  </dc:elements>
+                  <dc:for-each>
+                    <jetty description="{$jetty_kind}"
+                           factory="wmsjettiesfactory"
+                           ids="{$river_id};{$jetty_kind};{$jetty_kind_id}"/>
+                  </dc:for-each>
                 </jetties>
               </dc:if>
             </dc:context>
           </dc:macro>
-            <dc:macro name="flood-map-fixpoints">
-              <dc:context>
-                <dc:statement>
-                  SELECT count(*) as km_exists, name as name
-                  FROM fixpoints WHERE river_id = ${river_id} GROUP BY name
-                </dc:statement>
-                 <dc:elements>
-                  <dc:if test="$km_exists>0">
-                    <fixpoint>
-                      <dc:attribute name="factory" value="wmsfixpointsfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${name}"/>
-                      <dc:attribute name="name"  value="${name}"/>
-                    </fixpoint>
-                  </dc:if>
-                </dc:elements>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-gaugelocations">
-              <dc:context>
-                <dc:statement>
-                  SELECT count(*) as km_exists, name as name
-                  FROM gauge_location WHERE river_id = ${river_id} GROUP BY name
-                </dc:statement>
-                 <dc:elements>
-                  <dc:if test="$km_exists>0">
-                    <gaugelocation>
-                      <dc:attribute name="factory" value="wmsgaugelocationfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${name}"/>
-                      <dc:attribute name="name"  value="${name}"/>
-                    </gaugelocation>
-                  </dc:if>
-                </dc:elements>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-uesk">
-              <uesk>
-                <calculations>
-                  <current>
-                    <bfg>
-                      <dc:context>
-                        <dc:statement>
-                            SELECT count(*) as uesg_exist, name as name
-                            FROM floodmaps
-                            WHERE river_id = ${river_id} AND kind = 111
-                            GROUP BY name, kind
-                        </dc:statement>
-                        <dc:elements>
-                          <dc:if test="$uesg_exist>0">
-                            <floodmaps>
-                              <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
-                              <dc:attribute name="ids" value="${river_id};${name}"/>
-                              <dc:attribute name="name" value="${name}"/>
-                            </floodmaps>
-                          </dc:if>
-                        </dc:elements>
-                      </dc:context>
-                    </bfg>
-                    <land>
-                      <dc:context>
-                        <dc:statement>
-                            SELECT count(*) as uesg_exist, name as name
-                            FROM floodmaps
-                            WHERE river_id = ${river_id} AND kind = 112
-                            GROUP BY name, kind
-                        </dc:statement>
-                        <dc:elements>
-                          <dc:if test="$uesg_exist>0">
-                            <floodmaps>
-                              <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
-                              <dc:attribute name="ids" value="${river_id};${name}"/>
-                              <dc:attribute name="name" value="${name}"/>
-                            </floodmaps>
-                          </dc:if>
-                        </dc:elements>
-                      </dc:context>
-                    </land>
-                  </current>
-                  <potentiel>
-                    <bfg>
-                      <dc:context>
-                        <dc:statement>
-                            SELECT count(*) as uesg_exist, name as name
-                            FROM floodmaps
-                            WHERE river_id = ${river_id} AND kind = 121
-                            GROUP BY name, kind
-                        </dc:statement>
-                        <dc:elements>
-                          <dc:if test="$uesg_exist>0">
-                            <floodmaps>
-                              <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
-                              <dc:attribute name="ids" value="${river_id};${name}"/>
-                              <dc:attribute name="name" value="${name}"/>
-                            </floodmaps>
-                          </dc:if>
-                        </dc:elements>
-                      </dc:context>
-                    </bfg>
-                    <land>
-                      <dc:context>
-                        <dc:statement>
-                            SELECT count(*) as uesg_exist, name as name
-                            FROM floodmaps
-                            WHERE river_id = ${river_id} AND kind = 122
-                            GROUP BY name, kind
-                        </dc:statement>
-                        <dc:elements>
-                          <dc:if test="$uesg_exist>0">
-                            <floodmaps>
-                              <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
-                              <dc:attribute name="ids" value="${river_id};${name}"/>
-                              <dc:attribute name="name" value="${name}"/>
-                            </floodmaps>
-                          </dc:if>
-                        </dc:elements>
-                      </dc:context>
-                    </land>
-                  </potentiel>
-                </calculations>
-              </uesk>
-            </dc:macro>
 
-            <dc:macro name="flood-map-catchments">
-              <dc:attribute name="factory" value="externalwmsfactory"/>
-              <dc:attribute name="ids" value="http://geoportal.bafg.de/wmsproxy/INSPIRE/DrainageBasin;HY.PHYSICALWATERS.CATCHMENTS;Einzugsgebiet"/>
-            </dc:macro>
+          <dc:macro name="flood-map-fixpoints">
+            <dc:context>
+              <dc:statement>
+                SELECT count(*) AS km_exists, name AS name
+                FROM fixpoints WHERE river_id = ${river_id} GROUP BY name
+              </dc:statement>
+               <dc:for-each>
+                <dc:if test="$km_exists>0">
+                  <fixpoint factory="wmsfixpointsfactory"
+                            ids="{$river_id};{$name}"
+                            name="{$name}"/>
+                </dc:if>
+              </dc:for-each>
+            </dc:context>
+          </dc:macro>
 
-            <dc:macro name="flood-map-routing">
-              <qps>
-                <dc:call-macro name="flood-map-qps"/>
-              </qps>
-              <dc:call-macro name="flood-map-fixpoints"/>
-              <dc:call-macro name="flood-map-km"/>
-              <axis>
-                <dc:call-macro name="flood-map-riveraxis"/>
-              </axis>
-            </dc:macro>
+          <dc:macro name="flood-map-gaugelocations">
+            <dc:attribute name="factory" value="externalwmsfactory"/>
+            <dc:attribute name="ids" value="http://www.pegelonline.wsv.de/webservices/gis/wms;Pegelpunkte;Pegelonline-Pegelpunkte"/>
+          </dc:macro>
 
-            <dc:macro name="flood-map-complete">
-                <buildings>
-                  <dc:call-macro name="flood-map-buildings"/>
-                </buildings>
-                <catchments>
-                  <dc:call-macro name="flood-map-catchments"/>
-                </catchments>
-                <!-- TODO: HW-Marken -->
-                <hws>
-                  <dc:call-macro name="hwslines"/>
-                  <dc:call-macro name="hwspoints"/>
-                </hws>
-                <route_data>
-                  <dc:call-macro name="flood-map-routing"/>
-                </route_data>
-                <hydrboundaries>
-                  <dc:call-macro name="flood-map-hydr-boundaries"/>
-                  <dc:call-macro name="flood-map-floodplain"/>
-                </hydrboundaries>
-                <dc:call-macro name="flood-map-uesk"/>
-                <gaugelocations>
-                  <dc:call-macro name="flood-map-gaugelocations"/>
-                </gaugelocations>
-                <background>
-                  <dc:attribute name="factory" value="wmsbackground"/>
-                  <dc:attribute name="ids" value="${river_id}"/>
-                </background>
-              </dc:macro>
+          <dc:macro name="flood-map-uesk">
+            <uesk>
+              <calculations>
+                <current>
+                  <bfg>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT count(*) AS uesg_exist, name AS name
+                        FROM floodmaps
+                        WHERE river_id = ${river_id} AND kind = 111
+                        GROUP BY name, kind
+                      </dc:statement>
+                      <dc:for-each>
+                        <dc:if test="$uesg_exist>0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </dc:context>
+                  </bfg>
+                  <land>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT count(*) AS uesg_exist, name AS name
+                        FROM floodmaps
+                        WHERE river_id = ${river_id} AND kind = 112
+                        GROUP BY name, kind
+                      </dc:statement>
+                      <dc:for-each>
+                        <dc:if test="$uesg_exist>0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </dc:context>
+                  </land>
+                </current>
+                <potentiel>
+                  <bfg>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT count(*) AS uesg_exist, name AS name
+                        FROM floodmaps
+                        WHERE river_id = ${river_id} AND kind = 121
+                        GROUP BY name, kind
+                      </dc:statement>
+                      <dc:for-each>
+                        <dc:if test="$uesg_exist>0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </dc:context>
+                  </bfg>
+                  <land>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT count(*) AS uesg_exist, name AS name
+                        FROM floodmaps
+                        WHERE river_id = ${river_id} AND kind = 122
+                        GROUP BY name, kind
+                      </dc:statement>
+                      <dc:for-each>
+                        <dc:if test="$uesg_exist>0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </dc:context>
+                  </land>
+                </potentiel>
+              </calculations>
+            </uesk>
+          </dc:macro>
+
+          <dc:macro name="flood-map-catchments">
+            <dc:attribute name="factory" value="externalwmsfactory"/>
+            <dc:attribute name="ids" value="http://geoportal.bafg.de/wmsproxy/INSPIRE/DrainageBasin;HY.PHYSICALWATERS.CATCHMENTS;Einzugsgebiet"/>
+          </dc:macro>
+
+          <dc:macro name="flood-map-routing">
+            <qps>
+              <dc:call-macro name="flood-map-qps"/>
+            </qps>
+            <dc:call-macro name="flood-map-fixpoints"/>
+            <dc:call-macro name="flood-map-km"/>
+            <axis>
+              <dc:call-macro name="flood-map-riveraxis"/>
+            </axis>
+          </dc:macro>
+
+          <dc:macro name="flood-map-complete">
+            <buildings>
+              <dc:call-macro name="flood-map-buildings"/>
+            </buildings>
+            <catchments>
+              <dc:call-macro name="flood-map-catchments"/>
+            </catchments>
+            <dc:comment><!-- TODO: HW-Marken --></dc:comment>
+            <hws>
+              <dc:call-macro name="hwslines"/>
+              <dc:call-macro name="hwspoints"/>
+            </hws>
+            <route_data>
+              <dc:call-macro name="flood-map-routing"/>
+            </route_data>
+            <hydrboundaries>
+              <dc:call-macro name="flood-map-floodplain"/>
+              <dc:call-macro name="flood-map-hydr-boundaries"/>
+            </hydrboundaries>
+            <dc:call-macro name="flood-map-uesk"/>
+            <gaugelocations>
+              <dc:call-macro name="flood-map-gaugelocations"/>
+            </gaugelocations>
+            <background factory="wmsbackground" ids="{$river_id}"/>
+          </dc:macro>
+
         </dc:if>
+
         <dc:if test="dc:contains($artifact-outs, 'minfo-heights')">
           <dc:call-macro name="minfo-heights"/>
           <dc:macro name="minfo-heights">
@@ -1836,25 +1716,25 @@
             <dc:call-macro name="bed-heights-epoch"/>
           </bedheights>
         </dc:if>
+
         <dc:macro name="bed-heights-single">
           <single>
             <dc:context>
               <dc:statement>
-                  SELECT id          AS bedh_id,
-                         year        AS bedh_year,
-                         description AS bedh_descr
-                  FROM bed_height_single WHERE river_id = ${river_id}
+                SELECT id          AS bedh_id,
+                       year        AS bedh_year,
+                       description AS bedh_descr
+                FROM bed_height_single WHERE river_id = ${river_id}
               </dc:statement>
-              <dc:elements>
-                <height>
-                  <dc:attribute name="factory" value="bedheight"/>
-                  <dc:attribute name="ids" value="bedheight-single-${bedh_id}-${bedh_year}"/>
-                  <dc:attribute name="description" value="${bedh_descr}"/>
-                </height>
-              </dc:elements>
+              <dc:for-each>
+                <height factory="bedheight"
+                        ids="bedheight-single-{$bedh_id}-{$bedh_year}"
+                        description="{$bedh_descr}"/>
+              </dc:for-each>
             </dc:context>
           </single>
         </dc:macro>
+
         <dc:macro name="bed-heights-epoch">
           <epoch>
             <dc:context>
@@ -1864,17 +1744,16 @@
                        description      AS bedh_descr
                 FROM bed_height_epoch WHERE river_id = ${river_id}
               </dc:statement>
-              <dc:elements>
-                <height>
-                  <dc:attribute name="factory" value="bedheight"/>
-                  <dc:attribute name="ids" value="bedheight-epoch-${bedh_id}-${bedh_interval_id}"/>
-                  <dc:attribute name="description" value="${bedh_descr}"/>
-                </height>
-              </dc:elements>
+              <dc:for-each>
+                <height factory="bedheight"
+                        ids="bedheight-epoch-{$bedh_id}-{$bedh_interval_id}"
+                        description="{$bedh_descr}"/>
+              </dc:for-each>
             </dc:context>
           </epoch>
         </dc:macro>
-      </dc:elements>
+
+      </dc:for-each>
     </dc:context>
   </dc:macro>
 
@@ -1885,718 +1764,741 @@
     </dc:comment>
     <dc:when test="dc:contains($parameters, 'user-id')">
 
+      <old_calculations>
 
-    <old_calculations>
-      <!--      <dc:macro name="load-user">-->
+        <dc:comment><!-- <dc:macro name="load-user">--></dc:comment>
         <dc:call-macro name="user-range">
-        <dc:context connection="user">
-          <dc:comment>
-            Get the user and collection-id.
-          </dc:comment>
-          <dc:statement>
-            SELECT u.id AS user_id, c.id AS collection_id, c.name as collection_name
-            FROM collections c JOIN users u ON c.user_id = u.id
-            WHERE u.gid = CAST(${user-id} AS uuid)
-            ORDER BY c.creation DESC
-        </dc:statement>
+          <dc:context connection="user">
+            <dc:comment> Get the user and collection-id. </dc:comment>
+            <dc:statement>
+              SELECT u.id AS user_id, c.id AS collection_id, c.name AS collection_name
+              FROM collections c JOIN users u ON c.user_id = u.id
+              WHERE u.gid = CAST(${user-id} AS uuid)
+              ORDER BY c.creation DESC
+            </dc:statement>
 
-
-        <dc:macro name="range-filter">
-                 <dc:statement>
-                   SELECT m.id AS a_id,
-                          m.state AS a_state,
-                          m.gid AS a_gid,
-                          m.creation AS a_creation,
-                          COALESCE(ld_mode, '')      AS ld_m,
-                          COALESCE(ld_locations, '') AS ld_l,
-                          COALESCE(ld_from, '')      AS ld_f,
-                          COALESCE(ld_to, '')        AS ld_t
-                   FROM   master_artifacts_range m
-                   WHERE  m.collection_id = ${collection_id} AND m.gid <> CAST(${artifact-id} AS uuid)
-                   AND EXISTS (
-                       SELECT id FROM artifact_data ad WHERE ad.artifact_id = m.id AND k = 'river' AND v = ${river})
-                 </dc:statement>
-                 <dc:elements>
-                   <dc:variable name="from" type="number" expr="dc:fromValue($ld_m, $ld_l, $ld_f)"/>
-                   <dc:variable name="to" type="number" expr="dc:toValue($ld_m, $ld_l, $ld_t)"/>
-                   <dc:if test="($from >= $fromkm and $from <= $tokm) or ($to <= $tokm and $to >= $fromkm) or ($from <= $fromkm and $to >= $tokm)">
-                     <dc:macro-body/>
-                   </dc:if>
-                 </dc:elements>
-               </dc:macro>
- 
-        <!-- OFFICIAL LINES -->
-        <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')">
-          <dc:comment comment=".wst -------------------------------"/>
-          <officiallines>
-            <dc:elements>
-                <dc:context>
-                  <dc:statement>
-                    SELECT m.id AS a_id,
-                           m.state AS a_state,
-                           m.gid AS a_gid,
-                           m.creation AS a_creation,
-                           ardg.v AS gaugy,
-                           arv.v AS wqsingle
-                    FROM   master_artifacts m,
-                           artifact_data ardg,
-                           artifact_data arv
-                    WHERE  m.collection_id = ${collection_id}
-                      AND m.gid = CAST(${artifact-id} AS uuid)
-                      AND ardg.artifact_id = m.id
-                      AND ardg.k = 'ld_gaugename'
-                      AND arv.artifact_id = m.id
-                      AND arv.k = 'wq_single'
-                      AND EXISTS (
-                        SELECT id
-                        FROM artifact_data ad
-                        WHERE ad.artifact_id = m.id
-                          AND k = 'river'
-                          AND v = ${river})
-                  </dc:statement>
-                  <dc:elements>
+            <dc:macro name="range-filter">
+              <dc:statement>
+                SELECT m.id       AS a_id,
+                       m.state    AS a_state,
+                       m.gid      AS a_gid,
+                       m.creation AS a_creation,
+                       COALESCE(ld_mode, '')      AS ld_m,
+                       COALESCE(ld_locations, '') AS ld_l,
+                       COALESCE(ld_from, '')      AS ld_f,
+                       COALESCE(ld_to, '')        AS ld_t
+                FROM   master_artifacts_range m
+                WHERE  m.collection_id = ${collection_id} AND m.gid <> CAST(${artifact-id} AS uuid)
+                AND EXISTS (
+                    SELECT id FROM artifact_data ad WHERE ad.artifact_id = m.id AND k = 'river' AND v = ${river})
+              </dc:statement>
+              <dc:for-each>
+                <dc:variable name="from" type="number" expr="dc:fromValue($ld_m, $ld_l, $ld_f)"/>
+                <dc:variable name="to" type="number" expr="dc:toValue($ld_m, $ld_l, $ld_t)"/>
+                <dc:if test="($from >= $fromkm and $from <= $tokm) or ($to <= $tokm and $to >= $fromkm) or ($from <= $fromkm and $to >= $tokm)">
+                  <dc:macro-body/>
+                </dc:if>
+              </dc:for-each>
+            </dc:macro>
+     
+            <!-- OFFICIAL LINES -->
+            <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')">
+              <dc:comment comment=".wst -------------------------------"/>
+              <officiallines>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:statement>
+                      SELECT m.id AS a_id,
+                             m.state AS a_state,
+                             m.gid AS a_gid,
+                             m.creation AS a_creation,
+                             ardg.v AS gaugy,
+                             arv.v AS wqsingle
+                      FROM   master_artifacts m,
+                             artifact_data ardg,
+                             artifact_data arv
+                      WHERE  m.collection_id = ${collection_id}
+                        AND m.gid = CAST(${artifact-id} AS uuid)
+                        AND ardg.artifact_id = m.id
+                        AND ardg.k = 'ld_gaugename'
+                        AND arv.artifact_id = m.id
+                        AND arv.k = 'wq_single'
+                        AND EXISTS (
+                          SELECT id
+                          FROM artifact_data ad
+                          WHERE ad.artifact_id = m.id
+                            AND k = 'river'
+                            AND v = ${river})
+                    </dc:statement>
+                    <dc:for-each>
                       <dc:context connection="system">
                         <dc:statement>
                           SELECT ol.wst_id AS wstid, ol.wst_column_pos AS wstcolpos, ol.name AS olname, ol.value AS oval
                           FROM official_q_values ol
                           WHERE ol.value = CAST(${wqsingle} AS NUMERIC(10,2)) AND ol.gauge_name = ${gaugy}
                         </dc:statement>
-                        <dc:elements>
+                        <dc:for-each>
                           <dc:element name="${olname}">
                             <dc:attribute name="name" value="${olname}"/>
                             <dc:attribute name="ids" value="additionals-wstv-${wstcolpos}-${wstid}"/>
                             <dc:attribute name="factory" value="staticwkms"/>
                           </dc:element>
-                        </dc:elements>
+                        </dc:for-each>
                       </dc:context>
-                  </dc:elements>
-                </dc:context>
-          </dc:elements>
-          </officiallines>
-        </dc:if>
-        <!-- END OFFICIAL LINES -->
+                    </dc:for-each>
+                  </dc:context>
+                </dc:for-each>
+              </officiallines>
+            </dc:if>
+            <!-- END OFFICIAL LINES -->
 
-        <dc:comment>
-          SHOW W-DIFFERENCES
-        </dc:comment>
+            <dc:comment>
+              SHOW W-DIFFERENCES
+            </dc:comment>
 
-       <dc:macro name="differences">
-          <differences>
-            <dc:elements>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="differences">
+              <differences>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
                       <dc:context>
                         <dc:statement>
-                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
-                          FROM outs as o, facets as f, artifacts as a
+                          SELECT a.gid AS aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description AS facet_description
+                          FROM outs AS o, facets AS f, artifacts AS a
                           WHERE f.name = 'w_differences' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                         </dc:statement>
-                        <dc:elements>
+                        <dc:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <dc:attribute name="factory" value="winfo"/>
                             <dc:attribute name="artifact-id" value="${aid}"/>
-                            <dc:attribute name="ids"         value="${aid}"/>
-                            <dc:attribute name="out"         value="w_differences"/>
+                            <dc:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="w_differences"/>
                           </dc:element>
-                        </dc:elements>
+                        </dc:for-each>
                       </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:elements>
-          </differences>
-        </dc:macro>
+                  </dc:context>
+                </dc:for-each>
+              </differences>
+            </dc:macro>
 
-        <dc:comment>
-          SHOW REFERENCE CURVE
-        </dc:comment>
+            <dc:comment>
+              SHOW REFERENCE CURVE
+            </dc:comment>
 
-
-        <dc:macro name="reference-curves">
-          <reference_curves>
-            <dc:elements>
-                <dc:context>
-                  <dc:call-macro name="user-range">
+            <dc:macro name="reference-curves">
+              <reference_curves>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="user-range">
                       <dc:context>
                         <dc:statement>
-                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
-                          FROM outs as o, facets as f, artifacts as a
+                          SELECT a.gid AS aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description AS facet_description
+                          FROM outs AS o, facets AS f, artifacts AS a
                           WHERE f.name = 'reference_curve' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                         </dc:statement>
-                        <dc:elements>
+                        <dc:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <dc:attribute name="factory" value="winfo"/>
                             <dc:attribute name="artifact-id" value="${aid}"/>
-                            <dc:attribute name="ids"         value="${aid}"/>
-                            <dc:attribute name="out"         value="reference_curve"/>
+                            <dc:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="reference_curve"/>
                           </dc:element>
-                        </dc:elements>
+                        </dc:for-each>
+                      </dc:context>
+                     </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </reference_curves>
+            </dc:macro>
+
+            <dc:comment>
+              SHOW COMPUTED DISCHARGE CURVES
+            </dc:comment>
+
+            <dc:macro name="computed-discharge-curve">
+              <computed_discharge_curves>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT a.gid AS aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description AS facet_description
+                          FROM outs AS o, facets AS f, artifacts AS a
+                          WHERE f.name = 'computed_discharge_curve.q' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
+                        </dc:statement>
+                        <dc:for-each>
+                          <dc:element name="${facet_name}">
+                            <dc:attribute name="description" value="${facet_description}"/>
+                            <dc:attribute name="factory" value="winfo"/>
+                            <dc:attribute name="artifact-id" value="${aid}"/>
+                            <dc:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="computed_discharge_curve"/>
+                          </dc:element>
+                        </dc:for-each>
                       </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:elements>
-          </reference_curves>
-        </dc:macro>
+                  </dc:context>
+                </dc:for-each>
+              </computed_discharge_curves>
+            </dc:macro>
 
-        <dc:comment>
-          SHOW COMPUTED DISCHARGE CURVES
-        </dc:comment>
+            <dc:comment>
+              CROSS SECTION
+            </dc:comment>
 
-        <dc:macro name="computed-discharge-curve">
-          <computed_discharge_curves>
-            <dc:elements>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="waterlevels">
+              <waterlevels>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
                       <dc:context>
                         <dc:statement>
-                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
-                          FROM outs as o, facets as f, artifacts as a
-                          WHERE f.name = 'computed_discharge_curve.q' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'cross_section'
                         </dc:statement>
-                        <dc:elements>
+                        <dc:for-each>
+                          <dc:context>
+                            <dc:statement>
+                              SELECT name AS facet_name, num AS facet_num, description AS facet_description
+                              FROM facets
+                              WHERE out_id = ${out_id}
+                              ORDER BY num ASC, name DESC
+                            </dc:statement>
+                            <longitudinal_section_columns description="{$river} {$a_creation}">
+                              <dc:for-each>
+                                <dc:element name="${facet_name}">
+                                  <dc:attribute name="description" value="${facet_description}"/>
+                                  <dc:attribute name="ids" value="${facet_num}"/>
+                                  <dc:attribute name="factory" value="winfo"/>
+                                  <dc:attribute name="artifact-id" value="${a_gid}"/>
+                                  <dc:attribute name="out" value="cross_section"/>
+                                </dc:element>
+                              </dc:for-each>
+                            </longitudinal_section_columns>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="longitudinal">
+              <waterlevels>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'longitudinal_section'
+                        </dc:statement>
+                        <dc:for-each>
+                          <dc:context>
+                            <dc:statement>
+                              SELECT name AS facet_name, num AS facet_num, description AS facet_description
+                              FROM facets
+                              WHERE out_id = ${out_id}
+                              ORDER BY num ASC, name DESC
+                            </dc:statement>
+                            <longitudinal_section_columns description="{$river} {$a_creation}">
+                              <dc:for-each>
+                                <dc:element name="${facet_name}">
+                                  <dc:attribute name="description" value="${facet_description}"/>
+                                  <dc:attribute name="ids" value="${facet_num}"/>
+                                  <dc:attribute name="factory" value="winfo"/>
+                                  <dc:attribute name="artifact-id" value="${a_gid}"/>
+                                  <dc:attribute name="out" value="longitudinal_section"/>
+                                </dc:element>
+                              </dc:for-each>
+                            </longitudinal_section_columns>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="longitudinal-section">
+              <waterlevels>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'fix_longitudinal_section_curve'
+                        </dc:statement>
+                        <dc:for-each>
+                          <dc:context>
+                            <dc:comment><!-- average und deviation ls_0 . ls_1 ...--></dc:comment>
+                            <dc:statement>
+                              SELECT name AS facet_name, num AS facet_num, description AS facet_description
+                              FROM facets
+                              WHERE out_id = ${out_id} AND ( 
+                                  name LIKE 'fix_deviation_ls%'       OR 
+                                  name LIKE 'fix_sector_average_ls%'  OR 
+                                  name LIKE 'fix_analysis_events_ls%' OR 
+                                  name LIKE 'fix_reference_events_ls%' )
+                              ORDER BY num ASC, name DESC
+                            </dc:statement>
+                            <waterlevels description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <dc:element name="${facet_name}">
+                                  <dc:attribute name="description" value="${facet_description}"/>
+                                  <dc:attribute name="ids" value="${facet_num}"/>
+                                  <dc:attribute name="factory" value="fixanalysis"/>
+                                  <dc:attribute name="artifact-id" value="${a_gid}"/>
+                                  <dc:attribute name="out" value="fix_longitudinal_section_curve"/>
+                                </dc:element>
+                              </dc:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="delta-wt">
+              <waterlevels>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'fix_deltawt_curve'
+                        </dc:statement>
+                        <dc:for-each>
+                          <dc:context>
+                            <dc:statement>
+                              SELECT name AS facet_name, num AS facet_num, description AS facet_description
+                              FROM facets
+                              WHERE out_id = ${out_id} and (
+                                name LIKE 'fix_sector_average_dwt%' OR
+                                name LIKE 'fix_deviation_dwt%'      OR
+                                name = 'fix_analysis_events_dwt'    OR
+                                name = 'fix_reference_events_dwt'   OR
+                                name = 'fix_analysis_periods_dwt' )
+                              ORDER BY num ASC, name DESC
+                            </dc:statement>
+                            <waterlevels description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <dc:element name="${facet_name}">
+                                  <dc:attribute name="description" value="${facet_description}"/>
+                                  <dc:attribute name="ids" value="${facet_num}"/>
+                                  <dc:attribute name="factory" value="fixanalysis"/>
+                                  <dc:attribute name="artifact-id" value="${a_gid}"/>
+                                  <dc:attribute name="out" value="fix_deltawt_curve"/>
+                                </dc:element>
+                              </dc:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="fix-derivate-curve">
+              <waterlevels>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'fix_derivate_curve'
+                        </dc:statement>
+                        <dc:for-each>
+                          <dc:context>
+                            <dc:statement>
+                              SELECT name AS facet_name, num AS facet_num, description AS facet_description
+                              FROM facets
+                              WHERE out_id = ${out_id} and name = 'fix_derivate_curve'
+                              ORDER BY num ASC, name DESC
+                            </dc:statement>
+                            <waterlevels description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <dc:element name="${facet_name}">
+                                  <dc:attribute name="description" value="${facet_description}"/>
+                                  <dc:attribute name="ids" value="${facet_num}"/>
+                                  <dc:attribute name="factory" value="fixanalysis"/>
+                                  <dc:attribute name="artifact-id" value="${a_gid}"/>
+                                  <dc:attribute name="out" value="fix_derivate_curve"/>
+                                </dc:element>
+                              </dc:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="fix-wq-curve">
+              <waterlevels>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'fix_wq_curve'
+                        </dc:statement>
+                        <dc:for-each>
+                          <dc:context>
+                            <dc:statement>
+                              SELECT name AS facet_name, num AS facet_num, description AS facet_description
+                              FROM facets
+                              WHERE out_id = ${out_id} and (
+                                name LIKE 'fix_sector_average_wq%'  OR
+                                name = 'fix_wq_curve'               OR
+                                name LIKE 'fix_analysis_events_wq%' OR
+                                name LIKE 'fix_reference_events_wq%' )
+                              ORDER BY num ASC, name DESC
+                            </dc:statement>
+                            <waterlevels description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <dc:element name="${facet_name}">
+                                  <dc:attribute name="description" value="${facet_description}"/>
+                                  <dc:attribute name="ids" value="${facet_num}"/>
+                                  <dc:attribute name="factory" value="fixanalysis"/>
+                                  <dc:attribute name="artifact-id" value="${a_gid}"/>
+                                  <dc:attribute name="out" value="fix_wq_curve"/>
+                                </dc:element>
+                              </dc:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="duration-curve">
+              <computed_discharge_curves>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT a.gid         AS aid,
+                                 f.id          AS fid,
+                                 f.name        AS facet_name,
+                                 f.num         AS facet_num,
+                                 f.description AS facet_description
+                          FROM outs AS o, facets AS f, artifacts AS a
+                          WHERE
+                              (f.name = 'duration_curve.q' OR f.name = 'duration_curve.w') AND 
+                              f.out_id = o.id         AND
+                              o.artifact_id = ${a_id} AND
+                              a.id = ${a_id}
+                        </dc:statement>
+                        <dc:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <dc:attribute name="factory" value="winfo"/>
                             <dc:attribute name="artifact-id" value="${aid}"/>
-                            <dc:attribute name="ids"         value="${aid}"/>
-                            <dc:attribute name="out"         value="computed_discharge_curve"/>
+                            <dc:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="duration_curve"/>
                           </dc:element>
-                        </dc:elements>
+                        </dc:for-each>
                       </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:elements>
-          </computed_discharge_curves>
-        </dc:macro>
+                  </dc:context>
+                </dc:for-each>
+              </computed_discharge_curves>
+            </dc:macro>
 
-        <dc:comment>
-          CROSS SECTION
-        </dc:comment>
+            <dc:comment>
+               WATERLEVELS - ONLY SHOW Ws
+            </dc:comment>
 
+            <dc:comment><!-- TODO doesnt work nicely for fix/wq-diags. --></dc:comment>
 
-        <dc:macro name="waterlevels">
-          <waterlevels>
-            <dc:elements>
-              <dc:context>
-                <dc:call-macro name="range-filter">
-                     <dc:context>
-                       <dc:statement>
-                         SELECT id AS out_id
-                         FROM outs
-                         WHERE artifact_id = ${a_id} AND name = 'cross_section'
-                       </dc:statement>
-                       <dc:elements>
-                         <dc:context>
-                           <dc:statement>
-                             SELECT name AS facet_name, num as facet_num, description AS facet_description
-                             FROM facets
-                             WHERE out_id = ${out_id}
-                             ORDER BY num ASC, name DESC
-                           </dc:statement>
-                           <longitudinal_section_columns>
-                             <dc:attribute name="description" value="${river} ${a_creation}"/>
-                             <dc:elements>
-                               <dc:element name="${facet_name}">
-                                 <dc:attribute name="description" value="${facet_description}"/>
-                                 <dc:attribute name="ids" value="${facet_num}"/>
-                                 <dc:attribute name="factory" value="winfo"/>
-                                 <dc:attribute name="artifact-id" value="${a_gid}"/>
-                                 <dc:attribute name="out" value="cross_section"/>
-                               </dc:element>
-                             </dc:elements>
-                           </longitudinal_section_columns>
-                         </dc:context>
-                       </dc:elements>
-                     </dc:context>
-                   </dc:call-macro>
-               </dc:context>
-             </dc:elements>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="longitudinal">
-          <waterlevels>
-            <dc:elements>
-              <dc:context>
-                <dc:call-macro name="range-filter">
+            <dc:macro name="waterlevels-fix">
+              <waterlevels>
+                <dc:for-each>
                   <dc:context>
-                     <dc:statement>
-                       SELECT id AS out_id
-                       FROM outs
-                       WHERE artifact_id = ${a_id} AND name = 'longitudinal_section'
-                     </dc:statement>
-                     <dc:elements>
-                       <dc:context>
-                         <dc:statement>
-                           SELECT name AS facet_name, num as facet_num, description AS facet_description
-                           FROM facets
-                           WHERE out_id = ${out_id}
-                           ORDER BY num ASC, name DESC
-                         </dc:statement>
-                         <longitudinal_section_columns>
-                             <dc:attribute name="description" value="${river} ${a_creation}"/>
-                             <dc:elements>
-                               <dc:element name="${facet_name}">
-                                 <dc:attribute name="description" value="${facet_description}"/>
-                                 <dc:attribute name="ids" value="${facet_num}"/>
-                                 <dc:attribute name="factory" value="winfo"/>
-                                 <dc:attribute name="artifact-id" value="${a_gid}"/>
-                                 <dc:attribute name="out" value="longitudinal_section"/>
-                               </dc:element>
-                             </dc:elements>
-                         </longitudinal_section_columns>
-                       </dc:context>
-                     </dc:elements>
-                   </dc:context>
-                 </dc:call-macro>
-               </dc:context>
-             </dc:elements>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="longitudinal-section">
-          <waterlevels>
-            <dc:elements>
-              <dc:context>
-                <dc:call-macro name="range-filter">
-                   <dc:context>
-                   <dc:statement>
-                     SELECT id AS out_id
-                     FROM outs
-                     WHERE artifact_id = ${a_id} AND name = 'fix_longitudinal_section_curve'
-                   </dc:statement>
-                   <dc:elements>
-                     <dc:context>
-                     <!-- average und deviation ls_0 . ls_1 ...-->
-                       <dc:statement>
-                         SELECT name AS facet_name, num as facet_num, description AS facet_description
-                         FROM facets
-                         WHERE out_id = ${out_id} AND ( name LIKE 'fix_deviation_ls%' OR name LIKE 'fix_sector_average_ls%' OR name LIKE 'fix_analysis_events_ls%' OR name LIKE 'fix_reference_events_ls%' )
-                         ORDER BY num ASC, name DESC
-                       </dc:statement>
-                       <waterlevels>
-                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
-                         <dc:elements>
-                           <dc:element name="${facet_name}">
-                             <dc:attribute name="description" value="${facet_description}"/>
-                             <dc:attribute name="ids"         value="${facet_num}"/>
-                             <dc:attribute name="factory"     value="fixanalysis"/>
-                             <dc:attribute name="artifact-id" value="${a_gid}"/>
-                             <dc:attribute name="out"         value="fix_longitudinal_section_curve"/>
-                           </dc:element>
-                         </dc:elements>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:elements>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:elements>
-          </waterlevels>
-        </dc:macro>
-
-        <dc:macro name="delta-wt">
-          <waterlevels>
-            <dc:elements>
-              <dc:context>
-                <dc:call-macro name="range-filter">
-                   <dc:context>
-                   <dc:statement>
-                     SELECT id AS out_id
-                     FROM outs
-                     WHERE artifact_id = ${a_id} AND name = 'fix_deltawt_curve'
-                   </dc:statement>
-                   <dc:elements>
-                     <dc:context>
-                       <dc:statement>
-                         SELECT name AS facet_name, num as facet_num, description AS facet_description
-                         FROM facets
-                         WHERE out_id = ${out_id} and ( name LIKE 'fix_sector_average_dwt%' OR name LIKE 'fix_deviation_dwt%' OR name = 'fix_analysis_events_dwt' OR name = 'fix_reference_events_dwt' OR name = 'fix_analysis_periods_dwt' )
-                         ORDER BY num ASC, name DESC
-                       </dc:statement>
-                       <waterlevels>
-                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
-                         <dc:elements>
-                           <dc:element name="${facet_name}">
-                             <dc:attribute name="description" value="${facet_description}"/>
-                             <dc:attribute name="ids"         value="${facet_num}"/>
-                             <dc:attribute name="factory"     value="fixanalysis"/>
-                             <dc:attribute name="artifact-id" value="${a_gid}"/>
-                             <dc:attribute name="out"         value="fix_deltawt_curve"/>
-                           </dc:element>
-                         </dc:elements>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:elements>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:elements>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="fix-derivate-curve">
-          <waterlevels>
-            <dc:elements>
-              <dc:context>
-                <dc:call-macro name="range-filter">
-                   <dc:context>
-                   <dc:statement>
-                     SELECT id AS out_id
-                     FROM outs
-                     WHERE artifact_id = ${a_id} AND name = 'fix_derivate_curve'
-                   </dc:statement>
-                   <dc:elements>
-                     <dc:context>
-                       <dc:statement>
-                         SELECT name AS facet_name, num as facet_num, description AS facet_description
-                         FROM facets
-                         WHERE out_id = ${out_id} and name = 'fix_derivate_curve'
-                         ORDER BY num ASC, name DESC
-                       </dc:statement>
-                       <waterlevels>
-                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
-                         <dc:elements>
-                           <dc:element name="${facet_name}">
-                             <dc:attribute name="description" value="${facet_description}"/>
-                             <dc:attribute name="ids"         value="${facet_num}"/>
-                             <dc:attribute name="factory"     value="fixanalysis"/>
-                             <dc:attribute name="artifact-id" value="${a_gid}"/>
-                             <dc:attribute name="out"         value="fix_derivate_curve"/>
-                           </dc:element>
-                         </dc:elements>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:elements>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:elements>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="fix-wq-curve">
-          <waterlevels>
-            <dc:elements>
-              <dc:context>
-                <dc:call-macro name="range-filter">
-                   <dc:context>
-                   <dc:statement>
-                     SELECT id AS out_id
-                     FROM outs
-                     WHERE artifact_id = ${a_id} AND name = 'fix_wq_curve'
-                   </dc:statement>
-                   <dc:elements>
-                     <dc:context>
-                       <dc:statement>
-                         SELECT name AS facet_name, num as facet_num, description AS facet_description
-                         FROM facets
-                         WHERE out_id = ${out_id} and ( name LIKE 'fix_sector_average_wq%' OR name = 'fix_wq_curve' OR name LIKE 'fix_analysis_events_wq%' OR name LIKE 'fix_reference_events_wq%' )
-                         ORDER BY num ASC, name DESC
-                       </dc:statement>
-                       <waterlevels>
-                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
-                         <dc:elements>
-                           <dc:element name="${facet_name}">
-                             <dc:attribute name="description" value="${facet_description}"/>
-                             <dc:attribute name="ids"         value="${facet_num}"/>
-                             <dc:attribute name="factory"     value="fixanalysis"/>
-                             <dc:attribute name="artifact-id" value="${a_gid}"/>
-                             <dc:attribute name="out"         value="fix_wq_curve"/>
-                           </dc:element>
-                         </dc:elements>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:elements>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:elements>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="duration-curve">
-          <computed_discharge_curves>
-            <dc:elements>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+                    <dc:call-macro name="range-filter">
                       <dc:context>
                         <dc:statement>
-                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
-                          FROM outs as o, facets as f, artifacts as a
-                          WHERE (f.name = 'duration_curve.q' or f.name = 'duration_curve.w') and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'longitudinal_section'
                         </dc:statement>
-                        <dc:elements>
+                        <dc:for-each>
+                          <dc:context>
+                            <dc:statement>
+                              SELECT name AS facet_name, num AS facet_num, description AS facet_description
+                              FROM facets
+                              WHERE out_id = ${out_id} and name = 'longitudinal_section.w'
+                              ORDER BY num ASC, name DESC
+                            </dc:statement>
+                            <waterlevels description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <dc:element name="${facet_name}">
+                                  <dc:attribute name="description" value="${facet_description}"/>
+                                  <dc:attribute name="ids" value="${facet_num}"/>
+                                  <dc:attribute name="factory" value="winfo"/>
+                                  <dc:attribute name="artifact-id" value="${a_gid}"/>
+                                  <dc:attribute name="out" value="longitudinal_section"/>
+                                </dc:element>
+                              </dc:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:comment>
+              SHOW FLOODMAPS
+            </dc:comment>
+
+            <dc:macro name="flood-map">
+              <floodmap>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
+                      <dc:context>
+                        <dc:statement>
+                          SELECT a.gid         AS aid,
+                                 f.id          AS fid,
+                                 f.name        AS facet_name,
+                                 f.num         AS facet_num,
+                                 f.description AS facet_description
+                          FROM outs AS o, facets AS f, artifacts AS a
+                          WHERE f.name = 'floodmap.wsplgen' AND
+                                f.out_id = o.id             AND
+                                o.artifact_id = ${a_id}     AND
+                                a.id = ${a_id}
+                        </dc:statement>
+                        <dc:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <dc:attribute name="factory" value="winfo"/>
                             <dc:attribute name="artifact-id" value="${aid}"/>
-                            <dc:attribute name="ids"         value="${aid}"/>
-                            <dc:attribute name="out"         value="duration_curve"/>
+                            <dc:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="floodmap"/>
                           </dc:element>
-                        </dc:elements>
+                        </dc:for-each>
                       </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:elements>
-          </computed_discharge_curves>
-        </dc:macro>
+                  </dc:context>
+                </dc:for-each>
+              </floodmap>
+            </dc:macro>
 
-        <dc:comment>
-           WATERLEVELS - ONLY SHOW Ws
-        </dc:comment>
+            <dc:comment>
+              MINFO bedheight difference
+            </dc:comment>
 
-        <!-- TODO doesnt work nicely for fix/wq-diags. -->
-
-        <dc:macro name="waterlevels-fix">
-          <waterlevels>
-            <dc:elements>
-              <dc:context>
-                <dc:call-macro name="range-filter">
-                   <dc:context>
-                   <dc:statement>
-                     SELECT id AS out_id
-                     FROM outs
-                     WHERE artifact_id = ${a_id} AND name = 'longitudinal_section'
-                   </dc:statement>
-                   <dc:elements>
-                     <dc:context>
-                       <dc:statement>
-                         SELECT name AS facet_name, num as facet_num, description AS facet_description
-                         FROM facets
-                         WHERE out_id = ${out_id} and name = 'longitudinal_section.w'
-                         ORDER BY num ASC, name DESC
-                       </dc:statement>
-                       <waterlevels>
-                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
-                         <dc:elements>
-                           <dc:element name="${facet_name}">
-                             <dc:attribute name="description" value="${facet_description}"/>
-                             <dc:attribute name="ids"         value="${facet_num}"/>
-                             <dc:attribute name="factory"     value="winfo"/>
-                             <dc:attribute name="artifact-id" value="${a_gid}"/>
-                             <dc:attribute name="out"         value="longitudinal_section"/>
-                           </dc:element>
-                         </dc:elements>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:elements>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:elements>
-          </waterlevels>
-        </dc:macro>
-
-        <dc:comment>
-          SHOW FLOODMAPS
-        </dc:comment>
-
-
-        <dc:macro name="flood-map">
-          <floodmap>
-            <dc:elements>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="bed-difference">
+              <fix_longitudinal_section_curve>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
                       <dc:context>
                         <dc:statement>
-                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
-                          FROM outs as o, facets as f, artifacts as a
-                          WHERE f.name = 'floodmap.wsplgen' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
+                          SELECT a.gid         AS aid,
+                                 f.id          AS fid,
+                                 f.name        AS facet_name,
+                                 f.num         AS facet_num,
+                                 f.description AS facet_description
+                          FROM outs AS o, facets AS f, artifacts AS a
+                          WHERE (
+                              f.name = 'fix_sector_average_ls_0' OR
+                              f.name = 'fix_sector_average_ls_1' OR
+                              f.name = 'fix_sector_average_ls_2' OR
+                              f.name = 'fix_sector_average_ls_3' OR
+                              f.name = 'fix_analysis_events_ls'  OR
+                              f.name = 'fix_reference_events_ls'
+                              ) AND f.out_id = o.id AND o.artifact_id = ${a_id} AND a.id = ${a_id}
                         </dc:statement>
-                        <dc:elements>
-                          <dc:element name="${facet_name}">
-                            <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
-                            <dc:attribute name="artifact-id" value="${aid}"/>
-                            <dc:attribute name="ids"         value="${aid}"/>
-                            <dc:attribute name="out"         value="floodmap"/>
-                          </dc:element>
-                        </dc:elements>
+                        <fix_longitudinal_section_curve description="{$river} {$a_creation} {$collection_name}">
+                          <dc:for-each>
+                            <dc:element name="${facet_name}">
+                              <dc:attribute name="description" value="${facet_description}"/>
+                              <dc:attribute name="factory" value="fixanalysis"/>
+                              <dc:attribute name="artifact-id" value="${aid}"/>
+                              <dc:attribute name="ids" value="${facet_num}"/>
+                              <dc:attribute name="out" value="fix_longitudinal_section_curve"/>
+                            </dc:element>
+                          </dc:for-each>
+                        </fix_longitudinal_section_curve>
                       </dc:context>
-                  </dc:call-macro>
-                </dc:context>
-            </dc:elements>
-          </floodmap>
-        </dc:macro>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </fix_longitudinal_section_curve>
+            </dc:macro>
 
-        <dc:comment>
-          MINFO bedheight difference
-        </dc:comment>
+            <dc:comment>
+              MINFO bedheight middle
+            </dc:comment>
 
-        <dc:macro name="bed-difference">
-          <fix_longitudinal_section_curve>
-            <dc:elements>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="bed-height">
+              <fix_vollmer_wq_curve>
+                <dc:for-each>
+                  <dc:context>
+                    <dc:call-macro name="range-filter">
                       <dc:context>
                         <dc:statement>
-                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
-                          FROM outs as o, facets as f, artifacts as a
-                          WHERE (f.name = 'fix_sector_average_ls_0' or f.name = 'fix_sector_average_ls_1' or f.name = 'fix_sector_average_ls_2'
-                                 or f.name = 'fix_sector_average_ls_3' or f.name = 'fix_analysis_events_ls' or f.name = 'fix_reference_events_ls')
-                                and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
+                          SELECT a.gid         AS aid,
+                                 f.id          AS fid,
+                                 f.name        AS facet_name,
+                                 f.num         AS facet_num,
+                                 f.description AS facet_description
+                          FROM outs AS o, facets AS f, artifacts AS a
+                          WHERE (
+                              f.name = 'longitudinal_section.w' OR 
+                              f.name = 'heightmarks_points'
+                          ) AND f.out_id = o.id AND o.artifact_id = ${a_id} AND a.id = ${a_id}
                         </dc:statement>
-                        <fix_longitudinal_section_curve>
-                            <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
-                            <dc:elements>
+                        <fix_vollmer_wq_curve description="{$river} {$a_creation} {$collection_name}">
+                          <dc:for-each>
                             <dc:element name="${facet_name}">
-                                <dc:attribute name="description" value="${facet_description}"/>
-                                <dc:attribute name="factory"     value="fixanalysis"/>
-                                <dc:attribute name="artifact-id" value="${aid}"/>
-                                <dc:attribute name="ids"         value="${facet_num}"/>
-                                <dc:attribute name="out"         value="fix_longitudinal_section_curve"/>
+                              <dc:attribute name="description" value="${facet_description}"/>
+                              <dc:attribute name="factory" value="fixanalysis"/>
+                              <dc:attribute name="artifact-id" value="${aid}"/>
+                              <dc:attribute name="ids" value="${facet_num}"/>
+                              <dc:attribute name="out" value="longitudinal_section"/>
                             </dc:element>
-                            </dc:elements>
-                        </fix_longitudinal_section_curve>
-                        </dc:context>
+                          </dc:for-each>
+                        </fix_vollmer_wq_curve>
+                      </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:elements>
-          </fix_longitudinal_section_curve>
-        </dc:macro>
+                  </dc:context>
+                </dc:for-each>
+              </fix_vollmer_wq_curve>
+            </dc:macro>
 
-        <dc:comment>
-          MINFO bedheight middle
-        </dc:comment>
-
-        <dc:macro name="bed-height">
-          <fix_vollmer_wq_curve>
-            <dc:elements>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
-                      <dc:context>
-                        <dc:statement>
-                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
-                          FROM outs as o, facets as f, artifacts as a
-                          WHERE (f.name = 'longitudinal_section.w' or f.name = 'heightmarks_points')
-                                and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
-                        </dc:statement>
-                        <fix_vollmer_wq_curve>
-                            <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
-                            <dc:elements>
-                                <dc:element name="${facet_name}">
-                                    <dc:attribute name="description" value="${facet_description}"/>
-                                    <dc:attribute name="factory"     value="fixanalysis"/>
-                                    <dc:attribute name="artifact-id" value="${aid}"/>
-                                    <dc:attribute name="ids"         value="${facet_num}"/>
-                                    <dc:attribute name="out"         value="longitudinal_section"/>
-                                </dc:element>
-                            </dc:elements>
-                        </fix_vollmer_wq_curve>
-                        </dc:context>
-                    </dc:call-macro>
-                </dc:context>
-            </dc:elements>
-          </fix_vollmer_wq_curve>
-        </dc:macro>
-
-        <dc:macro name="floodmap-hws-user">
+            <dc:macro name="floodmap-hws-user">
+              <dc:context>
+                <dc:statement>
+                  SELECT id AS out_id
+                  FROM outs
+                  WHERE artifact_id = ${a_id} AND name = 'floodmap'
+                </dc:statement>
+                <dc:for-each>
                   <dc:context>
                     <dc:statement>
-                      SELECT id AS out_id
-                      FROM outs
-                      WHERE artifact_id = ${a_id} AND name = 'floodmap'
+                      SELECT name        AS facet_name,
+                             num         AS facet_num,
+                             description AS facet_description
+                      FROM facets
+                      WHERE out_id = ${out_id} AND name = 'floodmap.usershape'
+                      ORDER BY num ASC, name DESC
                     </dc:statement>
-                    <dc:elements>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT name AS facet_name, num as facet_num, description AS facet_description
-                          FROM facets
-                          WHERE out_id = ${out_id} and name = 'floodmap.usershape'
-                          ORDER BY num ASC, name DESC
-                        </dc:statement>
-                        <own-hws>
-                          <dc:elements>
-                            <dc:element name="${facet_name}">
-                              <dc:attribute name="description" value="${facet_description}"/>
-                              <dc:attribute name="ids"         value="${facet_num}"/>
-                              <dc:attribute name="factory"     value="winfo"/>
-                              <dc:attribute name="artifact-id" value="${a_gid}"/>
-                              <dc:attribute name="out"         value="floodmap"/>
-                            </dc:element>
-                          </dc:elements>
-                        </own-hws>
-                      </dc:context>
-                    </dc:elements>
+                    <own-hws>
+                      <dc:for-each>
+                        <dc:element name="${facet_name}">
+                          <dc:attribute name="description" value="${facet_description}"/>
+                          <dc:attribute name="ids" value="${facet_num}"/>
+                          <dc:attribute name="factory" value="winfo"/>
+                          <dc:attribute name="artifact-id" value="${a_gid}"/>
+                          <dc:attribute name="out" value="floodmap"/>
+                        </dc:element>
+                      </dc:for-each>
+                    </own-hws>
                   </dc:context>
-        </dc:macro>
-        <dc:if test="dc:contains($artifact-outs, 'longitudinal_section') or (dc:contains($artifact-outs, 'discharge_longitudinal_section') or (dc:contains($artifact-outs, 'w_differences')))">
-          <dc:call-macro name="longitudinal"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'fix_deltawt_curve')">
-          <dc:call-macro name="delta-wt"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'longitudinal_section') or (dc:contains($artifact-outs, 'w_differences') or (dc:contains($artifact-outs, 'discharge_longitudinal_section')))">
-          <dc:call-macro name="differences"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'reference_curve')">
-          <dc:call-macro name="reference-curves"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve')">
-          <dc:call-macro name="computed-discharge-curve"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'cross_section')">
-          <dc:call-macro name="waterlevels"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'fix_longitudinal_section_curve')">
-          <dc:call-macro name="longitudinal-section"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'fix_derivate_curve')">
-          <dc:call-macro name="fix-derivate-curve"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'fix_wq_curve')">
-          <dc:call-macro name="fix-wq-curve"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'duration_curve')">
-          <dc:call-macro name="duration-curve"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'waterlevels') or (dc:contains($artifact-outs, 'fix_wq_curve'))">
-          <dc:call-macro name="waterlevels-fix"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'floodmap') or dc:contains($artifact-outs, 'map')">
-          <dc:call-macro name="flood-map"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'bed_difference_year') or dc:contains($artifact-outs, 'bed_difference_height_year')">
-          <dc:call-macro name="bed-difference"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'bedheight_middle')">
-          <dc:call-macro name="bed-height"/>
-        </dc:if>
-        <dc:if test="dc:contains($artifact-outs, 'floodmap-hws')">
-          <dc:call-macro name="floodmap-hws-user"/>
-        </dc:if>
-      </dc:context>
-  </dc:call-macro>
+                </dc:for-each>
+              </dc:context>
+            </dc:macro>
+
+            <dc:if test="dc:contains($artifact-outs, 'longitudinal_section') or (dc:contains($artifact-outs, 'discharge_longitudinal_section') or (dc:contains($artifact-outs, 'w_differences')))">
+              <dc:call-macro name="longitudinal"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'fix_deltawt_curve')">
+              <dc:call-macro name="delta-wt"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'longitudinal_section') or (dc:contains($artifact-outs, 'w_differences') or (dc:contains($artifact-outs, 'discharge_longitudinal_section')))">
+              <dc:call-macro name="differences"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'reference_curve')">
+              <dc:call-macro name="reference-curves"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve')">
+              <dc:call-macro name="computed-discharge-curve"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'cross_section')">
+              <dc:call-macro name="waterlevels"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'fix_longitudinal_section_curve')">
+              <dc:call-macro name="longitudinal-section"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'fix_derivate_curve')">
+              <dc:call-macro name="fix-derivate-curve"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'fix_wq_curve')">
+              <dc:call-macro name="fix-wq-curve"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'duration_curve')">
+              <dc:call-macro name="duration-curve"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'waterlevels') or (dc:contains($artifact-outs, 'fix_wq_curve'))">
+              <dc:call-macro name="waterlevels-fix"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'floodmap') or dc:contains($artifact-outs, 'map')">
+              <dc:call-macro name="flood-map"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'bed_difference_year') or dc:contains($artifact-outs, 'bed_difference_height_year')">
+              <dc:call-macro name="bed-difference"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'bedheight_middle')">
+              <dc:call-macro name="bed-height"/>
+            </dc:if>
+            <dc:if test="dc:contains($artifact-outs, 'floodmap-hws')">
+              <dc:call-macro name="floodmap-hws-user"/>
+            </dc:if>
+          </dc:context>
+        </dc:call-macro>
 
       </old_calculations>
 
-
-      <dc:comment>
-        Include System specific part when 'load-system' is in parameters.
-        -----------------------------------------------------------------
-      </dc:comment>
-      <dc:choose>
-        <dc:when test="dc:contains($parameters,'load-system')">
-          <dc:call-macro name="load-system"/>
-        </dc:when>
-      </dc:choose>
+      <dc:if test="dc:contains($parameters,'load-system')">
+        <dc:comment>
+          Include System specific part when 'load-system' is in parameters.
+          -----------------------------------------------------------------
+        </dc:comment>
+        <dc:call-macro name="load-system"/>
+      </dc:if>
     </dc:when>
 
-
-    <dc:comment>
-      Include System specific part only if no user ID is given.
-      ---------------------------------------------------------
-    </dc:comment>
     <dc:otherwise>
-        <dc:call-macro name="load-system"/>
+      <dc:comment>
+        Include System specific part only if no user ID is given.
+        ---------------------------------------------------------
+      </dc:comment>
+      <dc:call-macro name="load-system"/>
     </dc:otherwise>
   </dc:choose>
+
 </datacage>
 </dc:template>
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/SQRelationArtifact.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/SQRelationArtifact.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,158 @@
+package de.intevation.flys.artifacts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.data.DefaultStateData;
+import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.flys.artifacts.model.sq.StaticSQRelation;
+import de.intevation.flys.artifacts.resources.Resources;
+import de.intevation.flys.artifacts.states.StaticState;
+import de.intevation.flys.artifacts.states.sq.SQStaticState;
+
+
+public class SQRelationArtifact
+extends AbstractStaticStateArtifact
+{
+    private static final Logger logger =
+        Logger.getLogger(SQRelationArtifact.class);
+
+    public static final String XPATH_RIVER = "/art:action/art:river/@art:name";
+    public static final String XPATH_STATION =
+        "/art:action/art:measurement_station/@art:number";
+    public static final String NAME = "staticsqrelation";
+    public static final String STATIC_STATE_NAME = "state.sqrelation.static";
+    public static final String UIPROVIDER = "static_sqrelation";
+    public static final String SQ_RELATION_OUT_A = "sq_relation_a";
+    public static final String SQ_RELATION_OUT_B = "sq_relation_b";
+    public static final String SQ_RELATION_OUT_C = "sq_relation_c";
+    public static final String SQ_RELATION_OUT_D = "sq_relation_d";
+    public static final String SQ_RELATION_OUT_E = "sq_relation_e";
+    public static final String SQ_RELATION_OUT_F = "sq_relation_f";
+
+
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callmeta,
+        Document        data
+    ) {
+        logger.debug("SQRelationArtifact.setup()");
+
+        String river = XMLUtils.xpathString(
+            data,
+            XPATH_RIVER,
+            ArtifactNamespaceContext.INSTANCE);
+        String station = XMLUtils.xpathString(
+            data,
+            XPATH_STATION,
+            ArtifactNamespaceContext.INSTANCE);
+
+        addData(
+            "river",
+            new DefaultStateData(
+                "river",
+                Resources.getMsg(callmeta, "static.sq.river", "Rivername"),
+                "String",
+                river));
+        addData(
+            "station",
+            new DefaultStateData(
+                "station",
+                Resources.getMsg(callmeta, "static.sq.station", "Station"),
+                "String",
+                station));
+        super.setup(identifier, factory, context, callmeta, data);
+    }
+
+    @Override
+    protected void initStaticState() {
+        StaticState state = new SQStaticState(STATIC_STATE_NAME);
+
+        List<Facet> fs = new ArrayList<Facet>();
+        state.staticCompute(fs, this);
+
+        if (hasParameter(StaticSQRelation.Parameter.A, fs)) {
+            DefaultOutput outputA = new DefaultOutput(
+                SQ_RELATION_OUT_A,
+                "output.static.sqrelation.a",
+                "image/png",
+                fs,
+                "chart");
+            state.addOutput(outputA);
+        }
+        if (hasParameter(StaticSQRelation.Parameter.B, fs)) {
+            DefaultOutput outputB = new DefaultOutput(
+                SQ_RELATION_OUT_B,
+                "output.static.sqrelation.b",
+                "image/png",
+                fs,
+                "chart");
+            state.addOutput(outputB);
+        }
+        if (hasParameter(StaticSQRelation.Parameter.C, fs)) {
+            DefaultOutput outputC = new DefaultOutput(
+                SQ_RELATION_OUT_C,
+                "output.static.sqrelation.c",
+                "image/png",
+                fs,
+                "chart");
+            state.addOutput(outputC);
+        }
+        if (hasParameter(StaticSQRelation.Parameter.D, fs)) {
+            DefaultOutput outputD = new DefaultOutput(
+                SQ_RELATION_OUT_D,
+                "output.static.sqrelation.d",
+                "image/png",
+                fs,
+                "chart");
+            state.addOutput(outputD);
+        }
+        if (hasParameter(StaticSQRelation.Parameter.E, fs)) {
+            DefaultOutput outputE = new DefaultOutput(
+                SQ_RELATION_OUT_E,
+                "output.static.sqrelation.e",
+                "image/png",
+                fs,
+                "chart");
+            state.addOutput(outputE);
+        }
+        if (hasParameter(StaticSQRelation.Parameter.F, fs)) {
+            DefaultOutput outputF = new DefaultOutput(
+                SQ_RELATION_OUT_F,
+                "output.static.sqrelation.f",
+                "image/png",
+                fs,
+                "chart");
+            state.addOutput(outputF);
+        }
+        addFacets(STATIC_STATE_NAME, fs);
+        state.setUIProvider(UIPROVIDER);
+        setStaticState(state);
+    }
+
+    @Override
+    public String getName() {
+        return NAME;
+    }
+
+    private boolean hasParameter(StaticSQRelation.Parameter p, List<Facet> fs) {
+        for (Facet f : fs) {
+            if (f.getName().equals("sq_" +
+                p.toString().toLowerCase() + "_curve")) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java	Tue Apr 02 08:58:24 2013 +0200
@@ -84,21 +84,6 @@
             riverId = 0;
         }
 
-        public int getRiverId() {
-            if (riverId == 0) {
-                String ids = artifact.getDataAsString("ids");
-
-                try {
-                    riverId = Integer.parseInt(ids);
-                }
-                catch (NumberFormatException nfe) {
-                    logger.error("Cannot parse river id from '" + ids + "'");
-                }
-            }
-
-            return riverId;
-        }
-
         protected River getRiver() {
             return RiverFactory.getRiver(getRiverId());
         }
@@ -121,19 +106,46 @@
 
         @Override
         protected Envelope getExtent(boolean reproject) {
-            River      river = getRiver();
-            Floodplain plain = Floodplain.getFloodplain(river.getName());
+            River river = getRiver();
+            List<Floodplain> fps;
 
-            Envelope e = plain.getGeom().getEnvelopeInternal();
+            String kind = getIdPart(2);
 
-            return e != null && reproject
-                ? GeometryUtils.transform(e, getSrid())
-                : e;
+            if (kind != null && ! kind.equals("1")) {
+                fps = Floodplain.getFloodplains(river.getName(),
+                        getName(), Integer.parseInt(kind));
+            } else {
+                fps = Floodplain.getFloodplains(river.getName(), 1);
+            }
+
+            Envelope max = null;
+
+            for (Floodplain fp: fps) {
+                Envelope env = fp.getGeom().getEnvelopeInternal();
+
+                if (max == null) {
+                    max = env;
+                    continue;
+                }
+
+                max.expandToInclude(env);
+            }
+
+            return max != null && reproject
+                ? GeometryUtils.transform(max, getSrid())
+                : max;
         }
 
         @Override
         protected String getFilter() {
-            return "river_id=" + String.valueOf(getRiverId());
+            String kind = getIdPart(2);
+            if (kind != null && ! kind.equals("1")) {
+                return "river_id=" + String.valueOf(getRiverId()) +
+                    " AND kind_id=" + kind +
+                    " AND name='" + getName() + "'";
+            }
+            return "river_id=" + String.valueOf(getRiverId()) +
+                    " AND kind_id=1";
         }
 
         @Override
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryArtifact.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryArtifact.java	Tue Apr 02 08:58:24 2013 +0200
@@ -102,8 +102,14 @@
 
         @Override
         protected Envelope getExtent(boolean reproject) {
-            List<HydrBoundary> boundaries = HydrBoundary.getHydrBoundaries(
-                getRiverId(), getName());
+            List<HydrBoundary> boundaries;
+            String kind = getIdPart(2);
+            if (kind != null) {
+                boundaries = HydrBoundary.getHydrBoundaries(getRiverId(),
+                        getName(), Integer.parseInt(kind));
+            } else {
+                boundaries = HydrBoundary.getHydrBoundaries(getRiverId(), getName());
+            }
 
             Envelope max = null;
 
@@ -125,6 +131,12 @@
 
         @Override
         protected String getFilter() {
+            String kind = getIdPart(2);
+            if (kind != null) {
+                return "river_id=" + String.valueOf(getRiverId())
+                    + " AND name='" + getName() + "'"
+                    + " AND kind = " + kind;
+            }
             return "river_id=" + String.valueOf(getRiverId())
                 + " AND name='" + getName() + "'";
         }
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryPolyArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryPolyArtifact.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryPolyArtifact.java	Tue Apr 02 08:58:24 2013 +0200
@@ -102,8 +102,31 @@
 
         @Override
         protected Envelope getExtent(boolean reproject) {
-            List<HydrBoundaryPoly> boundaries = HydrBoundaryPoly.getHydrBoundaries(
-                getRiverId(), getName());
+            String kind = getIdPart(2);
+            String sectie = getIdPart(3);
+            String sobek = getIdPart(4);
+            int kindId = -1;
+            int sectieId = -1;
+            int sobekId = -1;
+
+            if (kind != null) {
+                kindId = Integer.parseInt(kind);
+            }
+            if (sectie != null && !sectie.equals("-1")) {
+                sectieId = Integer.parseInt(sectie);
+            }
+            if (sobek != null && !sobek.equals("-1")) {
+                sobekId = Integer.parseInt(sobek);
+            }
+
+            List<HydrBoundaryPoly> boundaries;
+            if (kindId == -1 && sobekId == -1 && sectieId == -1) {
+                boundaries = HydrBoundaryPoly.getHydrBoundaries(
+                        getRiverId(), getName());
+            } else {
+                boundaries = HydrBoundaryPoly.getHydrBoundaries(
+                        getRiverId(), kindId, sectieId, sobekId);
+            }
 
             Envelope max = null;
 
@@ -125,8 +148,29 @@
 
         @Override
         protected String getFilter() {
+            // Expected id string:
+            // river_id;layer_name;kind;sectie;sobek
+            String kind = getIdPart(2);
+            String sectie = getIdPart(3);
+            String sobek = getIdPart(4);
+
+            String filter = "";
+            if (kind != null && !kind.equals("-1")) {
+                filter += " AND kind = " + kind;
+            }
+            if (sectie != null && !sectie.equals("-1")) {
+                filter += " AND sectie = " + sectie;
+            }
+            if (sobek != null && !sobek.equals("-1")) {
+                filter += " AND sobek = " + sobek;
+            }
+
+            if (filter.isEmpty()) {
+                filter = " AND name='" + getName() + "'";
+            }
+
             return "river_id=" + String.valueOf(getRiverId())
-                + " AND name='" + getName() + "'";
+                + filter;
         }
 
         @Override
@@ -134,10 +178,10 @@
             String srid = getSrid();
 
             if (FLYSUtils.isUsingOracle()) {
-                return "geom FROM hydr_boundaries USING SRID " + srid;
+                return "geom FROM hydr_boundaries_poly USING SRID " + srid;
             }
             else {
-                return "geom FROM hydr_boundaries USING UNIQUE id USING SRID " + srid;
+                return "geom FROM hydr_boundaries_poly USING UNIQUE id USING SRID " + srid;
             }
         }
 
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/StaticSQRelationAccess.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/StaticSQRelationAccess.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,31 @@
+package de.intevation.flys.artifacts.access;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+
+public class StaticSQRelationAccess
+extends RiverAccess
+{
+    /** The logger that is used in this state. */
+    private static final Logger logger =
+        Logger.getLogger(StaticSQRelationAccess.class);
+
+    private String measurementStation;
+
+    public StaticSQRelationAccess(FLYSArtifact artifact) {
+        super(artifact);
+    }
+
+    /** Get measurement station */
+    public String getMeasurementStation() {
+        if (measurementStation == null) {
+            measurementStation = getString("station");
+        }
+        if (logger.isDebugEnabled()) {
+            logger.debug("measurement station: '" + measurementStation + "'");
+        }
+        return measurementStation;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java	Tue Apr 02 08:58:24 2013 +0200
@@ -32,6 +32,7 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
 
 
 /** Handles and evaluate meta-data template against dbs. */
@@ -185,7 +186,7 @@
         }
 
         /**
-         * Handle a \<context\> node.
+         * Handle a dc:context node.
          */
         protected void context(Node parent, Element current)
         throws SQLException
@@ -282,72 +283,82 @@
             return new ResultData(rd.getColumnLabels(), filtered);
         }
 
+        protected void filter(Node parent, Element current)
+        throws SQLException
+        {
+            String expr = current.getAttribute("expr");
+
+            if ((expr = expr.trim()).length() == 0) {
+                expr = null;
+            }
+
+            NodeList subs = current.getChildNodes();
+            int S = subs.getLength();
+            if (S == 0) {
+                log.debug("dc:filter has no children");
+                return;
+            }
+
+            ResultData orig = null;
+            Pair<Builder.NamedConnection, ResultData> pair = null;
+
+            if (expr != null && !connectionsStack.isEmpty()) {
+                pair = connectionsStack.peek();
+                orig = pair.getB();
+                pair.setB(createFilteredResultData(orig, expr));
+            }
+
+            try {
+                for (int i = 0; i < S; ++i) {
+                    build(parent, subs.item(i));
+                }
+            }
+            finally {
+                if (orig != null) {
+                    pair.setB(orig);
+                }
+            }
+        }
+
         /**
          * Kind of foreach over results of a statement within a context.
          */
-        protected void elements(Node parent, Element current)
+        protected void foreach(Node parent, Element current)
         throws SQLException
         {
-            log.debug("dc:elements");
+            log.debug("dc:for-each");
 
             if (connectionsStack.isEmpty()) {
-                log.warn("dc:elements without having results");
+                log.debug("dc:for-each without having results");
                 return;
             }
 
-            String filter = current.getAttribute("filter");
-
-            if ((filter = filter.trim()).length() == 0) {
-                filter = null;
-            }
-
             NodeList subs = current.getChildNodes();
             int S = subs.getLength();
 
             if (S == 0) {
-                log.debug("dc:elements has no children");
+                log.debug("dc:for-each has no children");
                 return;
             }
 
             Pair<Builder.NamedConnection, ResultData> pair =
                 connectionsStack.peek();
 
-            ResultData rd = connectionsStack.peek().getB();
-            ResultData orig = rd;
+            ResultData rd = pair.getB();
 
-            if (filter != null) {
-                ResultData rdCopy = createFilteredResultData(rd, filter);
-                pair.setB(rdCopy);
-                rd = rdCopy;
-            }
-            try {
-                String [] columns = rd.getColumnLabels();
+            String [] columns = rd.getColumnLabels();
 
-                //if (log.isDebugEnabled()) {
-                //    log.debug("pushing vars: "
-                //        + java.util.Arrays.toString(columns));
-                //}
-
-                for (Object [] row: rd.getRows()) {
-                    frames.enter();
-                    try {
-                        frames.put(columns, row);
-                        //if (log.isDebugEnabled()) {
-                        //    log.debug("current vars: " + frames.dump());
-                        //}
-                        for (int i = 0; i < S; ++i) {
-                            build(parent, subs.item(i));
-                        }
-                    }
-                    finally {
-                        frames.leave();
+            for (Object [] row: rd.getRows()) {
+                frames.enter();
+                try {
+                    frames.put(columns, row);
+                    for (int i = 0; i < S; ++i) {
+                        build(parent, subs.item(i));
                     }
                 }
-            }
-            finally {
-                 if (filter != null) {
-                     pair.setB(orig);
-                 }
+                finally {
+                    frames.leave();
+                }
             }
         }
 
@@ -660,45 +671,47 @@
                 }
                 else {
                     String localName = current.getLocalName();
+                    Element curr = (Element)current;
                     if ("attribute".equals(localName)) {
-                        attribute(parent, (Element)current);
+                        attribute(parent, curr);
                     }
                     else if ("context".equals(localName)) {
-                        context(parent, (Element)current);
+                        context(parent, curr);
                     }
                     else if ("if".equals(localName)) {
-                        ifClause(parent, (Element)current);
+                        ifClause(parent, curr);
                     }
                     else if ("choose".equals(localName)) {
-                        choose(parent, (Element)current);
+                        choose(parent, curr);
                     }
                     else if ("call-macro".equals(localName)) {
-                        callMacro(parent, (Element)current);
+                        callMacro(parent, curr);
                     }
                     else if ("macro-body".equals(localName)) {
-                        macroBody(parent, (Element)current);
+                        macroBody(parent, curr);
                     }
-                    else if ("macro".equals(localName)) {
-                        // Simply ignore the definition.
+                    else if ("macro".equals(localName)
+                         ||  "comment".equals(localName)
+                         ||  "statement".equals(localName)) {
+                        // Simply ignore them.
                     }
                     else if ("element".equals(localName)) {
-                        element(parent, (Element)current);
+                        element(parent, curr);
                     }
-                    else if ("elements".equals(localName)) {
-                        elements(parent, (Element)current);
+                    else if ("for-each".equals(localName)) {
+                        foreach(parent, curr);
+                    }
+                    else if ("filter".equals(localName)) {
+                        filter(parent, curr);
                     }
                     else if ("text".equals(localName)) {
-                        text(parent, (Element)current);
+                        text(parent, curr);
                     }
                     else if ("variable".equals(localName)) {
-                        variable((Element)current);
-                    }
-                    else if ("comment".equals(localName)
-                         ||  "statement".equals(localName)) {
-                        // ignore comments and statements in output
+                        variable(curr);
                     }
                     else if ("convert".equals(localName)) {
-                        convert((Element)current);
+                        convert(curr);
                     }
                     else {
                         log.warn("unknown '" + localName + "' -> ignore");
@@ -721,13 +734,17 @@
 
             Node copy = owner.importNode(current, false);
 
-            if (copy.getNodeType() == Node.ATTRIBUTE_NODE) {
-                evaluateAttributeValue((Attr)copy);
+            NodeList children = current.getChildNodes();
+            for (int i = 0, N = children.getLength(); i < N; ++i) {
+                build(copy, children.item(i));
             }
-            else {
-                NodeList children = current.getChildNodes();
-                for (int i = 0, N = children.getLength(); i < N; ++i) {
-                    build(copy, children.item(i));
+            if (copy.getNodeType() == Node.ELEMENT_NODE) {
+                NamedNodeMap nnm = ((Element)copy).getAttributes();
+                for (int i = 0, N = nnm.getLength(); i < N; ++i) {
+                    Node n = nnm.item(i);
+                    if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
+                        evaluateAttributeValue((Attr)n);
+                    }
                 }
             }
             parent.appendChild(copy);
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQCacheKey.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQCacheKey.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,30 @@
+package de.intevation.flys.artifacts.model.sq;
+
+import java.io.Serializable;
+
+
+public class StaticSQCacheKey
+implements Serializable
+{
+    public static final String CACHE_NAME = "static-sq-relation";
+
+    private String river;
+    private int measurementId;
+
+    public StaticSQCacheKey(String river, int measurementId) {
+        this.river = river;
+        this.measurementId = measurementId;
+    }
+
+    public int hashCode() {
+        return this.river.hashCode() | measurementId;
+    }
+
+    public boolean equals(Object other) {
+        if (!(other instanceof StaticSQCacheKey)) {
+            return false;
+        }
+        StaticSQCacheKey o = (StaticSQCacheKey) other;
+        return this.river == o.river && this.measurementId == o.measurementId;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQContainer.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQContainer.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,85 @@
+package de.intevation.flys.artifacts.model.sq;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class StaticSQContainer
+{
+    private String description;
+    private String stationName;
+    private double km;
+
+    private List<StaticSQRelation> relations;
+
+
+    public StaticSQContainer() {
+        relations = new ArrayList<StaticSQRelation>();
+    }
+
+    public StaticSQContainer(
+        String stationName,
+        String description,
+        double km
+    ) {
+        this.stationName = stationName;
+        this.description = description;
+        this.km = km;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getStationName() {
+        return stationName;
+    }
+
+    public void setStationName(String stationName) {
+        this.stationName = stationName;
+    }
+
+    public double getKm() {
+        return km;
+    }
+
+    public void setKm(double km) {
+        this.km = km;
+    }
+
+    public List<StaticSQRelation> getSQRelations() {
+        return relations;
+    }
+
+    public void setSQRelations(List<StaticSQRelation> relations) {
+        this.relations = relations;
+    }
+
+    public void addSQRelation(StaticSQRelation relation) {
+        this.relations.add(relation);
+    }
+
+    public StaticSQRelation getSQRelation(int ndx) {
+        return this.relations.get(ndx);
+    }
+
+    public int size() {
+        return this.relations.size();
+    }
+
+    public List<StaticSQRelation> getRelationsByParameter(
+        StaticSQRelation.Parameter parameter
+    ) {
+        List<StaticSQRelation> result = new ArrayList<StaticSQRelation>();
+        for (StaticSQRelation relation : relations) {
+            if (relation.getParameter() == parameter) {
+                result.add(relation);
+            }
+        }
+        return result;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQFactory.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQFactory.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,123 @@
+package de.intevation.flys.artifacts.model.sq;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import org.apache.log4j.Logger;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import de.intevation.flys.artifacts.cache.CacheFactory;
+import de.intevation.flys.backend.SessionHolder;
+
+
+public class StaticSQFactory
+{
+    private static final Logger log =
+        Logger.getLogger(StaticSQFactory.class);
+
+    public static final String SQL_SQ =
+        "SELECT " +
+            "sq.description AS description,"+
+            "ti.start_time  AS start_time," +
+            "ti.stop_time    AS stop_time, " +
+            "ms.name AS station_name, " +
+            "ms.station AS station_km, " +
+            "ms.measurement_type AS measurement_type, " +
+            "sqv.parameter AS parameter, " +
+            "sqv.a AS a, " +
+            "sqv.b AS b, " +
+            "sqv.qmax AS qmax " +
+        "FROM sq_relation sq " +
+            "JOIN time_intervals ti ON ti.id   = sq.time_interval_id " +
+            "JOIN rivers r ON r.id = sq.river_id " +
+            "JOIN sq_relation_value sqv ON sqv.sq_relation_id = sq.id " +
+            "JOIN measurement_station ms ON sqv.measurement_station_id = ms.id " +
+        "WHERE " +
+            "r.name = :river " +
+            "AND ms.id = :ms_id ";
+
+
+    private StaticSQFactory() {
+    }
+
+    public static StaticSQContainer getSQRelations(
+        String river,
+        int measurementStation
+    ) {
+        Cache cache = CacheFactory.getCache(StaticSQCacheKey.CACHE_NAME);
+
+        StaticSQCacheKey cacheKey;
+
+        if (cache != null) {
+            cacheKey = new StaticSQCacheKey(river, measurementStation);
+            Element element = cache.get(cacheKey);
+            if (element != null) {
+                log.debug("Got static bedheight values from cache");
+                return (StaticSQContainer)element.getValue();
+            }
+        }
+        else {
+            cacheKey = null;
+        }
+
+        StaticSQContainer values = getUncached(river, measurementStation);
+
+        if (values != null && cacheKey != null) {
+            log.debug("Store static sq relations in cache.");
+            Element element = new Element(cacheKey, values);
+            cache.put(element);
+        }
+        return values;
+    }
+
+    private static StaticSQContainer getUncached(
+        String river,
+        int measurementStation
+    ) {
+        Session session = SessionHolder.HOLDER.get();
+
+        Query query = session.createSQLQuery(SQL_SQ)
+            .addScalar("description")
+            .addScalar("start_time")
+            .addScalar("stop_time")
+            .addScalar("station_name")
+            .addScalar("station_km")
+            .addScalar("measurement_type")
+            .addScalar("parameter")
+            .addScalar("a")
+            .addScalar("b")
+            .addScalar("qmax");
+
+        query.setParameter("river", river);
+        query.setParameter("ms_id", measurementStation);
+
+        List<Object []> list = query.list();
+
+        if (list.isEmpty()) {
+            return new StaticSQContainer();
+        }
+
+        StaticSQContainer sq = new StaticSQContainer();
+        sq.setDescription((String)list.get(0)[0]);
+        sq.setStationName((String)list.get(0)[3]);
+        sq.setKm(((BigDecimal)list.get(0)[4]).doubleValue());
+
+        for (Object[] row : list) {
+            StaticSQRelation relation = new StaticSQRelation();
+            relation.setStartTime((Date)row[1]);
+            relation.setStopTime((Date)row[2]);
+            relation.setType((String)row[5]);
+            relation.setParameter((String)row[6]);
+            relation.setA(((BigDecimal)row[7]).doubleValue());
+            relation.setB(((BigDecimal)row[8]).doubleValue());
+            relation.setQmax(((BigDecimal)row[9]).doubleValue());
+            sq.addSQRelation(relation);
+        }
+        return sq;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQRelation.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/StaticSQRelation.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,103 @@
+package de.intevation.flys.artifacts.model.sq;
+
+import java.io.Serializable;
+import java.util.Date;
+
+
+public class StaticSQRelation implements Serializable{
+
+    private Date startTime;
+    private Date stopTime;
+    private String type;
+    private Parameter parameter;
+    private double a;
+    private double b;
+    private double qmax;
+
+    public static enum Parameter {
+        A, B, C, D, E, F
+    }
+
+
+    public StaticSQRelation() {
+    }
+
+    public StaticSQRelation(
+        Date startTime,
+        Date stopTime,
+        String type,
+        Parameter parameter,
+        double a,
+        double b
+    ) {
+        this.startTime = startTime;
+        this.stopTime = stopTime;
+        this.type = type;
+        this.parameter = parameter;
+        this.a = a;
+        this.b = b;
+    }
+
+    public Date getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Date startTime) {
+        this.startTime = startTime;
+    }
+
+    public Date getStopTime() {
+        return stopTime;
+    }
+
+    public void setStopTime(Date stopTime) {
+        this.stopTime = stopTime;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Parameter getParameter() {
+        return parameter;
+    }
+
+    public void setParameter(Parameter parameter) {
+        this.parameter = parameter;
+    }
+
+    public void setParameter(String parameter) {
+        if (parameter == null) {
+            return;
+        }
+        this.parameter = Parameter.valueOf(parameter);
+    }
+
+    public double getA() {
+        return a;
+    }
+
+    public void setA(double a) {
+        this.a = a;
+    }
+
+    public double getB() {
+        return b;
+    }
+
+    public void setB(double b) {
+        this.b = b;
+    }
+
+    public double getQmax() {
+        return qmax;
+    }
+
+    public void setQmax(double qmax) {
+        this.qmax = qmax;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MeasurementStationInfoService.java	Tue Apr 02 08:58:24 2013 +0200
@@ -15,7 +15,6 @@
 import de.intevation.artifacts.GlobalContext;
 
 import de.intevation.flys.model.MeasurementStation;
-import de.intevation.flys.model.Gauge;
 import de.intevation.flys.model.Range;
 import de.intevation.flys.model.TimeInterval;
 
@@ -106,8 +105,7 @@
                 }
             }
 
-            Gauge gauge = mstation.getGauge();
-            String gaugename = gauge.getName();
+            String gaugename= mstation.getGaugeName();
 
             if (gaugename != null) {
                 Element egauge = ec.create("gauge");
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/sq/SQStaticState.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/sq/SQStaticState.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,80 @@
+package de.intevation.flys.artifacts.states.sq;
+
+import java.text.DateFormat;
+import java.util.List;
+
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.access.StaticSQRelationAccess;
+import de.intevation.flys.artifacts.model.sq.StaticSQContainer;
+import de.intevation.flys.artifacts.model.sq.StaticSQFactory;
+import de.intevation.flys.artifacts.model.sq.StaticSQRelation;
+import de.intevation.flys.artifacts.states.StaticState;
+
+
+public class SQStaticState
+extends StaticState
+{
+    private static final Logger log =
+        Logger.getLogger(SQStaticState.class);
+
+    public SQStaticState() {
+        super();
+    }
+
+    public SQStaticState(String name) {
+        super(name);
+    }
+
+    @Override
+    public Object staticCompute(
+        List<Facet> facets,
+        FLYSArtifact artifact
+    ) {
+        StaticSQRelationAccess access = new StaticSQRelationAccess(artifact);
+
+        String river = access.getRiver();
+        String measurementStation = access.getMeasurementStation();
+
+        int ms = -1;
+        try {
+            ms = Integer.parseInt(measurementStation);
+        }
+        catch (NumberFormatException nfe) {
+            log.error("Unparseable measurement station: " + measurementStation);
+            return null;
+        }
+
+        StaticSQContainer sqRelations =
+            StaticSQFactory.getSQRelations(river, ms);
+
+        for (StaticSQRelation.Parameter p: StaticSQRelation.Parameter.values()) {
+
+            List<StaticSQRelation> relations =
+                sqRelations.getRelationsByParameter(p);
+
+            if (!relations.isEmpty()) {
+                int count = 0;
+
+                for (StaticSQRelation relation : relations) {
+                    String name = "sq_" + p.toString().toLowerCase() + "_curve";
+                    DateFormat df =
+                        DateFormat.getDateInstance(DateFormat.SHORT);
+                    String desc = p.toString() + ": " +
+                        df.format(relation.getStartTime()) + " - " +
+                        df.format(relation.getStopTime());
+                    facets.add(new StaticSQRelationFacet(
+                        count,
+                        name,
+                        desc,
+                        relation));
+                    count++;
+                }
+            }
+        }
+        return null;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/sq/StaticSQRelationFacet.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/sq/StaticSQRelationFacet.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,49 @@
+package de.intevation.flys.artifacts.states.sq;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+import de.intevation.flys.artifacts.math.fitting.Function;
+import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
+import de.intevation.flys.artifacts.model.sq.SQFunction;
+import de.intevation.flys.artifacts.model.sq.StaticSQRelation;
+
+
+public class StaticSQRelationFacet
+extends DefaultFacet
+implements Facet
+{
+    public static final String FUNCTION = "sq-pow";
+
+    private StaticSQRelation relation;
+
+
+    public StaticSQRelationFacet(
+        int ndx,
+        String name,
+        String description,
+        StaticSQRelation relation) {
+        super(ndx, name, description);
+        this.relation = relation;
+    }
+
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        double qmax = relation.getQmax();
+        double[] coeffs = new double[] {relation.getA(), relation.getB()};
+        Function func = FunctionFactory.getInstance().getFunction(FUNCTION);
+        de.intevation.flys.artifacts.math.Function function =
+            func.instantiate(coeffs);
+        SQFunction sqf = new SQFunction(function, 0, qmax);
+        return sqf;
+    }
+
+    @Override
+    public Facet deepCopy() {
+        StaticSQRelationFacet copy =
+            new StaticSQRelationFacet(index, name, description, relation);
+        copy.set(this);
+        return copy;
+    }
+}
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/resources/messages.properties
--- a/flys-artifacts/src/main/resources/messages.properties	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/resources/messages.properties	Tue Apr 02 08:58:24 2013 +0200
@@ -592,6 +592,8 @@
 sq.km.chart.title = Measuring Points
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Date
+static.sq.river = River
+static.sq.station = Station
 
 module.winfo = WINFO
 module.minfo = MINFO
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/resources/messages_de.properties
--- a/flys-artifacts/src/main/resources/messages_de.properties	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Tue Apr 02 08:58:24 2013 +0200
@@ -595,6 +595,8 @@
 sq.km.chart.title = Messstellen
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Datum
+static.sq.river = Gewaesser
+static.sq.station = Messstelle
 
 module.winfo = WINFO
 module.minfo = MINFO
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/resources/messages_de_DE.properties
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Tue Apr 02 08:58:24 2013 +0200
@@ -593,6 +593,8 @@
 sq.km.chart.title = Messstellen
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Datum
+static.sq.river = Gewaesser
+static.sq.station = Messstelle
 
 module.winfo = WINFO
 module.minfo = MINFO
diff -r 6dbc111e9aec -r 33d735f5433e flys-artifacts/src/main/resources/messages_en.properties
--- a/flys-artifacts/src/main/resources/messages_en.properties	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Tue Apr 02 08:58:24 2013 +0200
@@ -593,6 +593,8 @@
 sq.km.chart.title = Measuring Points
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Date
+static.sq.river = River
+static.sq.station = Station
 
 module.winfo = WINFO
 module.minfo = MINFO
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/contrib/shpimporter/boundaries.py
--- a/flys-backend/contrib/shpimporter/boundaries.py	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/contrib/shpimporter/boundaries.py	Tue Apr 02 08:58:24 2013 +0200
@@ -32,7 +32,7 @@
     def isShapeRelevant(self, name, path):
         shp = ogr.Open(path)
         if self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) and \
-                self.getKind(path) > 0:
+                self.getKind(path) > 0 and not "talaue" in path.lower():
             return True
         else:
             return False
@@ -59,9 +59,13 @@
         newFeat.SetField("kind", kind)
         if self.IsFieldSet(feat, "SECTIE"):
             newFeat.SetField("sectie", feat.GetField("SECTIE"))
+        else:
+            newFeat.SetField("sectie", 0)
 
         if self.IsFieldSet(feat, "SOBEK"):
             newFeat.SetField("sobek", feat.GetField("SOBEK"))
+        else:
+            newFeat.SetField("sobek", 0)
 
         if self.IsFieldSet(feat, "river_id"):
             newFeat.SetField("river_id", feat.GetField("river_id"))
@@ -102,10 +106,13 @@
 
         if self.IsFieldSet(feat, "SECTIE"):
             newFeat.SetField("sectie", feat.GetField("SECTIE"))
+        else:
+            newFeat.SetField("sectie", 0)
 
         if self.IsFieldSet(feat, "SOBEK"):
             newFeat.SetField("sobek", feat.GetField("SOBEK"))
-
+        else:
+            newFeat.SetField("sobek", 0)
 
         if self.IsFieldSet(feat, "river_id"):
             newFeat.SetField("river_id", feat.GetField("river_id"))
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/doc/schema/oracle-minfo.sql
--- a/flys-backend/doc/schema/oracle-minfo.sql	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/doc/schema/oracle-minfo.sql	Tue Apr 02 08:58:24 2013 +0200
@@ -137,6 +137,7 @@
     id                  NUMBER(38,0) NOT NULL,
     sediment_density_id NUMBER(38,0) NOT NULL,
     station             NUMBER(38,2) NOT NULL,
+    shore_offset	NUMBER(38,2),
     density             NUMBER(38,2) NOT NULL,
     description         VARCHAR(256),
     year                NUMBER(38,0),
@@ -322,7 +323,7 @@
     parameter                VARCHAR(1) NOT NULL,
     a                        NUMBER(38,20) NOT NULL,
     b                        NUMBER(38,20) NOT NULL,
-    qmax                     NUMBER(38,20),
+    qmax                     NUMBER(38,20) NOT NULL,
     rsq                      NUMBER(38,3),
     ntot                     NUMBER(38,0),
     noutl                    NUMBER(38,0),
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/doc/schema/oracle-spatial.sql
--- a/flys-backend/doc/schema/oracle-spatial.sql	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/doc/schema/oracle-spatial.sql	Tue Apr 02 08:58:24 2013 +0200
@@ -5,7 +5,7 @@
     name VARCHAR(64)
 );
 INSERT INTO axis_kinds(id, name) VALUES (0, 'Unbekannt');
-INSERT INTO axis_kinds(id, name) VALUES (1, 'Aktuell');
+INSERT INTO axis_kinds(id, name) VALUES (1, 'aktuelle Achse');
 INSERT INTO axis_kinds(id, name) VALUES (2, 'Sonstige');
 
 -- Geodaesie/Flussachse+km/achse
@@ -54,7 +54,7 @@
     name VARCHAR(64)
 );
 INSERT INTO cross_section_track_kinds(id, name) VALUES (0, 'Sonstige');
-INSERT INTO cross_section_track_kinds(id, name) VALUES (1, 'Aktuell');
+INSERT INTO cross_section_track_kinds(id, name) VALUES (1, 'aktuelle Querprofilspuren');
 
 CREATE SEQUENCE CROSS_SECTION_TRACKS_ID_SEQ;
 CREATE TABLE cross_section_tracks (
@@ -137,7 +137,7 @@
     name VARCHAR(64)
 );
 INSERT INTO floodplain_kinds(id, name) VALUES (0, 'Sonstige');
-INSERT INTO floodplain_kinds(id, name) VALUES (1, 'Aktuell');
+INSERT INTO floodplain_kinds(id, name) VALUES (1, 'aktuelle Talaue');
 
 CREATE SEQUENCE FLOODPLAIN_ID_SEQ;
 CREATE TABLE floodplain(
@@ -242,7 +242,7 @@
     id NUMBER PRIMARY KEY NOT NULL,
     name VARCHAR(64) NOT NULL
 );
-INSERT INTO sectie_kinds (id, name) VALUES (0, 'Unbekannt');
+INSERT INTO sectie_kinds (id, name) VALUES (0, 'SECTIE Unbekannt');
 INSERT INTO sectie_kinds (id, name) VALUES (1, 'Flussschlauch');
 INSERT INTO sectie_kinds (id, name) VALUES (2, 'Uferbank');
 INSERT INTO sectie_kinds (id, name) VALUES (3, 'Überflutungsbereich');
@@ -251,7 +251,7 @@
     id NUMBER PRIMARY KEY NOT NULL,
     name VARCHAR(64) NOT NULL
 );
-INSERT INTO sobek_kinds (id, name) VALUES (0, 'Unbekannt');
+INSERT INTO sobek_kinds (id, name) VALUES (0, 'SOBEK Unbekannt');
 INSERT INTO sobek_kinds (id, name) VALUES (1, 'Stromführend');
 INSERT INTO sobek_kinds (id, name) VALUES (2, 'Stromspeichernd');
 
@@ -337,9 +337,9 @@
     GEOM MDSYS.SDO_GEOMETRY,
     river_id NUMBER(38) REFERENCES rivers(id) ON DELETE CASCADE,
     name VARCHAR(255),
-    kind   NUMBER(38) REFERENCES boundary_kinds(id),
-    sectie NUMBER(38) REFERENCES sectie_kinds(id),
-    sobek  NUMBER(38) REFERENCES sobek_kinds(id),
+    kind   NUMBER(38) REFERENCES boundary_kinds(id) NOT NULL DEFAULT 0,
+    sectie NUMBER(38) REFERENCES sectie_kinds(id) NOT NULL DEFAULT 0,
+    sobek  NUMBER(38) REFERENCES sobek_kinds(id) NOT NULL DEFAULT 0,
     path     VARCHAR(256),
     id NUMBER PRIMARY KEY NOT NULL
 );
@@ -356,9 +356,9 @@
     GEOM MDSYS.SDO_GEOMETRY,
     river_id NUMBER(38) REFERENCES rivers(id) ON DELETE CASCADE,
     name VARCHAR(255),
-    kind   NUMBER(38) REFERENCES boundary_kinds(id),
-    sectie NUMBER(38) REFERENCES sectie_kinds(id),
-    sobek  NUMBER(38) REFERENCES sobek_kinds(id),
+    kind   NUMBER(38) REFERENCES boundary_kinds(id) NOT NULL DEFAULT 0,
+    sectie NUMBER(38) REFERENCES sectie_kinds(id) NOT NULL DEFAULT 0,
+    sobek  NUMBER(38) REFERENCES sobek_kinds(id) NOT NULL DEFAULT 0,
     path     VARCHAR(256),
     id NUMBER PRIMARY KEY NOT NULL
 );
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/doc/schema/postgresql-minfo.sql
--- a/flys-backend/doc/schema/postgresql-minfo.sql	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-minfo.sql	Tue Apr 02 08:58:24 2013 +0200
@@ -137,6 +137,7 @@
     id                  int NOT NULL,
     sediment_density_id int NOT NULL,
     station             NUMERIC NOT NULL,
+    shore_offset	NUMERIC,
     density             NUMERIC NOT NULL,
     description         VARCHAR(256),
     year                int,
@@ -322,7 +323,7 @@
     parameter              VARCHAR(1) NOT NULL,
     a                      NUMERIC NOT NULL,
     b                      NUMERIC NOT NULL,
-    qmax                   NUMERIC,
+    qmax                   NUMERIC NOT NULL,
     rsq                    NUMERIC,
     ntot                   int,
     noutl                  int,
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/doc/schema/postgresql-spatial.sql
--- a/flys-backend/doc/schema/postgresql-spatial.sql	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-spatial.sql	Tue Apr 02 08:58:24 2013 +0200
@@ -5,7 +5,7 @@
     name VARCHAR(64)
 );
 INSERT INTO axis_kinds(id, name) VALUES (0, 'Unbekannt');
-INSERT INTO axis_kinds(id, name) VALUES (1, 'Aktuell');
+INSERT INTO axis_kinds(id, name) VALUES (1, 'aktuelle Achse');
 INSERT INTO axis_kinds(id, name) VALUES (2, 'Sonstige');
 
 -- Geodaesie/Flussachse+km/achse
@@ -41,7 +41,7 @@
     name VARCHAR(64)
 );
 INSERT INTO cross_section_track_kinds(id, name) VALUES (0, 'Sonstige');
-INSERT INTO cross_section_track_kinds(id, name) VALUES (1, 'Aktuell');
+INSERT INTO cross_section_track_kinds(id, name) VALUES (1, 'aktuelle Querprofilspuren');
 
 CREATE SEQUENCE CROSS_SECTION_TRACKS_ID_SEQ;
 CREATE TABLE cross_section_tracks (
@@ -102,7 +102,7 @@
     name VARCHAR(64)
 );
 INSERT INTO floodplain_kinds(id, name) VALUES (0, 'Sonstige');
-INSERT INTO floodplain_kinds(id, name) VALUES (1, 'Aktuell');
+INSERT INTO floodplain_kinds(id, name) VALUES (1, 'aktuelle Talaue');
 
 CREATE SEQUENCE FLOODPLAIN_ID_SEQ;
 CREATE TABLE floodplain (
@@ -250,7 +250,7 @@
     id int PRIMARY KEY NOT NULL,
     name VARCHAR(64) NOT NULL
 );
-INSERT INTO sectie_kinds (id, name) VALUES (0, 'Unbekannt');
+INSERT INTO sectie_kinds (id, name) VALUES (0, 'SECTIE Unbekannt');
 INSERT INTO sectie_kinds (id, name) VALUES (1, 'Flussschlauch');
 INSERT INTO sectie_kinds (id, name) VALUES (2, 'Uferbank');
 INSERT INTO sectie_kinds (id, name) VALUES (3, 'Überflutungsbereich');
@@ -259,7 +259,7 @@
     id int PRIMARY KEY NOT NULL,
     name VARCHAR(64) NOT NULL
 );
-INSERT INTO sobek_kinds (id, name) VALUES (0, 'Unbekannt');
+INSERT INTO sobek_kinds (id, name) VALUES (0, 'SOBEK Unbekannt');
 INSERT INTO sobek_kinds (id, name) VALUES (1, 'Stromführend');
 INSERT INTO sobek_kinds (id, name) VALUES (2, 'Stromspeichernd');
 
@@ -277,9 +277,9 @@
     id         int PRIMARY KEY NOT NULL,
     river_id   int REFERENCES rivers(id) ON DELETE CASCADE,
     name       VARCHAR(255),
-    kind       int REFERENCES boundary_kinds(id),
-    sectie     int REFERENCES sectie_kinds(id),
-    sobek      int REFERENCES sobek_kinds(id),
+    kind       int REFERENCES boundary_kinds(id) NOT NULL DEFAULT 0,
+    sectie     int REFERENCES sectie_kinds(id) NOT NULL DEFAULT 0,
+    sobek      int REFERENCES sobek_kinds(id) NOT NULL DEFAULT 0,
     path       VARCHAR(256)
 );
 SELECT AddGeometryColumn('hydr_boundaries','geom',31467,'MULTILINESTRING',3);
@@ -291,9 +291,9 @@
     id         int PRIMARY KEY NOT NULL,
     river_id   int REFERENCES rivers(id) ON DELETE CASCADE,
     name       VARCHAR(255),
-    kind       int REFERENCES boundary_kinds(id),
-    sectie     int REFERENCES sectie_kinds(id),
-    sobek      int REFERENCES sobek_kinds(id),
+    kind       int REFERENCES boundary_kinds(id) NOT NULL DEFAULT 0,
+    sectie     int REFERENCES sectie_kinds(id) NOT NULL DEFAULT 0,
+    sobek      int REFERENCES sobek_kinds(id) NOT NULL DEFAULT 0,
     path       VARCHAR(256)
 );
 SELECT AddGeometryColumn('hydr_boundaries_poly','geom',31467,'MULTIPOLYGON',3);
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/ImportMeasurementStation.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportMeasurementStation.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportMeasurementStation.java	Tue Apr 02 08:58:24 2013 +0200
@@ -71,7 +71,7 @@
             }
 
             if (range == null) {
-                log.warn("No range found for measurement station'" + name + "'");
+                log.warn("No range found for measurement station '" + name + "'");
             }
 
             TimeInterval observationTimerange = this.observationTimerange
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelationValue.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelationValue.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelationValue.java	Tue Apr 02 08:58:24 2013 +0200
@@ -80,7 +80,7 @@
             List<MeasurementStation> result = query.list();
 
             if (result.isEmpty()) {
-                log.error("No measurement stations found.");
+                log.error("No measurement stations found at km " + km);
                 return null;
             }
 
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java	Tue Apr 02 08:58:24 2013 +0200
@@ -23,6 +23,8 @@
 
     protected BigDecimal station;
 
+    protected BigDecimal shoreOffset;
+
     protected BigDecimal density;
 
     private BigDecimal year;
@@ -32,11 +34,13 @@
 
     public ImportSedimentDensityValue(
         BigDecimal station,
+        BigDecimal shoreOffset,
         BigDecimal density,
         BigDecimal year,
         String     description
     ) {
         this.station     = station;
+        this.shoreOffset = shoreOffset;
         this.density     = density;
         this.year        = year;
         this.description = description;
@@ -60,12 +64,14 @@
                 "from SedimentDensityValue where " +
                 "   sedimentDensity=:sedimentDensity and " +
                 "   station=:station and " +
+                "   shoreOffset=:shoreOffset and " +
                 "   density=:density and " +
                 "   year=:year and " +
                 "   description=:description");
 
             query.setParameter("sedimentDensity", sedimentDensity);
             query.setParameter("station", station);
+            query.setParameter("shoreOffset", shoreOffset);
             query.setParameter("density", density);
             query.setParameter("year", year);
             query.setParameter("description", description);
@@ -77,6 +83,7 @@
                 peer = new SedimentDensityValue(
                     sedimentDensity,
                     station,
+                    shoreOffset,
                     density,
                     year,
                     description);
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -45,7 +45,7 @@
             km = new BigDecimal(nf.parse(values[0]).doubleValue());
         }
         catch (ParseException e) {
-            log.warn("Error while parsing number from data row: " + line);
+            log.warn("Unparseable number in data row: " + line);
             return;
         }
 
@@ -70,7 +70,7 @@
             obj.addValue(value);
         }
         catch (ParseException e) {
-            log.warn("Error while parsing number from data row: " + line);
+            log.warn("Unparseable number in data row: " + line);
         }
     }
 }
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -235,7 +235,7 @@
                 obj.setTimeInterval(new ImportTimeInterval(fromYear, toYear));
             }
             catch (NumberFormatException e) {
-                log.warn("BHP: Error while parsing timeinterval!", e);
+                log.warn("BHP: could not parse timeinterval", e);
             }
 
             return true;
@@ -256,7 +256,7 @@
                 return true;
             }
             catch (NumberFormatException e) {
-                log.warn("BHP: Error while parsing sounding width: " + line, e);
+                log.warn("BHP: Could not parse sounding width: " + line, e);
                 log.warn("-> Set default value '0'");
             }
             obj.setSoundingWidth(0);
@@ -316,7 +316,7 @@
                 return true;
             }
             catch (ParseException e) {
-                log.warn("BHP: Error while parsing range!", e);
+                log.warn("BHP: could not parse range", e);
             }
         }
 
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -82,7 +82,7 @@
             obj.addValue(value);
         }
         catch (ParseException e) {
-            log.warn("BSP: Error while parsing data row.", e);
+            log.warn("BSP: unparseable value in data row.", e);
         }
     }
     
@@ -94,7 +94,7 @@
         }
         catch (NumberFormatException nfe) {
             log.warn(
-                "Error parsing " +
+                "Could not parse " +
                 value +
                 " in bed heigt single row: "
                 + line);
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -96,7 +96,7 @@
             ));
         }
         catch (ParseException pe) {
-            log.warn("Error while parsing flow velocity values.", pe);
+            log.warn("Unparseable flow velocity values:", pe);
         }
     }
 }
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -200,7 +200,7 @@
                     new BigDecimal(nf.parse(qStr).doubleValue()) };
             }
             catch (ParseException pe) {
-                log.warn("Error while parsing Q value: '" + qStr + "'");
+                log.warn("Could not parse Q value: '" + qStr + "'");
             }
         }
 
@@ -232,7 +232,7 @@
             ));
         }
         catch (ParseException pe) {
-            log.warn("Error while parsing flow velocity values.", pe);
+            log.warn("Unparseable flow velocity values:", pe);
         }
     }
 }
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/MorphologicalWidthParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/MorphologicalWidthParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/MorphologicalWidthParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -108,7 +108,7 @@
             ));
         }
         catch (ParseException pe) {
-            log.warn("MWP: Error while parsing numbers in '" + line + "'");
+            log.warn("MWP: unparseable number in data row: " + line);
         }
     }
 
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/SQRelationParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SQRelationParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SQRelationParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -119,10 +119,18 @@
         Integer nOutlier = parseInteger(cols[11], line);
         Double cFer = parseDouble(cols[12], line);
         Double cDuan = parseDouble(cols[13], line);
-        if (km == null || a == null || b == null || cols[1].length() == 0) {
-            log.error("Incomplete SQ-relation row (missing km, a, b or parameter): "
-                + line);
-            return;
+        if (km == null || a == null || b == null || 
+	    qMax == null || cols[1].length() == 0) {
+	    if (km == null) {
+		log.error("No km for measurement station: Can not reference measurement station: "
+		    + line);
+	    }
+	    if ( a == null || b == null || 
+		qMax == null || cols[1].length() == 0) {
+		log.error("Incomplete SQ-relation row (missing a, b, Qmax or parameter): "
+		    + line);
+	    }
+	    return;
         }
         current.addValue(new ImportSQRelationValue(
             cols[1],
@@ -143,7 +151,7 @@
             result = Double.valueOf(value.replace(",", "."));
         }
         catch (NumberFormatException nfe) {
-            log.warn("parsing " + value + " in sq relation row: " + line);
+            log.warn("Unparseable " + value + " in sq relation row: " + line);
         }
         return result;
     }
@@ -154,7 +162,7 @@
             result = Integer.valueOf(value);
         }
         catch (NumberFormatException nfe) {
-            log.warn("parsing " + value + " in sq relation row: " + line);
+            log.warn("Unparseable " + value + " in sq relation row: " + line);
         }
         return result;
     }
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -85,27 +85,12 @@
         if (handleMetaDepth(line)) {
             return;
         }
-        else if (handleMetaColumns(line)) {
-            return;
-        }
         else {
             log.warn("Unknown meta line: '" + line + "'");
         }
     }
 
 
-    private boolean handleMetaColumns(String line) {
-        String[] columns = line.split(";");
-        for (int i = 0; i < columns.length; i++) {
-            if (columns[i].contains("Sedimentdichte")) {
-                this.densitsyColumn = i;
-                return true;
-            }
-        }
-        return false;
-    }
-
-
     protected boolean handleMetaDepth(String line) {
         Matcher m = META_DEPTH.matcher(line);
 
@@ -126,7 +111,7 @@
                 return true;
             }
             catch (ParseException pe) {
-                log.warn("Error while parsing numbers in: '" + line + "'");
+                log.warn("Unparseable numbers in: '" + line + "'");
             }
         }
         else {
@@ -145,41 +130,33 @@
             return;
         }
 
-        BigDecimal km;
-        BigDecimal density;
+        BigDecimal km = null;
+        BigDecimal shoreOffset = null;
+        BigDecimal density = null;
         try {
-            km      = new BigDecimal(nf.parse(vals[0]).doubleValue());
-            density = new BigDecimal(nf.parse(vals[this.densitsyColumn]).doubleValue());
-
+            km          = new BigDecimal(nf.parse(vals[0]).doubleValue());
+            density     = new BigDecimal(nf.parse(vals[2]).doubleValue());
+	    if (!vals[1].isEmpty()) {
+		shoreOffset = new BigDecimal(nf.parse(vals[1]).doubleValue());
+	    }
         }
         catch (ParseException pe) {
-            log.warn("Error while parsing numbers in '" + line + "'");
-            return;
+            log.warn("Unparseable numbers in '" + line + "'");
         }
 
+	if (km == null || density == null) {
+	    log.warn("SDP: No km nor density given. Skip line");
+	    return;
+	}
+
         BigDecimal year = null;
-        try {
-            year =
-                new BigDecimal(nf.parse(vals[vals.length - 1]).doubleValue());
-        }
-        catch(ParseException pe) {
-            try {
-                Date d = DateGuesser.guessDate(vals[vals.length - 1]);
-                Calendar c = Calendar.getInstance();
-                c.setTime(d);
-                year = new BigDecimal(c.get(Calendar.YEAR));
-            }
-            catch (IllegalArgumentException iae) {
-                log.warn("Error while parsing date in '" + line + "'");
-                return;
-            }
-        }
 
         current.addValue(new ImportSedimentDensityValue(
             km,
+	    shoreOffset,
             density,
             year,
-            vals[vals.length - 1])
+	    currentDescription)
         );
     }
 
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentYieldParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentYieldParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentYieldParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -228,7 +228,7 @@
             }
         }
         catch (ParseException pe) {
-            log.warn("SYP: Error while parsing numbers in '" + line + "':", pe);
+            log.warn("SYP: unparseable number in data row '" + line + "':", pe);
         }
     }
 
@@ -269,7 +269,7 @@
             log.warn("SYP: Unknown time interval string: '" + column + "'");
         }
         catch (ParseException pe) {
-            log.warn("SYP: Error while parsing years: " + column, pe);
+            log.warn("SYP: Could not parse years: " + column, pe);
         }
 
         return null;
@@ -296,7 +296,7 @@
                 );
             }
             catch (ParseException pe) {
-                log.warn("SYP: Error while parsing ranges of: '" + gfStr + "'");
+                log.warn("SYP: Could not parse ranges of: '" + gfStr + "'");
             }
         }
 
@@ -318,7 +318,7 @@
                 );
             }
             catch (ParseException pe) {
-                log.warn("SYP: Error while parsing ranges of: '" + gfStr + "'");
+                log.warn("SYP: Could not parse ranges of: '" + gfStr + "'");
             }
         }
 
@@ -346,7 +346,7 @@
                 }
             }
             catch (ParseException pe) {
-                log.warn("SYP: Error while parsing ranges of: '" + gfStr + "'");
+                log.warn("SYP: Could not parse ranges of: '" + gfStr + "'");    
             }
         }
 
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -185,12 +185,12 @@
                         new BigDecimal(nf.parse(value).doubleValue()));
                 }
                 catch (ParseException pe) {
-                    log.warn("Error while parsing value: '" + value + "'");
+                    log.warn("Could not parse value: '" + value + "'");
                 }
             }
         }
         catch (ParseException pe) {
-            log.warn("Error while parsing station: '" + line + "'");
+            log.warn("Could not parse station: '" + line + "'");
         }
     }
 }
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelParser.java	Tue Apr 02 08:58:24 2013 +0200
@@ -154,7 +154,7 @@
                 return true;
             }
             catch (ParseException pe) {
-                log.warn("Error while parsing Q range: '" + line + "'");
+                log.warn("Unparseable Q range: '" + line + "'");
             }
         }
 
@@ -184,7 +184,7 @@
             }
         }
         catch (ParseException pe) {
-            log.warn("Error while parsing number values: '" + line + "'");
+            log.warn("Unparseable number in data row: " + line);
         }
     }
 }
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/model/Floodplain.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/Floodplain.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Floodplain.java	Tue Apr 02 08:58:24 2013 +0200
@@ -13,6 +13,7 @@
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.annotations.Type;
+import org.hibernate.HibernateException;
 
 import com.vividsolutions.jts.geom.Polygon;
 
@@ -32,6 +33,8 @@
 
     private Polygon        geom;
 
+    private String         name;
+
 
     public Floodplain() {
     }
@@ -77,6 +80,42 @@
         this.geom = geom;
     }
 
+    @Column(name = "name")
+    public String getName() {
+        return name;
+    }
+
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public static List<Floodplain> getFloodplains(String river, String name, int kind)
+    throws HibernateException {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from Floodplain as fp where river.name =:river" +
+            " and kind.id =:kind" +
+            " and fp.name=:name");
+        query.setParameter("river", river);
+        query.setParameter("kind", kind);
+        query.setParameter("name", name);
+
+        List<Floodplain> list = query.list();
+        return list.isEmpty() ? null : list;
+    }
+
+    public static List<Floodplain> getFloodplains(String river, int kind)
+    throws HibernateException {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from Floodplain where river.name =:river AND kind.id =:kind");
+        query.setParameter("river", river);
+        query.setParameter("kind", kind);
+
+        List<Floodplain> list = query.list();
+        return list.isEmpty() ? null : list;
+    }
 
     public static Floodplain getFloodplain(String river) {
         Session session = SessionHolder.HOLDER.get();
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/model/HydrBoundary.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/HydrBoundary.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/HydrBoundary.java	Tue Apr 02 08:58:24 2013 +0200
@@ -91,6 +91,18 @@
         this.geom = geom;
     }
 
+    public static List<HydrBoundary> getHydrBoundaries(int riverId, String name, int kindId) {
+        Session session = SessionHolder.HOLDER.get();
+
+        Query query = session.createQuery(
+            "from HydrBoundary where river.id =:river_id and name=:name" + 
+            " and kind.id=:kind_id");
+        query.setParameter("river_id", riverId);
+        query.setParameter("name", name);
+        query.setParameter("kind_id", kindId);
+
+        return query.list();
+    }
 
     public static List<HydrBoundary> getHydrBoundaries(int riverId, String name) {
         Session session = SessionHolder.HOLDER.get();
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/model/HydrBoundaryPoly.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/HydrBoundaryPoly.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/HydrBoundaryPoly.java	Tue Apr 02 08:58:24 2013 +0200
@@ -104,6 +104,27 @@
         return query.list();
     }
 
+    public static List<HydrBoundaryPoly> getHydrBoundaries(int riverId,
+            int kind, int sectie, int sobek) {
+        Session session = SessionHolder.HOLDER.get();
+
+        String filter = " where river.id =:river_id";
+
+        if (kind != -1) {
+            filter += " and kind = " + kind;
+        }
+        if (sectie != -1) {
+            filter += " and sectie = " + sectie;
+        }
+        if (sobek != -1){
+            filter += " and sobek = " + sobek;
+        }
+
+        Query query = session.createQuery("from HydrBoundaryPoly" + filter);
+        query.setParameter("river_id", riverId);
+        return query.list();
+    }
+
     /**
      * Get sectie.
      *
diff -r 6dbc111e9aec -r 33d735f5433e flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java	Tue Apr 02 08:58:24 2013 +0200
@@ -23,6 +23,7 @@
     private SedimentDensity sedimentDensity;
 
     private BigDecimal station;
+    private BigDecimal shoreOffset;
     private BigDecimal density;
     private BigDecimal year;
 
@@ -36,12 +37,14 @@
     public SedimentDensityValue(
         SedimentDensity sedimentDensity,
         BigDecimal      station,
+	BigDecimal      shoreOffset,
         BigDecimal      density,
         BigDecimal      year,
         String          desc
     ) {
         this.sedimentDensity = sedimentDensity;
         this.station         = station;
+	this.shoreOffset     = shoreOffset;
         this.density         = density;
         this.year            = year;
         this.description     = desc;
@@ -83,6 +86,15 @@
         this.station = station;
     }
 
+    @Column(name = "shore_offset")
+    public BigDecimal getShoreOffset() {
+        return shoreOffset;
+    }
+
+    public void setShoreOffset(BigDecimal shoreOffset) {
+        this.shoreOffset = shoreOffset;
+    }
+
     @Column(name = "density")
     public BigDecimal getDensity() {
         return density;
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Tue Apr 02 08:58:24 2013 +0200
@@ -514,6 +514,60 @@
             });
     }
 
+    public void newSQRelation(String river, int measurementStation) {
+        Config config = Config.getInstance();
+
+        final String locale = config.getLocale();
+        final String riv = river;
+        final int mStation = measurementStation;
+        final FLYS   flys = this;
+
+        User user = getCurrentUser();
+
+        if (user == null) {
+            SC.warn(MSG.error_not_logged_in());
+            return;
+        }
+
+        collectionService.create(locale, user.identifier(),
+            new AsyncCallback<Collection>() {
+                @Override
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not create new collection.");
+                    SC.warn(getExceptionString(MSG, caught));
+                }
+
+                @Override
+                public void onSuccess(Collection collection) {
+                    GWT.log("Successfully created a new collection.");
+                    final Collection col = collection;
+                    artifactService.createSQRelationArtifact(
+                        col, locale, riv, mStation,
+                        new AsyncCallback<Artifact>() {
+                            @Override
+                            public void onFailure(Throwable caught) {
+                                GWT.log("Could not create the new artifact.");
+                                SC.warn(getExceptionString(MSG, caught));
+                            }
+
+                            @Override
+                            public void onSuccess(Artifact artifact) {
+                                GWT.log("Successfully created a new artifact.");
+                                CollectionView view = new CollectionView(flys,
+                                    col, artifact);
+                                workspace.addView(col.identifier(), view);
+
+                                view.addCollectionChangeHandler(getProjectList());
+                                view.addCloseClickHandler(
+                                    new CloseCollectionViewHandler(
+                                        FLYS.this, col.identifier()));
+                                projectList.updateUserCollections();
+                            }
+                    });
+                }
+            });
+    }
+
     @Override
     public void onCollectionChange(CollectionChangeEvent event) {
         Collection oldC = event.getOldValue();
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Apr 02 08:58:24 2013 +0200
@@ -8,6 +8,8 @@
  */
 public interface FLYSConstants extends ConstantsWithLookup {
 
+    String static_sqrelation();
+
     String add();
 
     String unexpected_exception();
@@ -1172,5 +1174,15 @@
 
     String axis();
 
+    String bfg_model();
+
+    String federal();
+
+    String areas();
+
+    String sobek_areas();
+
+    String sobek_flooded();
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Apr 02 08:58:24 2013 +0200
@@ -207,6 +207,7 @@
 askThemeRemove = Are you sure that you want to remove the selected theme / themes?
 add = Add
 
+static_sqrelation = SQ relation
 discharge_curve = Discharge Curve at Gauge
 discharge_curve_gaugeless = Discharge Curve
 gauge_discharge_curve = Discharge Table at Gauge
@@ -465,6 +466,11 @@
 route_data = Route Data
 other = Other
 axis = Axis
+bfg_model = BfG-Model
+federal = Federal States
+areas = Areas
+sobek_flooded = SOBEK-Boundary flooded / not flooded
+sobek_areas = SOBEK-Areas
 
 startcolor = Colorrange start color
 endcolor = Colorrange end color
@@ -564,7 +570,7 @@
 wsplgen_cat3 = Fill Color 2.0 <= DIFF < 3
 wsplgen_cat4 = Fill Color 3.0 <= DIFF < 4
 wsplgen_cat5 = Fill Color 4.0 <= DIFF
-attribution = &copyIntevation GmbH 2012<br>Data &copy<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
+attribution = &copyIntevation GmbH 2013<br>Data &copy<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
 
 # Manual Points Editor
 addpoints = Add points
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Apr 02 08:58:24 2013 +0200
@@ -207,6 +207,7 @@
 zoomboxTooltip = Ausschnitt vergr\u00f6\u00dfern
 chartPropertiesTooltip = Diagrammeigenschaften
 
+static_sqrelation = Transport-Abfluss Beziehung
 discharge_curve = Abflusskurve am Pegel
 discharge_curve_gaugeless = Abflusskurve
 gauge_discharge_curve = Abflusstafel am Pegel
@@ -409,7 +410,7 @@
 requireDGM = Sie m\u00fcssen ein DGM ausw\u00e4hlen.
 upload_file = hochladen
 shape_file_upload = Shapedatei hochladen
-attribution = &copyIntevation GmbH 2012<br>Data &copy<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
+attribution = &copyIntevation GmbH 2013<br>Data &copy<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
 
 # data cage
 waterlevels = Wasserst\u00e4nde
@@ -435,7 +436,7 @@
 lines = Linien
 buildings = Bauwerke
 fixpoints = Festpunkte
-uesk = \u00dcberschwemmungsfl\u00e4chen
+uesk = \u00dcberschwemmungsfl\u00e4chen - DAMI unfertig
 calculations = Berechnungen
 current = Aktuell
 potentiel = Potenziell
@@ -466,6 +467,11 @@
 route_data = Streckendaten
 other = Sonstige
 axis = Achse
+bfg_model = BfG-Modell
+federal = Bundesländer
+areas = Flächen
+sobek_flooded = SOBEK-Grenzlinie durchflutet / nicht durchflutet
+sobek_areas = SOBEK-Bereiche
 
 startcolor = Farbverlauf Startfarbe
 endcolor = Farbverlauf Endfarbe
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Apr 02 08:58:24 2013 +0200
@@ -208,6 +208,7 @@
 askThemeRemove = Are you sure that you want to remove the selected theme / themes?
 add = Add
 
+static_sqrelation = SQ relation
 discharge_curve = Discharge Curve at Gauge
 discharge_curve_gaugeless = Discharge Curve
 gauge_discharge_curve = Discharge Table at Gauge
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java	Tue Apr 02 08:58:24 2013 +0200
@@ -46,5 +46,19 @@
             String river,
             Long   gaugeref
     ) throws ServerException;
+
+    /**
+     * Create a new SQRelationArtifact
+     *
+     * @param collection the collection to add the artifact to
+     * @param river      the river
+     * @param measurementStation the measurement station id
+     */
+    public Artifact createSQRelationArtifact(
+            Collection collection,
+            String locale,
+            String river,
+            int measurementStation
+    ) throws ServerException;
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java	Tue Apr 02 08:58:24 2013 +0200
@@ -28,5 +28,13 @@
         Long   gaugeref,
         AsyncCallback<Artifact> callback
     );
+
+    public void createSQRelationArtifact(
+        Collection collection,
+        String locale,
+        String river,
+        int measurementStation,
+        AsyncCallback<Artifact> callback
+    );
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeDischargeCurvePanel.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeDischargeCurvePanel.java	Thu Mar 28 12:11:13 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-package de.intevation.flys.client.client.ui;
-
-import com.google.gwt.core.client.GWT;
-
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.Label;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.layout.HLayout;
-import com.smartgwt.client.widgets.layout.VLayout;
-
-import de.intevation.flys.client.client.FLYSConstants;
-import de.intevation.flys.client.shared.model.Data;
-import de.intevation.flys.client.shared.model.DataItem;
-import de.intevation.flys.client.shared.model.DataList;
-
-
-/**
- * This UIProvider displays the old DataItems of GaugeDischargeCurveArtifact
- *
- * @author <a href="mailto:bjoern.ricks at intevation.de">Björn Ricks</a>
- */
-public class GaugeDischargeCurvePanel
-extends      AbstractUIProvider
-{
-    private static final long serialVersionUID = 7411866539525588336L;
-
-    /** The message class that provides i18n strings.*/
-    protected FLYSConstants messages = GWT.create(FLYSConstants.class);
-
-    /** The combobox.*/
-    protected DynamicForm form;
-
-    @Override
-    public Canvas create(DataList data) {
-        VLayout layout   = new VLayout();
-        return layout;
-    }
-
-    @Override
-    public Canvas createOld(DataList dataList) {
-        VLayout vLayout = new VLayout();
-        vLayout.setWidth("400px");
-
-        int size = dataList.size();
-        for (int i = 0; i < size; i++) {
-            Data data        = dataList.get(i);
-            DataItem[] items = data.getItems();
-
-            for (DataItem item: items) {
-                HLayout hLayout = new HLayout();
-
-                hLayout.addMember(new Label(item.getLabel()));
-                hLayout.addMember(new Label(item.getStringValue()));
-
-                vLayout.addMember(hLayout);
-                vLayout.setWidth("130px");
-            }
-        }
-
-        return vLayout;
-    }
-
-    @Override
-    protected Data[] getData() {
-        return null;
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/ui/StaticDataPanel.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/StaticDataPanel.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,68 @@
+package de.intevation.flys.client.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DataList;
+
+
+/**
+ * This UIProvider displays the old DataItems of GaugeDischargeCurveArtifact
+ *
+ * @author <a href="mailto:bjoern.ricks at intevation.de">Björn Ricks</a>
+ */
+public class StaticDataPanel
+extends      AbstractUIProvider
+{
+    private static final long serialVersionUID = 7411866539525588336L;
+
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants messages = GWT.create(FLYSConstants.class);
+
+    /** The combobox.*/
+    protected DynamicForm form;
+
+    @Override
+    public Canvas create(DataList data) {
+        VLayout layout   = new VLayout();
+        return layout;
+    }
+
+    @Override
+    public Canvas createOld(DataList dataList) {
+        VLayout vLayout = new VLayout();
+        vLayout.setWidth("400px");
+
+        int size = dataList.size();
+        for (int i = 0; i < size; i++) {
+            Data data        = dataList.get(i);
+            DataItem[] items = data.getItems();
+
+            for (DataItem item: items) {
+                HLayout hLayout = new HLayout();
+
+                hLayout.addMember(new Label(item.getLabel()));
+                hLayout.addMember(new Label(item.getStringValue()));
+
+                vLayout.addMember(hLayout);
+                vLayout.setWidth("130px");
+            }
+        }
+
+        return vLayout;
+    }
+
+    @Override
+    protected Data[] getData() {
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Tue Apr 02 08:58:24 2013 +0200
@@ -162,7 +162,7 @@
             return new RadioPanel();
         }
         else if (uiProvider.equals("gauge_discharge_curve")) {
-            return new GaugeDischargeCurvePanel();
+            return new StaticDataPanel();
         }
         else if (uiProvider.equals("minfo.sedimentload_distance_select")) {
             return new SedLoadDistancePanel();
@@ -182,6 +182,9 @@
         else if (uiProvider.equals("user_rgd_panel")) {
             return new UserRGDProvider();
         }
+        else if (uiProvider.equals("static_sqrelation")) {
+            return new StaticDataPanel();
+        }
         else {
             //GWT.log("Picked default provider.");
             return new SelectProvider();
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationListGrid.java	Tue Apr 02 08:58:24 2013 +0200
@@ -7,6 +7,8 @@
 import com.smartgwt.client.widgets.WidgetCanvas;
 import com.smartgwt.client.widgets.grid.ListGridField;
 import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
+import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
 
 import de.intevation.flys.client.client.FLYS;
 import de.intevation.flys.client.shared.model.MeasurementStation;
@@ -18,7 +20,9 @@
 /**
  * @author <a href="mailto:bjoern.ricks at intevation.de">Björn Ricks</a>
  */
-public class MeasurementStationListGrid extends InfoListGrid {
+public class MeasurementStationListGrid
+extends InfoListGrid
+implements RecordClickHandler {
 
     public MeasurementStationListGrid(FLYS flys) {
         super(flys);
@@ -28,7 +32,9 @@
         ListGridField stfield = new ListGridField("station", "Station [km]");
         ListGridField lfield = new ListGridField("link", "Link");
         lfield.setType(ListGridFieldType.LINK);
-        this.setFields(nfield, sfield, efield, stfield, lfield);
+        ListGridField cfield = new ListGridField("curvelink", "SQ");
+        cfield.addRecordClickHandler(this);
+        this.setFields(nfield, sfield, efield, stfield, lfield, cfield);
     }
 
     /**
@@ -88,4 +94,12 @@
         MeasurementStationRecord station = (MeasurementStationRecord)record;
         return new WidgetCanvas(new MeasurementStationInfoPanel(station));
     }
+
+    @Override
+    public void onRecordClick(RecordClickEvent event) {
+        MeasurementStationRecord station =
+            (MeasurementStationRecord)event.getRecord();
+        flys.newSQRelation(station.getRiverName(), station.getID());
+    }
+
 }
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationRecord.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationRecord.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/stationinfo/MeasurementStationRecord.java	Tue Apr 02 08:58:24 2013 +0200
@@ -27,6 +27,7 @@
             MSG.measurement_station_url();
         this.setLink(link);
         this.setLinkText(MSG.measurement_station_info_link());
+        this.setCurveLink(MSG.static_sqrelation());
         this.setID(number);
         this.setName(station.getName());
         if (station.isKmUp()) {
@@ -172,4 +173,13 @@
     public void setLink(String link) {
         this.setAttribute("link", link);
     }
+
+    public void setCurveLink(String link) {
+        this.setAttribute("curvelink", link);
+    }
+
+    public String getCurveLink() {
+        return this.getAttribute("curvelink");
+    }
+
 }
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java	Tue Apr 02 08:58:24 2013 +0200
@@ -39,7 +39,7 @@
      * Name of the factory to generate a GaugeDischargeCurveArtifact
      */
     private static final String GAUGE_DISCHARGE_CURVE_ARTIFACT = "gaugedischargecurve";
-
+    private static final String SQ_RELATION_ARTIFACT = "staticsqrelation";
 
     private ArtifactHelper() {
     }
@@ -162,5 +162,35 @@
 
         return cf;
     }
+
+
+    public static Artifact createSQRelationArtifact(
+        String serverUrl,
+        String locale,
+        String river,
+        int measurementStation)
+    throws ServerException
+    {
+        Document create = ClientProtocolUtils.newCreateDocument(
+                SQ_RELATION_ARTIFACT);
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            create,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = create.getDocumentElement();
+
+        Element eriver = ec.create("river");
+        ec.addAttr(eriver, "name", river);
+
+        Element estation = ec.create("measurement_station");
+        ec.addAttr(estation, "number", String.valueOf(measurementStation));
+
+        root.appendChild(eriver);
+        root.appendChild(estation);
+
+        return sendCreate(serverUrl, locale, create);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java	Tue Apr 02 08:58:24 2013 +0200
@@ -78,5 +78,28 @@
         return artifact;
     }
 
+    @Override
+    public Artifact createSQRelationArtifact(
+        Collection collection,
+        String locale,
+        String river,
+        int measurementStation)
+    throws ServerException
+    {
+        logger.info("ArtifactServiceImpl.createSQRelationArtifact");
+        String url  = getServletContext().getInitParameter("server-url");
+
+        Artifact artifact = ArtifactHelper.createSQRelationArtifact(url,
+                locale, river, measurementStation);
+        if (artifact == null) {
+            return null;
+        }
+        logger.info("SQRelationArtifact created successfully");
+
+        CollectionHelper.addArtifact(collection, artifact, url, locale);
+
+        return artifact;
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java	Thu Mar 28 12:11:13 2013 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java	Tue Apr 02 08:58:24 2013 +0200
@@ -24,6 +24,7 @@
 import de.intevation.flys.client.shared.model.GaugeDischargeCurveArtifact;
 import de.intevation.flys.client.shared.model.MapArtifact;
 import de.intevation.flys.client.shared.model.MINFOArtifact;
+import de.intevation.flys.client.shared.model.StaticSQRelationArtifact;
 import de.intevation.flys.client.shared.model.WINFOArtifact;
 
 
@@ -149,6 +150,10 @@
             logger.debug("+++++ NEW GAUGEDISCHARGECURVE ARTIFACT.");
             return new GaugeDischargeCurveArtifact(uuid, hash, background, msg);
         }
+        else if (name.length() > 0 && name.equals("staticsqrelation")) {
+            logger.debug("+++++ STATICSQRELATION ARTIFACT.");
+            return new StaticSQRelationArtifact(uuid, hash, background, msg);
+        }
 
         return new DefaultArtifact(uuid, hash, background, msg);
     }
diff -r 6dbc111e9aec -r 33d735f5433e flys-client/src/main/java/de/intevation/flys/client/shared/model/StaticSQRelationArtifact.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/StaticSQRelationArtifact.java	Tue Apr 02 08:58:24 2013 +0200
@@ -0,0 +1,36 @@
+package de.intevation.flys.client.shared.model;
+
+import java.util.List;
+
+
+public class StaticSQRelationArtifact
+extends DefaultArtifact
+{
+
+    /** The name of this artifact */
+    public static final String NAME = "static_sqrelation";
+
+
+
+    public StaticSQRelationArtifact() {
+    }
+
+    public StaticSQRelationArtifact(String uuid, String hash) {
+        super(uuid, hash);
+    }
+
+
+    public StaticSQRelationArtifact(
+        String                   uuid,
+        String                   hash,
+        boolean                  inBackground,
+        List<CalculationMessage> messages
+    ) {
+        super(uuid, hash, inBackground, messages);
+    }
+
+
+    public String getName() {
+        return NAME;
+    }
+}


More information about the Dive4elements-commits mailing list