changeset 1108:5b1198c27d43

Export riveraxis and crosssections to shapefiles for WSPLGEN. flys-artifacts/trunk@2612 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Aug 2011 15:17:43 +0000
parents 005c2964f9af
children ba9fa72dd6f5
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java
diffstat 3 files changed, 124 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Aug 30 14:13:06 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Aug 30 15:17:43 2011 +0000
@@ -1,3 +1,12 @@
+2011-08-30  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/GeometryUtils.java: Improved
+	  exception handling: exceptions are catched in GeometryUtils now.
+
+	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
+	  Write river axis and crosssections to shapefiles and save shapefile
+	  pathes in WSPLGENJob.
+
 2011-08-30  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Aug 30 14:13:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Aug 30 15:17:43 2011 +0000
@@ -15,13 +15,10 @@
 
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.referencing.FactoryException;
-import org.opengis.referencing.NoSuchAuthorityCodeException;
 
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.FeatureCollections;
-import org.geotools.feature.SchemaException;
-import org.geotools.referencing.CRS;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
 
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
@@ -31,6 +28,9 @@
 
 import de.intevation.artifactdatabase.state.Facet;
 
+import de.intevation.flys.model.CrossSectionTrack;
+import de.intevation.flys.model.RiverAxis;
+
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WSPLGENFacet;
@@ -57,6 +57,8 @@
     public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par";
     public static final String WSPLGEN_BARRIERS_LINES = "barrier_lines.shp";
     public static final String WSPLGEN_BARRIERS_POLY  = "barrier_polygons.shp";
+    public static final String WSPLGEN_AXIS           = "axis.shp";
+    public static final String WSPLGEN_QPS            = "qps.shp";
 
     public static final int WSPLGEN_DEFAULT_OUTPUT = 0;
 
@@ -173,13 +175,13 @@
         setGel(artifact, job);
         setDist(artifact, job);
         setLine(artifact, artifactDir, job);
+        setAxis(artifact, artifactDir, job);
+        setPro(artifact, artifactDir, job);
 
         // TODO
         // setDgm(artifact, job);    // SHP
-        // setPro(artifact, job);    // SHP
         // setWsp(artifact, job);    // WSP
         // setWspTag(artifact, job);
-        // setAxis(artifact, job);   // SHP
         // setArea(artifact, job);   // SHP
         // setOutFile(artifact, job);
 
@@ -284,15 +286,13 @@
         try {
             GeometryUtils.writeShapefile(
                 shapeLines,
-                GeometryUtils.buildFeatureType(
-                    "lines", srs, LineString.class, CRS.decode(srs)),
+                GeometryUtils.buildFeatureType("lines", srs, LineString.class),
                 fcs[0]);
             job.addLin(shapeLines.getAbsolutePath());
 
             GeometryUtils.writeShapefile(
                 shapePolys,
-                GeometryUtils.buildFeatureType(
-                    "polygons", srs, Polygon.class, CRS.decode(srs)),
+                GeometryUtils.buildFeatureType("polygons", srs, Polygon.class),
                 fcs[1]);
             job.addLin(shapePolys.getAbsolutePath());
         }
@@ -302,39 +302,14 @@
         catch (IOException ioe) {
             logger.error("Error while writing shapefile: " + ioe.getMessage());
         }
-        catch (SchemaException se) {
-            logger.error("Error while writing shapefile: " + se.getMessage());
-        }
-        catch (NoSuchAuthorityCodeException nsae) {
-            logger.error("Error while writing shapefile: " + nsae.getMessage());
-        }
-        catch (FactoryException fe) {
-            logger.error("Error while writing shapefile: " + fe.getMessage());
-        }
     }
 
 
     protected List<SimpleFeature> getBarriersFeatures(String json, String srs) {
-        SimpleFeatureType   ft       = null;
-        List<SimpleFeature> features = null;
-
-        try {
-            ft = GeometryUtils.buildFeatureType(
-                "barriers", srs, Geometry.class, CRS.decode(srs));
+        SimpleFeatureType ft = GeometryUtils.buildFeatureType(
+            "barriers", srs,Geometry.class);
 
-            features = GeometryUtils.parseGeoJSON(json, ft);
-        }
-        catch (SchemaException se) {
-            logger.warn("Error while reading GeoJSON: " + se.getMessage());
-        }
-        catch (NoSuchAuthorityCodeException nsae) {
-            logger.warn("Error while reading GeoJSON: " + nsae.getMessage());
-        }
-        catch (FactoryException fe) {
-            logger.warn("Error while reading GeoJSON: " + fe.getMessage());
-        }
-
-        return features;
+        return GeometryUtils.parseGeoJSON(json, ft);
     }
 
 
