diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java @ 799:feeaf5aec552

ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries gnv-artifacts/trunk@881 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 06 Apr 2010 11:56:53 +0000
parents c4156275c1e1
children 2cea76f1112e
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java	Tue Apr 06 11:05:00 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java	Tue Apr 06 11:56:53 2010 +0000
@@ -1,23 +1,10 @@
 package de.intevation.gnv.utils;
 
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.MultiLineString;
-import com.vividsolutions.jts.geom.MultiPolygon;
-
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKTReader;
-
-import de.intevation.gnv.geobackend.base.Result;
-import de.intevation.gnv.geobackend.base.ResultDescriptor;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
-
 import java.net.MalformedURLException;
-
 import java.text.NumberFormat;
-
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
@@ -25,27 +12,30 @@
 import java.util.Map;
 
 import org.apache.log4j.Logger;
-
 import org.geotools.data.DataStoreFactorySpi;
 import org.geotools.data.DataUtilities;
 import org.geotools.data.DefaultTransaction;
 import org.geotools.data.FeatureStore;
 import org.geotools.data.Transaction;
-
 import org.geotools.data.shapefile.ShapefileDataStore;
 import org.geotools.data.shapefile.ShapefileDataStoreFactory;
-
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.FeatureCollections;
 import org.geotools.feature.SchemaException;
-
 import org.geotools.feature.simple.SimpleFeatureBuilder;
-
 import org.geotools.referencing.crs.DefaultGeographicCRS;
-
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.MultiLineString;
+import com.vividsolutions.jts.geom.MultiPolygon;
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.geobackend.base.ResultDescriptor;
+
 /**
  * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
  */
@@ -200,10 +190,10 @@
     }
 
 
-    public static String writeDataToFile(File shapeFile,
+    public static boolean writeDataToFile(File shapeFile,
                                           String name,
-                                          Collection<Result> data){
-        String geomType = null;
+                                          Collection<Result> data,
+                                          String geometryType){
 
         WKTReader wktReader = new WKTReader();
 
@@ -214,7 +204,7 @@
         }
         catch (MalformedURLException mue) {
             log.error(mue.getLocalizedMessage(), mue);
-            return null;
+            return false;
         }
 
         params.put("create spatial index", Boolean.TRUE);
@@ -237,8 +227,7 @@
                 int columns = rd.getColumnCount();
                 if (type == null){
                     try {
-                        geomType = g.getGeometryType().toUpperCase();
-                        String schema = "geom:"+g.getGeometryType()+":srid=4326";
+                        String schema = "geom:"+geometryType+":srid=4326";
                         for (int i = 1; i < columns; i++){
                             schema+=","+rd.getColumnName(i)+
                                     ":"+rd.getColumnClassName(i);
@@ -247,7 +236,7 @@
                     }
                     catch (SchemaException se) {
                         log.error(se.getLocalizedMessage(), se);
-                        return null;
+                        return false;
                     }
                     featureBuilder = new SimpleFeatureBuilder(type);
                 }
@@ -304,7 +293,7 @@
             }
         }
 
-        return geomType;
+        return true;
 
     }
 

http://dive4elements.wald.intevation.org