diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1107:005c2964f9af

Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles. flys-artifacts/trunk@2610 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Aug 2011 14:13:06 +0000
parents e9f66d63bdd0
children 5b1198c27d43
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Aug 30 11:09:54 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Aug 30 14:13:06 2011 +0000
@@ -7,6 +7,7 @@
 
 import javax.xml.xpath.XPathConstants;
 
+import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.LineString;
 import com.vividsolutions.jts.geom.Polygon;
 
@@ -14,10 +15,13 @@
 
 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 de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
@@ -43,6 +47,10 @@
     private static Logger logger = Logger.getLogger(FloodMapState.class);
 
 
+    public static final String KEEP_ARTIFACT_DIR =
+        System.getProperty("flys.uesk.keep.artifactsdir", "false");
+
+
     public static final String XPATH_SHAPEFILE_DIR =
         "/artifact-database/floodmap/shapefile-path/@value";
 
@@ -74,7 +82,9 @@
         WSPLGENJob job = prepareWSPLGENJob(artifact, artifactDir);
 
         if (job == null) {
-            removeDirectory(artifact);
+            if (KEEP_ARTIFACT_DIR.equals("false")) {
+                removeDirectory(artifact);
+            }
 
             logger.error("No WSPLGEN processing has been started!");
 
@@ -260,8 +270,11 @@
         String srid    = FLYSUtils.getRiverSrid(artifact);
         String srs     = "EPSG:" + srid;
 
-        SimpleFeatureType   ft = GeometryUtils.buildBarriersFeatureType(srs);
-        List<SimpleFeature> features = GeometryUtils.parseGeoJSON(geoJSON, ft);
+        List<SimpleFeature> features = getBarriersFeatures(geoJSON, srs);
+        if (features == null || features.size() == 0) {
+            logger.debug("No barrier features extracted.");
+            return;
+        }
 
         FeatureCollection[] fcs = splitLinesAndPolygons(features);
 
@@ -271,13 +284,15 @@
         try {
             GeometryUtils.writeShapefile(
                 shapeLines,
-                GeometryUtils.buildFeatureType("lines", srid, "LineString"),
+                GeometryUtils.buildFeatureType(
+                    "lines", srs, LineString.class, CRS.decode(srs)),
                 fcs[0]);
             job.addLin(shapeLines.getAbsolutePath());
 
             GeometryUtils.writeShapefile(
                 shapePolys,
-                GeometryUtils.buildFeatureType("polygons", srid, "Polygon"),
+                GeometryUtils.buildFeatureType(
+                    "polygons", srs, Polygon.class, CRS.decode(srs)),
                 fcs[1]);
             job.addLin(shapePolys.getAbsolutePath());
         }
@@ -290,6 +305,36 @@
         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));
+
+            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;
     }
 
 

http://dive4elements.wald.intevation.org