comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java @ 3806:881fcd01e056

merged flys-artifacts/pre2.6-2011-11-04
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:50 +0200
parents 5364b86a0880
children 06c157848c8f
comparison
equal deleted inserted replaced
3802:e831dc29e572 3806:881fcd01e056
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.artifacts.resources.Resources;
26 import de.intevation.flys.utils.FLYSUtils;
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 getTitle(CallMeta meta) {
111 return Resources.getMsg(meta, FLOODMAP_KMS, FLOODMAP_KMS);
112 }
113
114 @Override
115 protected String getUrl() {
116 return FLYSUtils.getUserWMSUrl(artifact.identifier());
117 }
118
119 @Override
120 protected String getSrid() {
121 River river = RiverFactory.getRiver(getRiverId());
122 return FLYSUtils.getRiverSrid(river.getName());
123 }
124
125 @Override
126 protected Envelope getExtent() {
127 List<RiverAxisKm> kms = RiverAxisKm.getRiverAxisKms(getRiverId());
128
129 Envelope max = null;
130
131 for (RiverAxisKm km: kms) {
132 Envelope env = km.getGeom().getEnvelopeInternal();
133
134 if (max == null) {
135 max = env;
136 continue;
137 }
138
139 max.expandToInclude(env);
140 }
141
142 return max;
143 }
144
145 @Override
146 protected String getFilter() {
147 return "river_id=" + String.valueOf(getRiverId());
148 }
149
150 @Override
151 protected String getDataString() {
152 return "geom FROM river_axes_km USING UNIQUE id USING SRID 31466";
153 }
154
155 @Override
156 protected String getGeometryType() {
157 return "POINT";
158 }
159 } // end of WMSKmState
160 }
161 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org