comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java @ 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 6eccb68a8b99
children f82e57a60124
comparison
equal deleted inserted replaced
726:8d475151b2c1 727:22dc921cd8b1
31 import com.vividsolutions.jts.geom.MultiPolygon; 31 import com.vividsolutions.jts.geom.MultiPolygon;
32 import com.vividsolutions.jts.io.ParseException; 32 import com.vividsolutions.jts.io.ParseException;
33 import com.vividsolutions.jts.io.WKTReader; 33 import com.vividsolutions.jts.io.WKTReader;
34 34
35 import de.intevation.gnv.geobackend.base.Result; 35 import de.intevation.gnv.geobackend.base.Result;
36 import de.intevation.gnv.geobackend.base.ResultDescriptor;
36 37
37 /** 38 /**
38 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) 39 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
39 */ 40 */
40 public final class ShapeFileWriter 41 public final class ShapeFileWriter
204 205
205 SimpleFeatureType type = null; 206 SimpleFeatureType type = null;
206 SimpleFeatureBuilder featureBuilder = null; 207 SimpleFeatureBuilder featureBuilder = null;
207 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = 208 FeatureCollection<SimpleFeatureType, SimpleFeature> collection =
208 FeatureCollections.newCollection(); 209 FeatureCollections.newCollection();
209 210 int j = 0;
210 for (Result result: data) { 211 for (Result result: data) {
212 j++;
211 try { 213 try {
212 Geometry g = wktReader.read(result.getString(0)); 214 Geometry g = wktReader.read(result.getString(0));
215 ResultDescriptor rd = result.getResultDescriptor();
216 int columns = rd.getColumnCount();
213 if (type == null){ 217 if (type == null){
214 try { 218 try {
215 geomType = g.getGeometryType().toUpperCase(); 219 geomType = g.getGeometryType().toUpperCase();
216 type = DataUtilities.createType( 220 String schema = "geom:"+g.getGeometryType()+":srid=4326";
217 name, 221 for (int i = 1; i < columns; i++){
218 "geom:"+g.getGeometryType()+":srid=4326"); 222 schema+=","+rd.getColumnName(i)+
219 // TODO add other AttributeTypes 223 ":"+rd.getColumnClassName(i);
224 }
225 type = DataUtilities.createType(name, schema);
220 } 226 }
221 catch (SchemaException se) { 227 catch (SchemaException se) {
222 log.error(se.getLocalizedMessage(), se); 228 log.error(se.getLocalizedMessage(), se);
223 return null; 229 return null;
224 } 230 }
225 featureBuilder = new SimpleFeatureBuilder(type); 231 featureBuilder = new SimpleFeatureBuilder(type);
226 } 232 }
227 featureBuilder.add(g); 233 featureBuilder.add(g);
234 for (int i = 1; i < columns; i++){
235 featureBuilder.add(result.getObject(i));
236 }
228 SimpleFeature feature = featureBuilder.buildFeature(null); 237 SimpleFeature feature = featureBuilder.buildFeature(null);
229 collection.add(feature); 238 collection.add(feature);
230 } catch (ParseException e) { 239 } catch (ParseException e) {
231 log.error(e,e); 240 log.error("cannot create geometry "+j+" for "+result.getString(0));
232 } catch (java.lang.IllegalArgumentException e){ 241 } catch (java.lang.IllegalArgumentException e){
233 log.error("cannot create geometry for "+result.getString(0)); 242 log.error("cannot create geometry for "+result.getString(0));
234 } 243 }
235 } 244 }
236 245

http://dive4elements.wald.intevation.org