Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1106:e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
flys-artifacts/trunk@2609 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 30 Aug 2011 11:09:54 +0000 |
parents | 9f88cc54570c |
children | 005c2964f9af |
comparison
equal
deleted
inserted
replaced
1105:adb52a2005e7 | 1106:e9f66d63bdd0 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | 2 |
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.IOException; | 4 import java.io.IOException; |
5 import java.net.MalformedURLException; | |
5 import java.util.List; | 6 import java.util.List; |
6 | 7 |
7 import javax.xml.xpath.XPathConstants; | 8 import javax.xml.xpath.XPathConstants; |
8 | 9 |
10 import com.vividsolutions.jts.geom.LineString; | |
11 import com.vividsolutions.jts.geom.Polygon; | |
12 | |
9 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
14 | |
15 import org.opengis.feature.simple.SimpleFeature; | |
16 import org.opengis.feature.simple.SimpleFeatureType; | |
17 | |
18 import org.geotools.feature.FeatureCollection; | |
19 import org.geotools.feature.FeatureCollections; | |
20 import org.geotools.feature.SchemaException; | |
10 | 21 |
11 import de.intevation.artifacts.Artifact; | 22 import de.intevation.artifacts.Artifact; |
12 import de.intevation.artifacts.CallContext; | 23 import de.intevation.artifacts.CallContext; |
13 | 24 |
14 import de.intevation.artifacts.common.utils.Config; | 25 import de.intevation.artifacts.common.utils.Config; |
19 import de.intevation.flys.artifacts.FLYSArtifact; | 30 import de.intevation.flys.artifacts.FLYSArtifact; |
20 import de.intevation.flys.artifacts.model.FacetTypes; | 31 import de.intevation.flys.artifacts.model.FacetTypes; |
21 import de.intevation.flys.artifacts.model.WSPLGENFacet; | 32 import de.intevation.flys.artifacts.model.WSPLGENFacet; |
22 import de.intevation.flys.artifacts.model.WSPLGENJob; | 33 import de.intevation.flys.artifacts.model.WSPLGENJob; |
23 import de.intevation.flys.utils.FLYSUtils; | 34 import de.intevation.flys.utils.FLYSUtils; |
35 import de.intevation.flys.utils.GeometryUtils; | |
24 | 36 |
25 | 37 |
26 public class FloodMapState | 38 public class FloodMapState |
27 extends DefaultState | 39 extends DefaultState |
28 implements FacetTypes | 40 implements FacetTypes |
33 | 45 |
34 public static final String XPATH_SHAPEFILE_DIR = | 46 public static final String XPATH_SHAPEFILE_DIR = |
35 "/artifact-database/floodmap/shapefile-path/@value"; | 47 "/artifact-database/floodmap/shapefile-path/@value"; |
36 | 48 |
37 public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par"; | 49 public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par"; |
50 public static final String WSPLGEN_BARRIERS_LINES = "barrier_lines.shp"; | |
51 public static final String WSPLGEN_BARRIERS_POLY = "barrier_polygons.shp"; | |
38 | 52 |
39 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; | 53 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; |
40 | 54 |
41 | 55 |
42 | 56 |
146 setOut(artifact, job); | 160 setOut(artifact, job); |
147 setRange(artifact, job); | 161 setRange(artifact, job); |
148 setDelta(artifact, job); | 162 setDelta(artifact, job); |
149 setGel(artifact, job); | 163 setGel(artifact, job); |
150 setDist(artifact, job); | 164 setDist(artifact, job); |
165 setLine(artifact, artifactDir, job); | |
151 | 166 |
152 // TODO | 167 // TODO |
153 // setDgm(artifact, job); // SHP | 168 // setDgm(artifact, job); // SHP |
154 // setPro(artifact, job); // SHP | 169 // setPro(artifact, job); // SHP |
155 // setWsp(artifact, job); // WSP | 170 // setWsp(artifact, job); // WSP |
156 // setWspTag(artifact, job); | 171 // setWspTag(artifact, job); |
157 // setLine(artifact, job); // SHP | |
158 // setAxis(artifact, job); // SHP | 172 // setAxis(artifact, job); // SHP |
159 // setArea(artifact, job); // SHP | 173 // setArea(artifact, job); // SHP |
160 // setOutFile(artifact, job); | 174 // setOutFile(artifact, job); |
161 | 175 |
162 try { | 176 try { |
237 } | 251 } |
238 catch (NumberFormatException nfe) { | 252 catch (NumberFormatException nfe) { |
239 // nothing to do here | 253 // nothing to do here |
240 } | 254 } |
241 } | 255 } |
256 | |
257 | |
258 protected void setLine(FLYSArtifact artifact, File dir, WSPLGENJob job) { | |
259 String geoJSON = artifact.getDataAsString("uesk.barriers"); | |
260 String srid = FLYSUtils.getRiverSrid(artifact); | |
261 String srs = "EPSG:" + srid; | |
262 | |
263 SimpleFeatureType ft = GeometryUtils.buildBarriersFeatureType(srs); | |
264 List<SimpleFeature> features = GeometryUtils.parseGeoJSON(geoJSON, ft); | |
265 | |
266 FeatureCollection[] fcs = splitLinesAndPolygons(features); | |
267 | |
268 File shapeLines = new File(dir, WSPLGEN_BARRIERS_LINES); | |
269 File shapePolys = new File(dir, WSPLGEN_BARRIERS_POLY); | |
270 | |
271 try { | |
272 GeometryUtils.writeShapefile( | |
273 shapeLines, | |
274 GeometryUtils.buildFeatureType("lines", srid, "LineString"), | |
275 fcs[0]); | |
276 job.addLin(shapeLines.getAbsolutePath()); | |
277 | |
278 GeometryUtils.writeShapefile( | |
279 shapePolys, | |
280 GeometryUtils.buildFeatureType("polygons", srid, "Polygon"), | |
281 fcs[1]); | |
282 job.addLin(shapePolys.getAbsolutePath()); | |
283 } | |
284 catch (MalformedURLException mue) { | |
285 logger.error("Error while writing shapefile: " + mue.getMessage()); | |
286 } | |
287 catch (IOException ioe) { | |
288 logger.error("Error while writing shapefile: " + ioe.getMessage()); | |
289 } | |
290 catch (SchemaException se) { | |
291 logger.error("Error while writing shapefile: " + se.getMessage()); | |
292 } | |
293 } | |
294 | |
295 | |
296 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) { | |
297 FeatureCollection lines = FeatureCollections.newCollection(); | |
298 FeatureCollection polygons = FeatureCollections.newCollection(); | |
299 | |
300 for (SimpleFeature feature: f) { | |
301 Object geom = feature.getDefaultGeometry(); | |
302 | |
303 if (geom instanceof LineString) { | |
304 lines.add(feature); | |
305 } | |
306 else if (geom instanceof Polygon) { | |
307 polygons.add(feature); | |
308 } | |
309 else { | |
310 logger.warn("Feature not supported: " + geom.getClass()); | |
311 } | |
312 } | |
313 | |
314 logger.debug("Found " + lines.size() + " barrier lines."); | |
315 logger.debug("Found " + polygons.size() + " barrier polygons."); | |
316 | |
317 return new FeatureCollection[] { lines, polygons }; | |
318 } | |
242 } | 319 } |
243 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 320 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |