Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.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 | ccad7a6ddaa4 |
children | 7a124cb11d8e |
comparison
equal
deleted
inserted
replaced
2638:ccad7a6ddaa4 | 2639:a78dafdd8590 |
---|---|
10 import java.util.ArrayList; | 10 import java.util.ArrayList; |
11 import java.util.Date; | 11 import java.util.Date; |
12 import java.util.List; | 12 import java.util.List; |
13 | 13 |
14 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
15 | |
16 import org.geotools.data.shapefile.ShpFiles; | |
17 import org.geotools.data.shapefile.shp.ShapefileReader; | |
18 import org.geotools.data.shapefile.shp.ShapefileHeader; | |
15 | 19 |
16 import org.apache.velocity.Template; | 20 import org.apache.velocity.Template; |
17 import org.apache.velocity.VelocityContext; | 21 import org.apache.velocity.VelocityContext; |
18 import org.apache.velocity.app.VelocityEngine; | 22 import org.apache.velocity.app.VelocityEngine; |
19 | 23 |
38 extends Thread | 42 extends Thread |
39 { | 43 { |
40 public static final String WSPLGEN_RESULT_SHAPE = "wsplgen.shp"; | 44 public static final String WSPLGEN_RESULT_SHAPE = "wsplgen.shp"; |
41 public static final String WSPLGEN_LINES_SHAPE = "barrier_lines.shp"; | 45 public static final String WSPLGEN_LINES_SHAPE = "barrier_lines.shp"; |
42 public static final String WSPLGEN_POLYGONS_SHAPE = "barrier_polygons.shp"; | 46 public static final String WSPLGEN_POLYGONS_SHAPE = "barrier_polygons.shp"; |
47 public static final String WSPLGEN_USER_SHAPE = "user-rgd.shp"; | |
43 | 48 |
44 public static final String WSPLGEN_LAYER_TEMPLATE = "wsplgen_layer.vm"; | 49 public static final String WSPLGEN_LAYER_TEMPLATE = "wsplgen_layer.vm"; |
45 public static final String SHP_LAYER_TEMPLATE = "shapefile_layer.vm"; | 50 public static final String SHP_LAYER_TEMPLATE = "shapefile_layer.vm"; |
46 public static final String DB_LAYER_TEMPLATE = "db_layer.vm"; | 51 public static final String DB_LAYER_TEMPLATE = "db_layer.vm"; |
47 | 52 |
48 public static final String MS_WSPLGEN_PREFIX = "wsplgen-"; | 53 public static final String MS_WSPLGEN_PREFIX = "wsplgen-"; |
49 public static final String MS_BARRIERS_PREFIX = "barriers-"; | 54 public static final String MS_BARRIERS_PREFIX = "barriers-"; |
50 public static final String MS_LINE_PREFIX = "lines-"; | 55 public static final String MS_LINE_PREFIX = "lines-"; |
51 public static final String MS_POLYGONS_PREFIX = "polygons-"; | 56 public static final String MS_POLYGONS_PREFIX = "polygons-"; |
52 public static final String MS_LAYER_PREFIX = "ms_layer-"; | 57 public static final String MS_LAYER_PREFIX = "ms_layer-"; |
58 public static final String MS_USERSHAPE_PREFIX = "user-"; | |
53 | 59 |
54 protected static final long SLEEPTIME = 10 * 1000L; // 10 seconds | 60 protected static final long SLEEPTIME = 10 * 1000L; // 10 seconds |
55 | 61 |
56 private static Logger logger = Logger.getLogger(MapfileGenerator.class); | 62 private static Logger logger = Logger.getLogger(MapfileGenerator.class); |
57 | 63 |
511 } | 517 } |
512 catch (FileNotFoundException fnfe) { | 518 catch (FileNotFoundException fnfe) { |
513 logger.error(fnfe, fnfe); | 519 logger.error(fnfe, fnfe); |
514 logger.warn("Unable to write layer: " + namePolygons); | 520 logger.warn("Unable to write layer: " + namePolygons); |
515 } | 521 } |
522 } | |
523 | |
524 | |
525 /** | |
526 * Creates a layer file used for Mapserver's mapfile which represents the | |
527 * shape files uploaded by the user. | |
528 * | |
529 * @param flys The FLYSArtifact that owns <i>wms</i>. | |
530 * @param wms The WMSLayerFacet that contains information for the layer. | |
531 */ | |
532 public void createUserShapeLayer(FLYSArtifact flys, WMSLayerFacet wms) | |
533 throws FileNotFoundException, IOException | |
534 { | |
535 logger.debug("createUserShapeLayer"); | |
536 | |
537 String uuid = flys.identifier(); | |
538 File dir = new File(getShapefileBaseDir(), uuid); | |
539 File test = new File(dir, WSPLGEN_USER_SHAPE); | |
540 | |
541 if (!test.exists() || !test.canRead()) { | |
542 logger.debug("No user layer existing."); | |
543 return; | |
544 } | |
545 | |
546 File userShape = new File(dir, WSPLGEN_USER_SHAPE); | |
547 ShpFiles sf = new ShpFiles(userShape); | |
548 ShapefileReader sfr = new ShapefileReader(sf, true, false, null); | |
549 ShapefileHeader sfh = sfr.getHeader(); | |
550 | |
551 String group = uuid + MS_USERSHAPE_PREFIX; | |
552 String groupTitle = "I18N_USER_SHAPE_TITLE"; | |
553 | |
554 LayerInfo info = new LayerInfo(); | |
555 info.setName(MS_USERSHAPE_PREFIX + uuid); | |
556 if (sfh.getShapeType().isLineType()) { | |
557 info.setType("LINE"); | |
558 } | |
559 else if (sfh.getShapeType().isPolygonType()) { | |
560 info.setType("POLYGON"); | |
561 } | |
562 else { | |
563 return; | |
564 } | |
565 info.setDirectory(uuid); | |
566 info.setData(WSPLGEN_USER_SHAPE); | |
567 info.setTitle("I18N_USER_SHAPE"); | |
568 info.setGroup(group); | |
569 info.setGroupTitle(groupTitle); | |
570 | |
571 String nameUser = MS_LAYER_PREFIX + wms.getName(); | |
572 | |
573 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE); | |
574 if (tpl == null) { | |
575 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found."); | |
576 return; | |
577 } | |
578 | |
579 try { | |
580 writeLayer(info, dir, nameUser, tpl); | |
581 } | |
582 catch (FileNotFoundException fnfe) { | |
583 logger.error(fnfe, fnfe); | |
584 logger.warn("Unable to write layer: " + nameUser); | |
585 } | |
586 | |
516 } | 587 } |
517 | 588 |
518 | 589 |
519 /** | 590 /** |
520 * Creates a layer file used for Mapserver's mapfile which represents | 591 * Creates a layer file used for Mapserver's mapfile which represents |