changeset 1123:be9bb260b835

Set the Z values of line and polygon barrier geometries used for WSPLGEN. flys-artifacts/trunk@2632 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 01 Sep 2011 12:23:23 +0000
parents 111794adf285
children 28a595b32980
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java
diffstat 2 files changed, 92 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Sep 01 12:15:46 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Sep 01 12:23:23 2011 +0000
@@ -1,3 +1,9 @@
+2011-09-01  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
+	  Set the Z values of line and polygon barrier geometries. Both barrier
+	  shapefiles will contain 3D geometries now.
+
 2011-08-31  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Get real data to display in CrossSection (although ignorant of
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Thu Sep 01 12:15:46 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Thu Sep 01 12:23:23 2011 +0000
@@ -4,10 +4,12 @@
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.xml.xpath.XPathConstants;
 
+import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.LineString;
 import com.vividsolutions.jts.geom.MultiPolygon;
@@ -288,7 +290,10 @@
         String srid    = FLYSUtils.getRiverSrid(artifact);
         String srs     = "EPSG:" + srid;
 
-        List<SimpleFeature> features = getBarriersFeatures(geoJSON, srs);
+        SimpleFeatureType ft = getBarriersFeatureType(
+            "barriers", srs, Geometry.class);
+
+        List<SimpleFeature> features = GeometryUtils.parseGeoJSON(geoJSON, ft);
         if (features == null || features.size() == 0) {
             logger.debug("No barrier features extracted.");
             return;
@@ -305,6 +310,9 @@
             fcs[0]);
 
         if (l) {
+            logger.debug(
+                "Successfully created barrier line shapefile. " +
+                "Write shapefile path into WSPLGEN job.");
             job.addLin(shapeLines.getAbsolutePath());
         }
 
@@ -314,16 +322,24 @@
             fcs[1]);
 
         if (p) {
+            logger.debug(
+                "Successfully created barrier polygon shapefile. " +
+                "Write shapefile path into WSPLGEN job.");
             job.addLin(shapePolys.getAbsolutePath());
         }
     }
 
 
-    protected List<SimpleFeature> getBarriersFeatures(String json, String srs) {
-        SimpleFeatureType ft = GeometryUtils.buildFeatureType(
-            "barriers", srs,Geometry.class);
+    protected SimpleFeatureType getBarriersFeatureType(
+        String name,
+        String srs,
+        Class  type
+    ) {
+        Object[][] attrs = new Object[2][];
+        attrs[0] = new Object[] { "typ", String.class };
+        attrs[1] = new Object[] { "elevation", Double.class };
 
-        return GeometryUtils.parseGeoJSON(json, ft);
+        return GeometryUtils.buildFeatureType(name, srs, type, attrs);
     }
 
 
@@ -334,10 +350,13 @@
         for (SimpleFeature feature: f) {
             Geometry geom = (Geometry) feature.getDefaultGeometry();
 
+
             if (geom instanceof LineString) {
+                geom = applyElevationAttribute(feature, (LineString) geom);
                 lines.add(feature);
             }
             else if (geom instanceof Polygon) {
+                geom = applyElevationAttribute(feature, (Polygon) geom);
                 polygons.add(feature);
             }
             else {
@@ -352,6 +371,68 @@
     }
 
 
+    protected static Geometry applyElevationAttribute(
+        SimpleFeature feature,
+        Geometry      geom
+    ) {
+        logger.debug("Apply elevations for: " + geom.getClass());
+
+        List<Double> elevations = extractElevations(feature);
+        int           numPoints = geom.getNumPoints();
+        int        numElevation = elevations.size();
+
+        String typ = (String) feature.getAttribute("typ");
+
+        if (numPoints > numElevation) {
+            logger.warn("More vertices in Geometry than elevations given.");
+        }
+
+        Coordinate[] c = geom.getCoordinates();
+        for (int i = 0; i < numPoints; i++) {
+            if (i < numElevation) {
+                c[i].z = elevations.get(i);
+            }
+            else if (typ != null && typ.equals("Graben")) {
+                c[i].z = -9999d;
+            }
+            else {
+                c[i].z = 9999d;
+            }
+        }
+
+        return geom;
+    }
+
+
+    protected static List<Double> extractElevations(SimpleFeature feature) {
+        String tmp = (String) feature.getAttribute("elevation");
+        String typ = (String) feature.getAttribute("typ");
+
+        String[] elevations = tmp == null ? null : tmp.split(" ");
+
+        int num = elevations != null ? elevations.length : 0;
+
+        List<Double> list = new ArrayList<Double>(num);
+
+        for (int i = 0; i < num; i++) {
+            try {
+                list.add(Double.parseDouble(elevations[i]));
+            }
+            catch (NumberFormatException nfe) {
+                logger.warn("Error while parsing elevation at pos: " + i);
+                if (typ != null && typ.equals("Graben")) {
+                    list.add(new Double(-9999.0));
+                }
+                else {
+                    list.add(new Double(9999.0));
+                }
+            }
+        }
+
+        return list;
+    }
+
+
     protected void setAxis(FLYSArtifact artifact, File dir, WSPLGENJob job) {
         String river = artifact.getDataAsString("river");
         String srid    = FLYSUtils.getRiverSrid(artifact);

http://dive4elements.wald.intevation.org