comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1121:66783d957201

Close open shapefile transactions properly. flys-artifacts/trunk@2628 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 01 Sep 2011 07:27:44 +0000
parents fb3947027e92
children be9bb260b835
comparison
equal deleted inserted replaced
1120:fb3947027e92 1121:66783d957201
2 2
3 import java.io.File; 3 import java.io.File;
4 import java.io.FileNotFoundException; 4 import java.io.FileNotFoundException;
5 import java.io.FileOutputStream; 5 import java.io.FileOutputStream;
6 import java.io.IOException; 6 import java.io.IOException;
7 import java.net.MalformedURLException;
8 import java.util.List; 7 import java.util.List;
9 8
10 import javax.xml.xpath.XPathConstants; 9 import javax.xml.xpath.XPathConstants;
11 10
12 import com.vividsolutions.jts.geom.Geometry; 11 import com.vividsolutions.jts.geom.Geometry;
298 FeatureCollection[] fcs = splitLinesAndPolygons(features); 297 FeatureCollection[] fcs = splitLinesAndPolygons(features);
299 298
300 File shapeLines = new File(dir, WSPLGEN_BARRIERS_LINES); 299 File shapeLines = new File(dir, WSPLGEN_BARRIERS_LINES);
301 File shapePolys = new File(dir, WSPLGEN_BARRIERS_POLY); 300 File shapePolys = new File(dir, WSPLGEN_BARRIERS_POLY);
302 301
303 try { 302 boolean l = GeometryUtils.writeShapefile(
304 GeometryUtils.writeShapefile( 303 shapeLines,
305 shapeLines, 304 GeometryUtils.buildFeatureType("lines", srs, LineString.class),
306 GeometryUtils.buildFeatureType("lines", srs, LineString.class), 305 fcs[0]);
307 fcs[0]); 306
307 if (l) {
308 job.addLin(shapeLines.getAbsolutePath()); 308 job.addLin(shapeLines.getAbsolutePath());
309 309 }
310 GeometryUtils.writeShapefile( 310
311 shapePolys, 311 boolean p = GeometryUtils.writeShapefile(
312 GeometryUtils.buildFeatureType("polygons", srs, Polygon.class), 312 shapePolys,
313 fcs[1]); 313 GeometryUtils.buildFeatureType("polygons", srs, Polygon.class),
314 fcs[1]);
315
316 if (p) {
314 job.addLin(shapePolys.getAbsolutePath()); 317 job.addLin(shapePolys.getAbsolutePath());
315 }
316 catch (MalformedURLException mue) {
317 logger.error("Error while writing shapefile: " + mue.getMessage());
318 }
319 catch (IOException ioe) {
320 logger.error("Error while writing shapefile: " + ioe.getMessage());
321 } 318 }
322 } 319 }
323 320
324 321
325 protected List<SimpleFeature> getBarriersFeatures(String json, String srs) { 322 protected List<SimpleFeature> getBarriersFeatures(String json, String srs) {
377 FeatureCollection collection = FeatureCollections.newCollection(); 374 FeatureCollection collection = FeatureCollections.newCollection();
378 collection.add(builder.buildFeature("0")); 375 collection.add(builder.buildFeature("0"));
379 376
380 File axisShape = new File(dir, WSPLGEN_AXIS); 377 File axisShape = new File(dir, WSPLGEN_AXIS);
381 378
382 try { 379 boolean a = GeometryUtils.writeShapefile(
383 GeometryUtils.writeShapefile( 380 axisShape,
384 axisShape, 381 GeometryUtils.buildFeatureType("axis", srs, LineString.class),
385 GeometryUtils.buildFeatureType("axis", srs, LineString.class), 382 collection);
386 collection); 383
384 if (a) {
387 job.setAxis(axisShape.getAbsolutePath()); 385 job.setAxis(axisShape.getAbsolutePath());
388 }
389 catch (MalformedURLException mue) {
390 logger.error("Error while writing shapefile: " + mue.getMessage());
391 }
392 catch (IOException ioe) {
393 logger.error("Error while writing shapefile: " + ioe.getMessage());
394 } 386 }
395 } 387 }
396 388
397 389
398 protected void setPro(FLYSArtifact artifact, File dir, WSPLGENJob job) { 390 protected void setPro(FLYSArtifact artifact, File dir, WSPLGENJob job) {
425 collection.add(builder.buildFeature(String.valueOf(i++))); 417 collection.add(builder.buildFeature(String.valueOf(i++)));
426 } 418 }
427 419
428 File qpsShape = new File(dir, WSPLGEN_QPS); 420 File qpsShape = new File(dir, WSPLGEN_QPS);
429 421
430 try { 422 boolean q = GeometryUtils.writeShapefile(
431 GeometryUtils.writeShapefile( 423 qpsShape,
432 qpsShape, 424 GeometryUtils.buildFeatureType("qps", srs, LineString.class, attrs),
433 GeometryUtils.buildFeatureType( 425 collection);
434 "qps", srs, LineString.class, attrs), 426
435 collection); 427 if (q) {
436 job.setPro(qpsShape.getAbsolutePath()); 428 job.setPro(qpsShape.getAbsolutePath());
437 }
438 catch (MalformedURLException mue) {
439 logger.error("Error while writing shapefile: " + mue.getMessage());
440 }
441 catch (IOException ioe) {
442 logger.error("Error while writing shapefile: " + ioe.getMessage());
443 } 429 }
444 } 430 }
445 431
446 432
447 protected void setDgm(FLYSArtifact artifact, WSPLGENJob job) { 433 protected void setDgm(FLYSArtifact artifact, WSPLGENJob job) {
478 FeatureCollection collection = FeatureCollections.newCollection(); 464 FeatureCollection collection = FeatureCollections.newCollection();
479 collection.add(builder.buildFeature("0")); 465 collection.add(builder.buildFeature("0"));
480 466
481 File talaueShape = new File(dir, WSPLGEN_FLOODPLAIN); 467 File talaueShape = new File(dir, WSPLGEN_FLOODPLAIN);
482 468
483 try { 469 boolean t = GeometryUtils.writeShapefile(
484 GeometryUtils.writeShapefile( 470 talaueShape,
485 talaueShape, 471 GeometryUtils.buildFeatureType("talaue", srs, MultiPolygon.class),
486 GeometryUtils.buildFeatureType( 472 collection);
487 "talaue", srs, MultiPolygon.class), 473
488 collection); 474 if (t) {
489 job.setArea(talaueShape.getAbsolutePath()); 475 job.setArea(talaueShape.getAbsolutePath());
490 }
491 catch (MalformedURLException mue) {
492 logger.error("Error while writing shapefile: " + mue.getMessage());
493 }
494 catch (IOException ioe) {
495 logger.error("Error while writing shapefile: " + ioe.getMessage());
496 } 476 }
497 } 477 }
498 478
499 479
500 protected void setOutFile(FLYSArtifact artifact, WSPLGENJob job) { 480 protected void setOutFile(FLYSArtifact artifact, WSPLGENJob job) {

http://dive4elements.wald.intevation.org