comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 2639:a78dafdd8590

Issue 657. Added file upload service to load a user defined shapefile. User the shapefile for wsplgen calculation and display a new layer. flys-artifacts/trunk@4292 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 25 Apr 2012 07:45:00 +0000
parents 8cb679d4ec49
children 6875120af2a2
comparison
equal deleted inserted replaced
2638:ccad7a6ddaa4 2639:a78dafdd8590
80 public static final String WSPLGEN_AXIS = "axis.shp"; 80 public static final String WSPLGEN_AXIS = "axis.shp";
81 public static final String WSPLGEN_QPS = "qps.shp"; 81 public static final String WSPLGEN_QPS = "qps.shp";
82 public static final String WSPLGEN_FLOODPLAIN = "talaue.shp"; 82 public static final String WSPLGEN_FLOODPLAIN = "talaue.shp";
83 public static final String WSPLGEN_WSP_FILE = "waterlevel.wst"; 83 public static final String WSPLGEN_WSP_FILE = "waterlevel.wst";
84 public static final String WSPLGEN_OUTPUT_FILE = "wsplgen.shp"; 84 public static final String WSPLGEN_OUTPUT_FILE = "wsplgen.shp";
85 public static final String WSPLGEN_USER_SHAPE = "user-rgd.shp";
86 public static final String WSPLGEN_USER_ZIP = "user-rgd.zip";
87 public static final String WSPLGEN_USER_FILENAME = "user-rgd";
85 88
86 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; 89 public static final int WSPLGEN_DEFAULT_OUTPUT = 0;
87 90
88 91
89 /** 92 /**
263 @Override 266 @Override
264 public void endOfLife(Artifact artifact, Object callContext) { 267 public void endOfLife(Artifact artifact, Object callContext) {
265 logger.info("FloodMapState.endOfLife: " + artifact.identifier()); 268 logger.info("FloodMapState.endOfLife: " + artifact.identifier());
266 269
267 FLYSArtifact flys = (FLYSArtifact) artifact; 270 FLYSArtifact flys = (FLYSArtifact) artifact;
268 removeDirectory(flys);
269 271
270 Scheduler scheduler = Scheduler.getInstance(); 272 Scheduler scheduler = Scheduler.getInstance();
271 scheduler.cancelJob(flys.identifier()); 273 scheduler.cancelJob(flys.identifier());
272 274
273 MapfileGenerator.getInstance().update(); 275 MapfileGenerator.getInstance().update();
296 setRange(artifact, job); 298 setRange(artifact, job);
297 setDelta(artifact, job); 299 setDelta(artifact, job);
298 setGel(artifact, job); 300 setGel(artifact, job);
299 setDist(artifact, job); 301 setDist(artifact, job);
300 setLine(artifact, facetCreator, artifactDir, job); 302 setLine(artifact, facetCreator, artifactDir, job);
303 setUserShape(artifact, facetCreator, artifactDir, job);
301 setAxis(artifact, artifactDir, job); 304 setAxis(artifact, artifactDir, job);
302 setPro(artifact, artifactDir, job); 305 setPro(artifact, artifactDir, job);
303 setDgm(artifact, job); 306 setDgm(artifact, job);
304 setArea(artifact, artifactDir, job); 307 setArea(artifact, artifactDir, job);
305 setOutFile(artifact, job); 308 setOutFile(artifact, job);
469 facetCreator.createBarrierFacet(); 472 facetCreator.createBarrierFacet();
470 } 473 }
471 } 474 }
472 475
473 476
477 protected void setUserShape(
478 FLYSArtifact artifact,
479 FacetCreator facetCreator,
480 File dir,
481 WSPLGENJob job
482 ) {
483 File archive = new File(dir, WSPLGEN_USER_ZIP);
484 boolean exists = archive.exists();
485 logger.debug("Zip file exists: " + exists);
486 if (exists) {
487 try {
488 File tmpDir = new File(dir, "usr_tmp");
489 FileTools.extractArchive(archive, tmpDir);
490 moveFiles(tmpDir, dir);
491 }
492 catch (IOException ioe) {
493 logger.warn("Zip archive " + dir + "/" + WSPLGEN_USER_ZIP + " could not be extracted.");
494 return;
495 }
496
497 job.addLin(dir + "/" + WSPLGEN_USER_SHAPE);
498 facetCreator.createUserShapeFacet();
499 }
500 }
501
474 protected SimpleFeatureType getBarriersFeatureType( 502 protected SimpleFeatureType getBarriersFeatureType(
475 String name, 503 String name,
476 String srs, 504 String srs,
477 Class type 505 Class type
478 ) { 506 ) {
806 } 834 }
807 catch (IOException ioe) { /* do nothing */ } 835 catch (IOException ioe) { /* do nothing */ }
808 } 836 }
809 } 837 }
810 } 838 }
839
840
841 protected void moveFiles(File source, final File target)
842 throws IOException
843 {
844 if (!source.exists()) {
845 return;
846 }
847 if (!target.exists()) {
848 target.mkdir();
849 }
850 FileTools.walkTree(source, new FileTools.FileVisitor() {
851 public boolean visit(File file) {
852 if (!file.isDirectory()) {
853 String name = file.getName();
854 String suffix = "";
855 int pos = name.lastIndexOf('.');
856 if (pos > 0 && pos < name.length() - 1) {
857 suffix = name.substring(pos + 1);
858 }
859 else {
860 return true;
861 }
862 try {
863 FileTools.copyFile(file, new File(target, WSPLGEN_USER_FILENAME + "." + suffix));
864 }
865 catch (IOException ioe) {
866 logger.warn ("Error while copying file " + file.getName());
867 return true;
868 }
869 }
870 return true;
871 }
872 });
873
874 FileTools.deleteRecursive(source);
875 }
811 } 876 }
812 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 877 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org