Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSLineArtifact.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | c8f670ae96e8 |
children | b0ba96bbf01d |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.w3c.dom.Document; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import com.vividsolutions.jts.geom.Envelope; | |
10 | |
11 import de.intevation.artifacts.ArtifactFactory; | |
12 import de.intevation.artifacts.CallMeta; | |
13 | |
14 import de.intevation.artifactdatabase.state.DefaultOutput; | |
15 import de.intevation.artifactdatabase.state.Facet; | |
16 import de.intevation.artifactdatabase.state.State; | |
17 | |
18 import de.intevation.flys.model.River; | |
19 import de.intevation.flys.model.Line; | |
20 | |
21 import de.intevation.flys.artifacts.model.FacetTypes; | |
22 import de.intevation.flys.artifacts.model.RiverFactory; | |
23 import de.intevation.flys.utils.FLYSUtils; | |
24 import de.intevation.flys.utils.GeometryUtils; | |
25 | |
26 | |
27 public class WMSLineArtifact extends WMSDBArtifact { | |
28 | |
29 public static final String NAME = "lines"; | |
30 | |
31 | |
32 private static final Logger logger = | |
33 Logger.getLogger(WMSLineArtifact.class); | |
34 | |
35 | |
36 @Override | |
37 public void setup( | |
38 String identifier, | |
39 ArtifactFactory factory, | |
40 Object context, | |
41 CallMeta callMeta, | |
42 Document data) | |
43 { | |
44 logger.debug("WMSLineArtifact.setup"); | |
45 | |
46 super.setup(identifier, factory, context, callMeta, data); | |
47 } | |
48 | |
49 | |
50 @Override | |
51 public String getName() { | |
52 return NAME; | |
53 } | |
54 | |
55 | |
56 @Override | |
57 public State getCurrentState(Object cc) { | |
58 State s = new LineState(this); | |
59 | |
60 List<Facet> fs = facets.get(getCurrentStateId()); | |
61 | |
62 DefaultOutput o = new DefaultOutput( | |
63 "floodmap", | |
64 "floodmap", | |
65 "image/png", | |
66 fs, | |
67 "map"); | |
68 | |
69 s.getOutputs().add(o); | |
70 | |
71 return s; | |
72 } | |
73 | |
74 | |
75 public static class LineState extends WMSDBState implements FacetTypes | |
76 { | |
77 private static final Logger logger = | |
78 Logger.getLogger(LineState.class); | |
79 | |
80 protected int riverId; | |
81 | |
82 public LineState(WMSDBArtifact artifact) { | |
83 super(artifact); | |
84 riverId = 0; | |
85 } | |
86 | |
87 public int getRiverId() { | |
88 if (riverId == 0) { | |
89 String ids = artifact.getDataAsString("ids"); | |
90 String[] parts = ids.split(";"); | |
91 | |
92 try { | |
93 riverId = Integer.valueOf(parts[0]); | |
94 } | |
95 catch (NumberFormatException nfe) { | |
96 logger.error("Cannot parse river id from '" + parts[0] + "'"); | |
97 } | |
98 } | |
99 | |
100 return riverId; | |
101 } | |
102 | |
103 @Override | |
104 protected String getFacetType() { | |
105 return FLOODMAP_LINES; | |
106 } | |
107 | |
108 @Override | |
109 protected String getUrl() { | |
110 return FLYSUtils.getUserWMSUrl(artifact.identifier()); | |
111 } | |
112 | |
113 @Override | |
114 protected String getSrid() { | |
115 River river = RiverFactory.getRiver(getRiverId()); | |
116 return FLYSUtils.getRiverSrid(river.getName()); | |
117 } | |
118 | |
119 @Override | |
120 protected Envelope getExtent() { | |
121 List<Line> lines = Line.getLines(getRiverId(), getName()); | |
122 | |
123 Envelope max = null; | |
124 | |
125 for (Line l: lines) { | |
126 Envelope env = l.getGeom().getEnvelopeInternal(); | |
127 | |
128 if (max == null) { | |
129 max = env; | |
130 continue; | |
131 } | |
132 | |
133 max.expandToInclude(env); | |
134 } | |
135 | |
136 return max != null | |
137 ? GeometryUtils.transform(max, getSrid()) | |
138 : max; | |
139 } | |
140 | |
141 @Override | |
142 protected String getFilter() { | |
143 return "river_id=" + String.valueOf(getRiverId()) + | |
144 " AND name='" + getName() + "'"; | |
145 } | |
146 | |
147 @Override | |
148 protected String getDataString() { | |
149 String srid = getSrid(); | |
150 | |
151 if (FLYSUtils.isUsingOracle()) { | |
152 return "geom FROM lines USING SRID " + srid; | |
153 } | |
154 else { | |
155 return "geom FROM lines USING UNIQUE id USING SRID " + srid; | |
156 } | |
157 } | |
158 | |
159 @Override | |
160 protected String getGeometryType() { | |
161 return "LINE"; | |
162 } | |
163 } // end of WMSKmState | |
164 } | |
165 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |