comparison flys-artifacts/src/main/java/de/intevation/flys/wsplgen/FacetCreator.java @ 3786:4adc35aa655c

merged flys-artifacts/2.9.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:47 +0200
parents 453d2d0c4258
children 36147ddb2c32
comparison
equal deleted inserted replaced
3719:e82acd5c86f7 3786:4adc35aa655c
1 package de.intevation.flys.wsplgen;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import com.vividsolutions.jts.geom.Envelope;
9
10 import de.intevation.artifactdatabase.state.Facet;
11 import de.intevation.artifacts.CallContext;
12 import de.intevation.flys.artifacts.FLYSArtifact;
13 import de.intevation.flys.artifacts.model.FacetTypes;
14 import de.intevation.flys.artifacts.model.map.WMSLayerFacet;
15 import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet;
16 import de.intevation.flys.artifacts.resources.Resources;
17 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
18 import de.intevation.flys.model.CrossSectionTrack;
19 import de.intevation.flys.utils.FLYSUtils;
20 import de.intevation.flys.utils.GeometryUtils;
21 import de.intevation.flys.utils.MapfileGenerator;
22
23
24 public class FacetCreator implements FacetTypes {
25
26 public static final String I18N_WSPLGEN_RESULT = "floodmap.uesk";
27 public static final String I18N_WSPLGEN_DEFAULT = "floodmap.uesk";
28 public static final String I18N_BARRIERS = "floodmap.barriers";
29 public static final String I18N_BARRIERS_DEFAULT = "floodmap.barriers";
30 public static final String I18N_USERSHAPE = "floodmap.usershape";
31 public static final String I18N_USERSHAPE_DEFAULT = "floodmap.usershape";
32
33 protected FLYSArtifact artifact;
34
35 protected CallContext cc;
36
37 protected List<Facet> facets;
38 protected List<Facet> tmpFacets;
39
40 protected String url;
41 protected String hash;
42 protected String stateId;
43
44
45 private static Logger logger = Logger.getLogger(FacetCreator.class);
46
47
48 public FacetCreator(
49 FLYSArtifact artifact,
50 CallContext cc,
51 String hash,
52 String sId,
53 List<Facet> facets
54 ) {
55 this.tmpFacets = new ArrayList<Facet>(2);
56 this.facets = facets;
57 this.artifact = artifact;
58 this.cc = cc;
59 this.hash = hash;
60 this.stateId = sId;
61 }
62
63 protected String getRiver() {
64 return artifact.getDataAsString("river");
65 }
66
67 protected String getUrl() {
68 return FLYSUtils.getUserWMSUrl(artifact.identifier());
69 }
70
71 protected String getSrid() {
72 return FLYSUtils.getRiverSrid(artifact);
73 }
74
75 protected Envelope getWSPLGENBounds() {
76 String river = getRiver();
77 double kms[] = FLYSUtils.getKmRange(artifact);
78
79 logger.debug("### getWSPLGENBounds");
80 logger.debug("### from km: " + kms[0]);
81 logger.debug("### to km: " + kms[1]);
82
83 CrossSectionTrack a =
84 CrossSectionTrack.getCrossSectionTrack(river, kms[0]);
85
86 CrossSectionTrack b =
87 CrossSectionTrack.getCrossSectionTrack(river, kms[1]);
88
89 if (a == null || b == null) {
90 return null;
91 }
92
93 Envelope envA = a.getGeom().getEnvelopeInternal();
94 Envelope envB = b.getGeom().getEnvelopeInternal();
95
96 envA.expandToInclude(envB);
97
98 logger.debug("### => " + envA);
99
100 return envA;
101 }
102
103 protected Envelope getBounds() {
104 return GeometryUtils.getRiverBoundary(getRiver());
105 }
106
107 public List<Facet> getFacets() {
108 return tmpFacets;
109 }
110
111 public void createWSPLGENFacet() {
112 WSPLGENLayerFacet wsplgen = new WSPLGENLayerFacet(
113 0,
114 FLOODMAP_WSPLGEN,
115 Resources.getMsg(
116 cc.getMeta(),
117 I18N_WSPLGEN_RESULT,
118 I18N_WSPLGEN_DEFAULT),
119 ComputeType.ADVANCE,
120 stateId,
121 hash,
122 getUrl());
123
124 Envelope bounds = getWSPLGENBounds();
125
126 if (bounds == null) {
127 bounds = getBounds();
128 }
129
130 wsplgen.addLayer(
131 MapfileGenerator.MS_WSPLGEN_PREFIX + artifact.identifier());
132 wsplgen.setSrid(getSrid());
133 wsplgen.setExtent(bounds);
134
135 tmpFacets.add(wsplgen);
136 }
137
138 public void createBarrierFacet() {
139 WMSLayerFacet barriers = new WMSLayerFacet(
140 1,
141 FLOODMAP_BARRIERS,
142 Resources.getMsg(
143 cc.getMeta(),
144 I18N_BARRIERS,
145 I18N_BARRIERS_DEFAULT),
146 ComputeType.ADVANCE,
147 stateId,
148 hash,
149 getUrl());
150
151 barriers.addLayer(
152 MapfileGenerator.MS_BARRIERS_PREFIX + artifact.identifier());
153 barriers.setSrid(getSrid());
154 barriers.setExtent(getBounds());
155
156 tmpFacets.add(barriers);
157 }
158
159
160 public void createUserShapeFacet() {
161 WMSLayerFacet shape = new WMSLayerFacet(
162 1,
163 FLOODMAP_USERSHAPE,
164 Resources.getMsg(
165 cc.getMeta(),
166 I18N_USERSHAPE,
167 I18N_USERSHAPE_DEFAULT),
168 ComputeType.ADVANCE,
169 stateId,
170 hash,
171 getUrl());
172
173 shape.addLayer(
174 MapfileGenerator.MS_USERSHAPE_PREFIX + artifact.identifier());
175 shape.setSrid(getSrid());
176 shape.setExtent(getBounds());
177
178 tmpFacets.add(shape);
179 }
180
181
182 public void finish() {
183 facets.addAll(getFacets());
184 }
185 }
186 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org