Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/mapserver/RiverMapfileGenerator.java @ 5022:a9243df307b1 mapgenfix
Move all classes of mapfile generation to de.intevation.flys.mapserver package.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 19 Feb 2013 13:41:20 +0100 |
parents | |
children | 61bf64b102bc |
comparison
equal
deleted
inserted
replaced
5009:7c8ce0a95a64 | 5022:a9243df307b1 |
---|---|
1 package de.intevation.flys.mapserver; | |
2 | |
3 import com.vividsolutions.jts.geom.Envelope; | |
4 import com.vividsolutions.jts.geom.LineString; | |
5 | |
6 import de.intevation.flys.artifacts.model.LayerInfo; | |
7 import de.intevation.flys.artifacts.model.RiverFactory; | |
8 | |
9 import de.intevation.flys.model.River; | |
10 import de.intevation.flys.model.RiverAxis; | |
11 import de.intevation.flys.utils.FLYSUtils; | |
12 import de.intevation.flys.utils.MapUtils; | |
13 | |
14 import java.io.File; | |
15 import java.io.FileNotFoundException; | |
16 | |
17 import java.util.ArrayList; | |
18 import java.util.List; | |
19 | |
20 import java.util.regex.Pattern; | |
21 | |
22 import org.apache.log4j.Logger; | |
23 | |
24 import org.apache.velocity.Template; | |
25 | |
26 public class RiverMapfileGenerator extends MapfileGenerator { | |
27 | |
28 public static final String XPATH_RIVERMAP_RIVER_PROJECTION = | |
29 "/artifact-database/rivermap/river[@name=$name]/srid/@value"; | |
30 | |
31 public static final String XPATH_RIVERMAP_SHAPEFILE_DIR = | |
32 "/artifact-database/rivermap/shapefile-path/@value"; | |
33 | |
34 public static final String XPATH_RIVERMAP_VELOCITY_LOGFILE = | |
35 "/artifact-database/rivermap/velocity/logfile/@path"; | |
36 | |
37 public static final String XPATH_RIVERMAP_MAPSERVER_URL = | |
38 "/artifact-database/rivermap/mapserver/server/@path"; | |
39 | |
40 public static final String XPATH_RIVERMAP_MAPFILE_PATH = | |
41 "/artifact-database/rivermap/mapserver/mapfile/@path"; | |
42 | |
43 public static final String XPATH_RIVERMAP_MAPFILE_TEMPLATE = | |
44 "/artifact-database/rivermap/mapserver/map-template/@path"; | |
45 | |
46 public static final String XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH = | |
47 "/artifact-database/rivermap/mapserver/templates/@path"; | |
48 | |
49 public static final Pattern DB_URL_PATTERN = | |
50 Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z]+)"); | |
51 | |
52 public static final Pattern DB_PSQL_URL_PATTERN = | |
53 Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z0-9]+)"); | |
54 | |
55 private static Logger logger = Logger.getLogger(RiverMapfileGenerator.class); | |
56 | |
57 /** | |
58 * Generate river axis mapfile. | |
59 */ | |
60 @Override | |
61 public void generate() { | |
62 logger.debug("generate()"); | |
63 | |
64 List<River> rivers = RiverFactory.getRivers(); | |
65 List<String> riverFiles = new ArrayList<String>(); | |
66 | |
67 for (River river : rivers) { | |
68 // We expect that every river has only one RiverAxis. | |
69 // This is not correct but currently the case here, see | |
70 // RiverAxis.java. | |
71 List<RiverAxis> riverAxis = RiverAxis.getRiverAxis(river.getName()); | |
72 if (riverAxis == null) { | |
73 logger.warn("River " + river.getName() + " has no river axis!"); | |
74 continue; | |
75 } | |
76 LineString geom = riverAxis.get(0).getGeom(); | |
77 Envelope extent = geom.getEnvelopeInternal(); | |
78 | |
79 createRiverAxisLayer( | |
80 river.getName(), | |
81 river.getId(), | |
82 Integer.toString(geom.getSRID()), | |
83 extent.getMinX() + " " + | |
84 extent.getMinY() + " " + | |
85 extent.getMaxX() + " " + | |
86 extent.getMaxY()); | |
87 | |
88 riverFiles.add("river-" + river.getName() + ".map"); | |
89 } | |
90 writeMapfile(riverFiles); | |
91 } | |
92 | |
93 protected void createRiverAxisLayer(String riverName, int riverID, String srid, String extend) { | |
94 LayerInfo layerInfo = new LayerInfo(); | |
95 layerInfo.setName(riverName); | |
96 layerInfo.setConnection(MapUtils.getConnection()); | |
97 layerInfo.setConnectionType(MapUtils.getConnectionType()); | |
98 layerInfo.setSrid(srid); | |
99 layerInfo.setExtent(extend); | |
100 layerInfo.setType("line"); | |
101 layerInfo.setData("geom FROM river_axes"); // FIXME: Use templates for that | |
102 layerInfo.setFilter("river_id = " + riverID); | |
103 layerInfo.setTitle(riverName + " RiverAxis"); | |
104 | |
105 File layerFile = new File("river-" + riverName + ".map"); | |
106 Template template = getTemplateByName("riveraxis-layer.vm"); | |
107 if (template == null) { | |
108 logger.warn("Template riveraxis-layer.vm not found."); | |
109 return; | |
110 } | |
111 | |
112 try { | |
113 writeLayer(layerInfo, layerFile, template); | |
114 } | |
115 catch (FileNotFoundException e) { | |
116 logger.warn(e.getLocalizedMessage(), e); | |
117 } | |
118 } | |
119 | |
120 @Override | |
121 protected String getVelocityLogfile() { | |
122 return FLYSUtils.getXPathString(XPATH_RIVERMAP_VELOCITY_LOGFILE); | |
123 } | |
124 | |
125 @Override | |
126 protected String getMapserverTemplatePath() { | |
127 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH); | |
128 } | |
129 | |
130 @Override | |
131 protected String getMapserverUrl() { | |
132 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPSERVER_URL); | |
133 } | |
134 | |
135 @Override | |
136 protected String getMapfilePath() { | |
137 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPFILE_PATH); | |
138 } | |
139 | |
140 @Override | |
141 protected String getMapfileTemplate() { | |
142 return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPFILE_TEMPLATE); | |
143 } | |
144 } |