Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.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 | b24920235944 |
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.Floodplain; | |
19 import de.intevation.flys.model.River; | |
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 WMSFloodplainArtifact extends WMSDBArtifact { | |
28 | |
29 public static final String NAME = "floodplain"; | |
30 | |
31 | |
32 private static final Logger logger = | |
33 Logger.getLogger(WMSFloodplainArtifact.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("WMSFloodplainArtifact.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 FloodplainState(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 FloodplainState extends WMSDBState implements FacetTypes | |
76 { | |
77 private static final Logger logger = | |
78 Logger.getLogger(FloodplainState.class); | |
79 | |
80 protected int riverId; | |
81 | |
82 public FloodplainState(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 | |
91 try { | |
92 riverId = Integer.valueOf(ids); | |
93 } | |
94 catch (NumberFormatException nfe) { | |
95 logger.error("Cannot parse river id from '" + ids + "'"); | |
96 } | |
97 } | |
98 | |
99 return riverId; | |
100 } | |
101 | |
102 protected River getRiver() { | |
103 return RiverFactory.getRiver(getRiverId()); | |
104 } | |
105 | |
106 @Override | |
107 protected String getFacetType() { | |
108 return FLOODMAP_FLOODPLAIN; | |
109 } | |
110 | |
111 @Override | |
112 protected String getUrl() { | |
113 return FLYSUtils.getUserWMSUrl(artifact.identifier()); | |
114 } | |
115 | |
116 @Override | |
117 protected String getSrid() { | |
118 River river = getRiver(); | |
119 return FLYSUtils.getRiverSrid(river.getName()); | |
120 } | |
121 | |
122 @Override | |
123 protected Envelope getExtent() { | |
124 River river = getRiver(); | |
125 Floodplain plain = Floodplain.getFloodplain(river.getName()); | |
126 | |
127 return GeometryUtils.transform( | |
128 plain.getGeom().getEnvelopeInternal(), | |
129 getSrid()); | |
130 } | |
131 | |
132 @Override | |
133 protected String getFilter() { | |
134 return "river_id=" + String.valueOf(getRiverId()); | |
135 } | |
136 | |
137 @Override | |
138 protected String getDataString() { | |
139 String srid = getSrid(); | |
140 | |
141 if (FLYSUtils.isUsingOracle()) { | |
142 return "geom FROM floodplain USING SRID " + srid; | |
143 } | |
144 else { | |
145 return "geom FROM floodplain USING UNIQUE id USING SRID " +srid; | |
146 } | |
147 } | |
148 | |
149 @Override | |
150 protected String getGeometryType() { | |
151 return "POLYGON"; | |
152 } | |
153 } // end of WMSKmState | |
154 } | |
155 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |