Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java @ 778:9a828e5a2390
Removed trailing whitespace
gnv-artifacts/trunk@851 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 29 Mar 2010 07:58:51 +0000 |
parents | 0b1de7e38907 |
children | b1f5f2a8840f |
comparison
equal
deleted
inserted
replaced
777:8009961db1cb | 778:9a828e5a2390 |
---|---|
65 return writeMultiLineStringsToFile( | 65 return writeMultiLineStringsToFile( |
66 shapeFile, | 66 shapeFile, |
67 parameterId, | 67 parameterId, |
68 layer, | 68 layer, |
69 date, | 69 date, |
70 multiLineStrings, | 70 multiLineStrings, |
71 "isolines"); | 71 "isolines"); |
72 } | 72 } |
73 | 73 |
74 public static boolean writeMultiLineStringsToFile( | 74 public static boolean writeMultiLineStringsToFile( |
75 File shapeFile, | 75 File shapeFile, |
95 if (name == null) { | 95 if (name == null) { |
96 name = shapeFile.getName(); | 96 name = shapeFile.getName(); |
97 } | 97 } |
98 | 98 |
99 SimpleFeatureType TYPE; | 99 SimpleFeatureType TYPE; |
100 | 100 |
101 try { | 101 try { |
102 TYPE = DataUtilities.createType( | 102 TYPE = DataUtilities.createType( |
103 name, | 103 name, |
104 "geom:MultiLineString:srid=4326," + | 104 "geom:MultiLineString:srid=4326," + |
105 "PARAMETER:Integer," + | 105 "PARAMETER:Integer," + |
106 "LAYER:Integer," + | 106 "LAYER:Integer," + |
107 "DATE:Date," + | 107 "DATE:Date," + |
108 "VALUE:Double," + | 108 "VALUE:Double," + |
109 "DESC:String"); | 109 "DESC:String"); |
110 } | 110 } |
114 } | 114 } |
115 | 115 |
116 SimpleFeatureBuilder featureBuilder = | 116 SimpleFeatureBuilder featureBuilder = |
117 new SimpleFeatureBuilder(TYPE); | 117 new SimpleFeatureBuilder(TYPE); |
118 | 118 |
119 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = | 119 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = |
120 FeatureCollections.newCollection(); | 120 FeatureCollections.newCollection(); |
121 | 121 |
122 for (Pair<Object, MultiLineString> pair: multiLineStrings) { | 122 for (Pair<Object, MultiLineString> pair: multiLineStrings) { |
123 featureBuilder.add(pair.getB()); | 123 featureBuilder.add(pair.getB()); |
124 featureBuilder.add(parameterId); | 124 featureBuilder.add(parameterId); |
153 featureStore.setTransaction(transaction); | 153 featureStore.setTransaction(transaction); |
154 | 154 |
155 featureStore.addFeatures(collection); | 155 featureStore.addFeatures(collection); |
156 transaction.commit(); | 156 transaction.commit(); |
157 success = true; | 157 success = true; |
158 } | 158 } |
159 catch (IOException ioe) { | 159 catch (IOException ioe) { |
160 log.error(ioe.getLocalizedMessage(), ioe); | 160 log.error(ioe.getLocalizedMessage(), ioe); |
161 } | 161 } |
162 finally { | 162 finally { |
163 if (transaction != null) { | 163 if (transaction != null) { |
179 Integer layer, | 179 Integer layer, |
180 Date date, | 180 Date date, |
181 Map<Integer, MultiPolygon> multiPolygons | 181 Map<Integer, MultiPolygon> multiPolygons |
182 ) { | 182 ) { |
183 return writeMultiPolygonsToFile( | 183 return writeMultiPolygonsToFile( |
184 shapeFile, | 184 shapeFile, |
185 parameterId, | 185 parameterId, |
186 layer, | 186 layer, |
187 date, | 187 date, |
188 multiPolygons, | 188 multiPolygons, |
189 "polygons"); | 189 "polygons"); |
190 } | 190 } |
191 | 191 |
192 | 192 |
193 public static String writeDataToFile(File shapeFile, | 193 public static String writeDataToFile(File shapeFile, |
194 String name, | 194 String name, |
195 Collection<Result> data){ | 195 Collection<Result> data){ |
196 String geomType = null; | 196 String geomType = null; |
197 | 197 |
198 WKTReader wktReader = new WKTReader(); | 198 WKTReader wktReader = new WKTReader(); |
199 | 199 |
200 Map<String, Serializable> params = new HashMap<String, Serializable>(); | 200 Map<String, Serializable> params = new HashMap<String, Serializable>(); |
201 | 201 |
202 try { | 202 try { |
203 params.put("url", shapeFile.toURI().toURL()); | 203 params.put("url", shapeFile.toURI().toURL()); |
204 } | 204 } |
214 name = shapeFile.getName(); | 214 name = shapeFile.getName(); |
215 } | 215 } |
216 | 216 |
217 SimpleFeatureType type = null; | 217 SimpleFeatureType type = null; |
218 SimpleFeatureBuilder featureBuilder = null; | 218 SimpleFeatureBuilder featureBuilder = null; |
219 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = | 219 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = |
220 FeatureCollections.newCollection(); | 220 FeatureCollections.newCollection(); |
221 int j = 0; | 221 int j = 0; |
222 for (Result result: data) { | 222 for (Result result: data) { |
223 j++; | 223 j++; |
224 try { | 224 try { |
225 Geometry g = wktReader.read(result.getString(0)); | 225 Geometry g = wktReader.read(result.getString(0)); |
226 ResultDescriptor rd = result.getResultDescriptor(); | 226 ResultDescriptor rd = result.getResultDescriptor(); |
227 int columns = rd.getColumnCount(); | 227 int columns = rd.getColumnCount(); |
228 if (type == null){ | 228 if (type == null){ |
229 try { | 229 try { |
230 geomType = g.getGeometryType().toUpperCase(); | 230 geomType = g.getGeometryType().toUpperCase(); |
231 String schema = "geom:"+g.getGeometryType()+":srid=4326"; | 231 String schema = "geom:"+g.getGeometryType()+":srid=4326"; |
232 for (int i = 1; i < columns; i++){ | 232 for (int i = 1; i < columns; i++){ |
233 schema+=","+rd.getColumnName(i)+ | 233 schema+=","+rd.getColumnName(i)+ |
234 ":"+rd.getColumnClassName(i); | 234 ":"+rd.getColumnClassName(i); |
277 featureStore.setTransaction(transaction); | 277 featureStore.setTransaction(transaction); |
278 | 278 |
279 featureStore.addFeatures(collection); | 279 featureStore.addFeatures(collection); |
280 transaction.commit(); | 280 transaction.commit(); |
281 success = true; | 281 success = true; |
282 } | 282 } |
283 catch (IOException ioe) { | 283 catch (IOException ioe) { |
284 log.error(ioe.getLocalizedMessage(), ioe); | 284 log.error(ioe.getLocalizedMessage(), ioe); |
285 } | 285 } |
286 finally { | 286 finally { |
287 if (transaction != null) { | 287 if (transaction != null) { |
293 catch (IOException ioe) {} | 293 catch (IOException ioe) {} |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 return geomType; | 297 return geomType; |
298 | 298 |
299 } | 299 } |
300 | 300 |
301 public static boolean writeMultiPolygonsToFile( | 301 public static boolean writeMultiPolygonsToFile( |
302 File shapeFile, | 302 File shapeFile, |
303 Integer parameterId, | 303 Integer parameterId, |
304 Integer layer, | 304 Integer layer, |
305 Date date, | 305 Date date, |
322 if (name == null) { | 322 if (name == null) { |
323 name = shapeFile.getName(); | 323 name = shapeFile.getName(); |
324 } | 324 } |
325 | 325 |
326 SimpleFeatureType TYPE; | 326 SimpleFeatureType TYPE; |
327 | 327 |
328 try { | 328 try { |
329 TYPE = DataUtilities.createType( | 329 TYPE = DataUtilities.createType( |
330 name, | 330 name, |
331 "geom:MultiPolygon:srid=4326," + | 331 "geom:MultiPolygon:srid=4326," + |
332 "PARAMETER:Integer," + | 332 "PARAMETER:Integer," + |
333 "LAYER:Integer," + | 333 "LAYER:Integer," + |
334 "DATE:Date," + | 334 "DATE:Date," + |
335 "CLASS:Integer"); | 335 "CLASS:Integer"); |
336 } | 336 } |
337 catch (SchemaException se) { | 337 catch (SchemaException se) { |
340 } | 340 } |
341 | 341 |
342 SimpleFeatureBuilder featureBuilder = | 342 SimpleFeatureBuilder featureBuilder = |
343 new SimpleFeatureBuilder(TYPE); | 343 new SimpleFeatureBuilder(TYPE); |
344 | 344 |
345 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = | 345 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = |
346 FeatureCollections.newCollection(); | 346 FeatureCollections.newCollection(); |
347 | 347 |
348 for (Map.Entry<Integer, MultiPolygon> entry: | 348 for (Map.Entry<Integer, MultiPolygon> entry: |
349 multiPolygons.entrySet() | 349 multiPolygons.entrySet() |
350 ) { | 350 ) { |
380 featureStore.setTransaction(transaction); | 380 featureStore.setTransaction(transaction); |
381 | 381 |
382 featureStore.addFeatures(collection); | 382 featureStore.addFeatures(collection); |
383 transaction.commit(); | 383 transaction.commit(); |
384 success = true; | 384 success = true; |
385 } | 385 } |
386 catch (IOException ioe) { | 386 catch (IOException ioe) { |
387 log.error(ioe.getLocalizedMessage(), ioe); | 387 log.error(ioe.getLocalizedMessage(), ioe); |
388 } | 388 } |
389 finally { | 389 finally { |
390 if (transaction != null) { | 390 if (transaction != null) { |