changeset 727:22dc921cd8b1

Added generic Export for all Columns which are in an ResultValue. gnv-artifacts/trunk@763 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 12 Mar 2010 11:28:36 +0000
parents 8d475151b2c1
children f6630d0203da
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Mar 10 15:04:30 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Fri Mar 12 11:28:36 2010 +0000
@@ -1,3 +1,10 @@
+2010-03-12  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java (writeDataToFile): 
+	  Added generic Export for all Columns which are in an ResultValue.
+	  The first Column must be the Geometryvalue. all other Columns will be added
+	  to the Shapefile using the defined Attribute-Class.
+
 2010-03-10  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	  Issue201
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java	Wed Mar 10 15:04:30 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java	Fri Mar 12 11:28:36 2010 +0000
@@ -33,6 +33,7 @@
 import com.vividsolutions.jts.io.WKTReader;
 
 import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.geobackend.base.ResultDescriptor;
 
 /**
  * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
@@ -206,17 +207,22 @@
         SimpleFeatureBuilder featureBuilder = null;
         FeatureCollection<SimpleFeatureType, SimpleFeature> collection = 
             FeatureCollections.newCollection();
-        
+        int j = 0;
         for (Result result: data) {
+            j++;
             try {
                 Geometry g = wktReader.read(result.getString(0));
+                ResultDescriptor rd = result.getResultDescriptor();
+                int columns = rd.getColumnCount();
                 if (type == null){
                     try { 
                         geomType = g.getGeometryType().toUpperCase();
-                        type = DataUtilities.createType(
-                            name,
-                            "geom:"+g.getGeometryType()+":srid=4326");
-                        // TODO add other AttributeTypes
+                        String schema = "geom:"+g.getGeometryType()+":srid=4326";
+                        for (int i = 1; i < columns; i++){
+                            schema+=","+rd.getColumnName(i)+
+                                    ":"+rd.getColumnClassName(i);
+                        }
+                        type = DataUtilities.createType(name, schema);
                     }
                     catch (SchemaException se) {
                         log.error(se.getLocalizedMessage(), se);
@@ -225,10 +231,13 @@
                     featureBuilder = new SimpleFeatureBuilder(type);
                 }
                 featureBuilder.add(g);
+                for (int i = 1; i < columns; i++){
+                    featureBuilder.add(result.getObject(i));
+                }
                 SimpleFeature feature = featureBuilder.buildFeature(null);
                 collection.add(feature);
             } catch (ParseException e) {
-                log.error(e,e);
+                log.error("cannot create geometry "+j+" for "+result.getString(0));
             } catch (java.lang.IllegalArgumentException e){
                 log.error("cannot create geometry for "+result.getString(0));
             }

http://dive4elements.wald.intevation.org