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

http://dive4elements.wald.intevation.org