Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java @ 4703:38ec171544de
Work on rivers.map Generator.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 18 Dec 2012 15:46:36 +0100 |
parents | 13abfb1bcb75 |
children | d93748043cbc |
rev | line source |
---|---|
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.utils; |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
2 |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.flys.artifacts.model.LayerInfo; |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
4 import de.intevation.flys.artifacts.model.RiverFactory; |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
5 import de.intevation.flys.model.River; |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
6 |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
7 import java.io.File; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
8 import java.io.FileNotFoundException; |
4702
13abfb1bcb75
Fix typo in class names and correct file path in floodmap.xml.
Christian Lins <christian.lins@intevation.de>
parents:
4656
diff
changeset
|
9 import java.util.ArrayList; |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
10 import java.util.List; |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
11 |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
12 import org.apache.log4j.Logger; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
13 import org.apache.velocity.Template; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
14 |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
15 public class RiverMapfileGenerator extends MapfileGenerator { |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
16 |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
17 public static final String XPATH_RIVERMAP_RIVER_PROJECTION = |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
18 "/artifact-database/rivermap/river[@name=$name]/srid/@value"; |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
19 |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
20 public static final String XPATH_RIVERMAP_SHAPEFILE_DIR = |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
21 "/artifact-database/rivermap/shapefile-path/@value"; |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
22 |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
23 public static final String XPATH_RIVERMAP_VELOCITY_LOGFILE = |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
24 "/artifact-database/rivermap/velocity/logfile/@path"; |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
25 |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
26 public static final String XPATH_RIVERMAP_MAPSERVER_URL = |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
27 "/artifact-database/rivermap/mapserver/server/@path"; |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
28 |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
29 public static final String XPATH_RIVERMAP_MAPFILE_PATH = |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
30 "/artifact-database/rivermap/mapserver/mapfile/@path"; |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
31 |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
32 public static final String XPATH_RIVERMAP_MAPFILE_TEMPLATE = |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
33 "/artifact-database/rivermap/mapserver/map-template/@path"; |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
34 |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
35 public static final String XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH = |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
36 "/artifact-database/rivermap/mapserver/templates/@path"; |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
37 |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
38 private static Logger logger = Logger.getLogger(RiverMapfileGenerator.class); |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
39 |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
40 /** |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
41 * Generate river axis mapfile. |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
42 */ |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
43 @Override |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
44 public void generate() { |
4702
13abfb1bcb75
Fix typo in class names and correct file path in floodmap.xml.
Christian Lins <christian.lins@intevation.de>
parents:
4656
diff
changeset
|
45 logger.debug("generate()"); |
13abfb1bcb75
Fix typo in class names and correct file path in floodmap.xml.
Christian Lins <christian.lins@intevation.de>
parents:
4656
diff
changeset
|
46 |
13abfb1bcb75
Fix typo in class names and correct file path in floodmap.xml.
Christian Lins <christian.lins@intevation.de>
parents:
4656
diff
changeset
|
47 List<River> rivers = RiverFactory.getRivers(); |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
48 List<String> riverFiles = new ArrayList<String>(); |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
49 |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
50 for (River river : rivers) { |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
51 createRiverAxisLayer( |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
52 river.getName(), |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
53 river.getId(), |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
54 "41677", |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
55 "100,100,100,100"); |
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
56 riverFiles.add("river-" + river.getName() + ".map"); |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
57 } |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
58 writeMapfile(riverFiles); |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
59 } |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
60 |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
61 protected void createRiverAxisLayer(String riverName, int riverID, String srid, String extend) { |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
62 LayerInfo layerInfo = new LayerInfo(); |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
63 layerInfo.setName(riverName); |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
64 layerInfo.setSrid(srid); |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
65 layerInfo.setExtent(extend); |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
66 layerInfo.setConnectionType(FLYSUtils.isUsingOracle() ? "oraclespatial" : "postgis"); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
67 |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
68 File layerFile = new File("river-" + riverName + ".map"); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
69 Template template = getTemplateByName(DB_LAYER_TEMPLATE); |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
70 if (template == null) { |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
71 logger.warn("Template '" + DB_LAYER_TEMPLATE + "' not found."); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
72 return; |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
73 } |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
74 |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
75 try { |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
76 writeLayer(layerInfo, layerFile, template); |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
77 } |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
78 catch (FileNotFoundException e) { |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
79 logger.warn(e.getLocalizedMessage(), e); |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
80 } |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
81 } |
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
82 |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
83 @Override |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
84 protected String getVelocityLogfile() { |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
85 return FLYSUtils.getXPathString(XPATH_RIVERMAP_VELOCITY_LOGFILE); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
86 } |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
87 |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
88 @Override |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
89 protected String getMapserverTemplatePath() { |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
90 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
91 } |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
92 |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
93 @Override |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
94 protected String getMapserverUrl() { |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
95 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPSERVER_URL); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
96 } |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
97 |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
98 @Override |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
99 protected String getMapfilePath() { |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
100 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPFILE_PATH); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
101 } |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
102 |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
103 @Override |
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
104 protected String getMapfileTemplate() { |
4703
38ec171544de
Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents:
4702
diff
changeset
|
105 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPFILE_TEMPLATE); |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4654
diff
changeset
|
106 } |
4654
861c47e0a8a0
Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
107 } |