comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFixpointsArtifact.java @ 3814:8083f6384023

merged flys-artifacts/pre2.6-2012-01-04
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:56 +0200
parents 841af55d5e53
children f5af3adb3b95
comparison
equal deleted inserted replaced
1491:2a00f4849738 3814:8083f6384023
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.Fixpoint;
20
21 import de.intevation.flys.artifacts.model.FacetTypes;
22 import de.intevation.flys.artifacts.model.RiverFactory;
23 import de.intevation.flys.artifacts.resources.Resources;
24 import de.intevation.flys.utils.FLYSUtils;
25
26
27 public class WMSFixpointsArtifact extends WMSDBArtifact {
28
29 public static final String NAME = "fixpoints";
30
31
32 private static final Logger logger =
33 Logger.getLogger(WMSFixpointsArtifact.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("WMSFixpointsArtifact.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 FixpointsState(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 FixpointsState extends WMSDBState implements FacetTypes
76 {
77 private static final Logger logger =
78 Logger.getLogger(FixpointsState.class);
79
80 protected int riverId;
81
82 public FixpointsState(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 @Override
103 protected String getFacetType() {
104 return FLOODMAP_FIXPOINTS;
105 }
106
107 @Override
108 protected String getTitle(CallMeta meta) {
109 return Resources.getMsg(
110 meta,
111 FLOODMAP_FIXPOINTS,
112 FLOODMAP_FIXPOINTS);
113 }
114
115 @Override
116 protected String getUrl() {
117 return FLYSUtils.getUserWMSUrl(artifact.identifier());
118 }
119
120 @Override
121 protected String getSrid() {
122 River river = RiverFactory.getRiver(getRiverId());
123 return FLYSUtils.getRiverSrid(river.getName());
124 }
125
126 @Override
127 protected Envelope getExtent() {
128 List<Fixpoint> fixpoints = Fixpoint.getFixpoints(getRiverId());
129
130 Envelope max = null;
131
132 for (Fixpoint f: fixpoints) {
133 Envelope env = f.getGeom().getEnvelopeInternal();
134
135 if (max == null) {
136 max = env;
137 continue;
138 }
139
140 max.expandToInclude(env);
141 }
142
143 return max;
144 }
145
146 @Override
147 protected String getFilter() {
148 return "river_id=" + String.valueOf(getRiverId());
149 }
150
151 @Override
152 protected String getDataString() {
153 String srid = getSrid();
154
155 if (FLYSUtils.isUsingOracle()) {
156 return "geom FROM fixpoints USING SRID " + srid;
157 }
158 else {
159 return "geom FROM fixpoints USING UNIQUE id USING SRID " + srid;
160 }
161 }
162
163 @Override
164 protected String getGeometryType() {
165 return "POINT";
166 }
167 } // end of WMSKmState
168 }
169 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org