comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java @ 655:6eccb68a8b99

Added WMS-Publishing to Product Layer gnv-artifacts/trunk@747 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 08 Mar 2010 14:04:28 +0000
parents 4fc97074eb90
children 22dc921cd8b1
comparison
equal deleted inserted replaced
654:a6081d76fa1c 655:6eccb68a8b99
176 multiPolygons, 176 multiPolygons,
177 "polygons"); 177 "polygons");
178 } 178 }
179 179
180 180
181 public static boolean writeDataToFile(File shapeFile, 181 public static String writeDataToFile(File shapeFile,
182 String name, 182 String name,
183 Collection<Result> data){ 183 Collection<Result> data){
184 String geomType = null;
185
184 WKTReader wktReader = new WKTReader(); 186 WKTReader wktReader = new WKTReader();
185 187
186 Map<String, Serializable> params = new HashMap<String, Serializable>(); 188 Map<String, Serializable> params = new HashMap<String, Serializable>();
187 189
188 try { 190 try {
189 params.put("url", shapeFile.toURI().toURL()); 191 params.put("url", shapeFile.toURI().toURL());
190 } 192 }
191 catch (MalformedURLException mue) { 193 catch (MalformedURLException mue) {
192 log.error(mue.getLocalizedMessage(), mue); 194 log.error(mue.getLocalizedMessage(), mue);
193 return false; 195 return null;
194 } 196 }
195 197
196 params.put("create spatial index", Boolean.TRUE); 198 params.put("create spatial index", Boolean.TRUE);
197 199
198 200
208 for (Result result: data) { 210 for (Result result: data) {
209 try { 211 try {
210 Geometry g = wktReader.read(result.getString(0)); 212 Geometry g = wktReader.read(result.getString(0));
211 if (type == null){ 213 if (type == null){
212 try { 214 try {
215 geomType = g.getGeometryType().toUpperCase();
213 type = DataUtilities.createType( 216 type = DataUtilities.createType(
214 name, 217 name,
215 "geom:"+g.getGeometryType()+":srid=4326"); 218 "geom:"+g.getGeometryType()+":srid=4326");
216 // TODO add other AttributeTypes 219 // TODO add other AttributeTypes
217 } 220 }
218 catch (SchemaException se) { 221 catch (SchemaException se) {
219 log.error(se.getLocalizedMessage(), se); 222 log.error(se.getLocalizedMessage(), se);
220 return false; 223 return null;
221 } 224 }
222 featureBuilder = new SimpleFeatureBuilder(type); 225 featureBuilder = new SimpleFeatureBuilder(type);
223 } 226 }
224 featureBuilder.add(g); 227 featureBuilder.add(g);
225 SimpleFeature feature = featureBuilder.buildFeature(null); 228 SimpleFeature feature = featureBuilder.buildFeature(null);
269 try { transaction.close(); } 272 try { transaction.close(); }
270 catch (IOException ioe) {} 273 catch (IOException ioe) {}
271 } 274 }
272 } 275 }
273 276
274 return success; 277 return geomType;
275 278
276 } 279 }
277 280
278 public static boolean writeMultiPolygonsToFile( 281 public static boolean writeMultiPolygonsToFile(
279 File shapeFile, 282 File shapeFile,

http://dive4elements.wald.intevation.org