@@ -361,5 +336,87 @@
 
         return new FeatureCollection[] { lines, polygons };
     }
+
+
+    protected void setAxis(FLYSArtifact artifact, File dir, WSPLGENJob job) {
+        String river = artifact.getDataAsString("river");
+        String srid    = FLYSUtils.getRiverSrid(artifact);
+        String srs     = "EPSG:" + srid;
+
+        RiverAxis axis = RiverAxis.getRiverAxis(river);
+        if (axis == null) {
+            logger.warn("Could not find river axis for: '" + river + "'");
+            return;
+        }
+
+        Geometry geom = axis.getGeom();
+
+        SimpleFeatureType ft = GeometryUtils.buildFeatureType(
+            "axis", srs, LineString.class);
+
+        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft);
+        builder.add(geom);
+
+        FeatureCollection collection = FeatureCollections.newCollection();
+        collection.add(builder.buildFeature("0"));
+
+        File axisShape = new File(dir, WSPLGEN_AXIS);
+
+        try {
+            GeometryUtils.writeShapefile(
+                axisShape,
+                GeometryUtils.buildFeatureType("axis", srs, LineString.class),
+                collection);
+            job.setAxis(axisShape.getAbsolutePath());
+        }
+        catch (MalformedURLException mue) {
+            logger.error("Error while writing shapefile: " + mue.getMessage());
+        }
+        catch (IOException ioe) {
+            logger.error("Error while writing shapefile: " + ioe.getMessage());
+        }
+    }
+
+
+    protected void setPro(FLYSArtifact artifact, File dir, WSPLGENJob job) {
+        String river = artifact.getDataAsString("river");
+        String srid    = FLYSUtils.getRiverSrid(artifact);
+        String srs     = "EPSG:" + srid;
+
+        List<CrossSectionTrack> cst =
+            CrossSectionTrack.getCrossSectionTrack(river);
+
+        logger.debug("Found " + cst.size() + " CrossSectionTracks.");
+
+        SimpleFeatureType ft = GeometryUtils.buildFeatureType(
+            "qps", srs, LineString.class);
+
+        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft);
+        FeatureCollection collection = FeatureCollections.newCollection();
+
+        int i = 0;
+        for (CrossSectionTrack track: cst) {
+            builder.reset();
+            builder.add(track.getGeom());
+
+            collection.add(builder.buildFeature(String.valueOf(i++)));
+        }
+
+        File qpsShape = new File(dir, WSPLGEN_QPS);
+
+        try {
+            GeometryUtils.writeShapefile(
+                qpsShape,
+                GeometryUtils.buildFeatureType("qps", srs, LineString.class),
+                collection);
+            job.setPro(qpsShape.getAbsolutePath());
+        }
+        catch (MalformedURLException mue) {
+            logger.error("Error while writing shapefile: " + mue.getMessage());
+        }
+        catch (IOException ioe) {
+            logger.error("Error while writing shapefile: " + ioe.getMessage());
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Tue Aug 30 14:13:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java	Tue Aug 30 15:17:43 2011 +0000
@@ -14,6 +14,8 @@
 
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.NoSuchAuthorityCodeException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
 import org.geotools.data.DataStoreFactorySpi;
@@ -24,9 +26,9 @@
 import org.geotools.data.shapefile.ShapefileDataStoreFactory;
 import org.geotools.feature.FeatureIterator;
 import org.geotools.feature.FeatureCollection;
-import org.geotools.feature.SchemaException;
 import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
 import org.geotools.geojson.feature.FeatureJSON;
+import org.geotools.referencing.CRS;
 
 
 public class GeometryUtils {
@@ -55,22 +57,27 @@
 
 
     public static SimpleFeatureType buildFeatureType(
-        String                    name,
-        String                    srs,
-        Class                     geometryType,
-        CoordinateReferenceSystem crs)
-    throws SchemaException
+        String name, String srs, Class geometryType)
     {
-        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+        try {
+            SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+            CoordinateReferenceSystem crs    = CRS.decode(srs);
 
-        builder.setName("flys");
-        builder.setNamespaceURI("http://www.intevation.de/");
-        builder.setCRS(crs);
-        builder.setSRS(srs);
+            builder.setName("flys");
+            builder.setNamespaceURI("http://www.intevation.de/");
+            builder.setCRS(crs);
+            builder.setSRS(srs);
 
-        builder.add("geometry", geometryType, crs);
+            builder.add("geometry", geometryType, crs);
 
-        return builder.buildFeatureType();
+            return builder.buildFeatureType();
+        }
+        catch (NoSuchAuthorityCodeException nsae) {
+        }
+        catch (FactoryException fe) {
+        }
+
+        return null;
     }
 
 

http://dive4elements.wald.intevation.org