comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1108:5b1198c27d43

Export riveraxis and crosssections to shapefiles for WSPLGEN. flys-artifacts/trunk@2612 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Aug 2011 15:17:43 +0000
parents 005c2964f9af
children ba9fa72dd6f5
comparison
equal deleted inserted replaced
1107:005c2964f9af 1108:5b1198c27d43
13 13
14 import org.apache.log4j.Logger; 14 import org.apache.log4j.Logger;
15 15
16 import org.opengis.feature.simple.SimpleFeature; 16 import org.opengis.feature.simple.SimpleFeature;
17 import org.opengis.feature.simple.SimpleFeatureType; 17 import org.opengis.feature.simple.SimpleFeatureType;
18 import org.opengis.referencing.FactoryException;
19 import org.opengis.referencing.NoSuchAuthorityCodeException;
20 18
21 import org.geotools.feature.FeatureCollection; 19 import org.geotools.feature.FeatureCollection;
22 import org.geotools.feature.FeatureCollections; 20 import org.geotools.feature.FeatureCollections;
23 import org.geotools.feature.SchemaException; 21 import org.geotools.feature.simple.SimpleFeatureBuilder;
24 import org.geotools.referencing.CRS;
25 22
26 import de.intevation.artifacts.Artifact; 23 import de.intevation.artifacts.Artifact;
27 import de.intevation.artifacts.CallContext; 24 import de.intevation.artifacts.CallContext;
28 25
29 import de.intevation.artifacts.common.utils.Config; 26 import de.intevation.artifacts.common.utils.Config;
30 import de.intevation.artifacts.common.utils.FileTools; 27 import de.intevation.artifacts.common.utils.FileTools;
31 28
32 import de.intevation.artifactdatabase.state.Facet; 29 import de.intevation.artifactdatabase.state.Facet;
30
31 import de.intevation.flys.model.CrossSectionTrack;
32 import de.intevation.flys.model.RiverAxis;
33 33
34 import de.intevation.flys.artifacts.FLYSArtifact; 34 import de.intevation.flys.artifacts.FLYSArtifact;
35 import de.intevation.flys.artifacts.model.FacetTypes; 35 import de.intevation.flys.artifacts.model.FacetTypes;
36 import de.intevation.flys.artifacts.model.WSPLGENFacet; 36 import de.intevation.flys.artifacts.model.WSPLGENFacet;
37 import de.intevation.flys.artifacts.model.WSPLGENJob; 37 import de.intevation.flys.artifacts.model.WSPLGENJob;
55 "/artifact-database/floodmap/shapefile-path/@value"; 55 "/artifact-database/floodmap/shapefile-path/@value";
56 56
57 public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par"; 57 public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par";
58 public static final String WSPLGEN_BARRIERS_LINES = "barrier_lines.shp"; 58 public static final String WSPLGEN_BARRIERS_LINES = "barrier_lines.shp";
59 public static final String WSPLGEN_BARRIERS_POLY = "barrier_polygons.shp"; 59 public static final String WSPLGEN_BARRIERS_POLY = "barrier_polygons.shp";
60 public static final String WSPLGEN_AXIS = "axis.shp";
61 public static final String WSPLGEN_QPS = "qps.shp";
60 62
61 public static final int WSPLGEN_DEFAULT_OUTPUT = 0; 63 public static final int WSPLGEN_DEFAULT_OUTPUT = 0;
62 64
63 65
64 66
171 setRange(artifact, job); 173 setRange(artifact, job);
172 setDelta(artifact, job); 174 setDelta(artifact, job);
173 setGel(artifact, job); 175 setGel(artifact, job);
174 setDist(artifact, job); 176 setDist(artifact, job);
175 setLine(artifact, artifactDir, job); 177 setLine(artifact, artifactDir, job);
178 setAxis(artifact, artifactDir, job);
179 setPro(artifact, artifactDir, job);
176 180
177 // TODO 181 // TODO
178 // setDgm(artifact, job); // SHP 182 // setDgm(artifact, job); // SHP
179 // setPro(artifact, job); // SHP
180 // setWsp(artifact, job); // WSP 183 // setWsp(artifact, job); // WSP
181 // setWspTag(artifact, job); 184 // setWspTag(artifact, job);
182 // setAxis(artifact, job); // SHP
183 // setArea(artifact, job); // SHP 185 // setArea(artifact, job); // SHP
184 // setOutFile(artifact, job); 186 // setOutFile(artifact, job);
185 187
186 try { 188 try {
187 job.toFile(paraFile); 189 job.toFile(paraFile);
282 File shapePolys = new File(dir, WSPLGEN_BARRIERS_POLY); 284 File shapePolys = new File(dir, WSPLGEN_BARRIERS_POLY);
283 285
284 try { 286 try {
285 GeometryUtils.writeShapefile( 287 GeometryUtils.writeShapefile(
286 shapeLines, 288 shapeLines,
287 GeometryUtils.buildFeatureType( 289 GeometryUtils.buildFeatureType("lines", srs, LineString.class),
288 "lines", srs, LineString.class, CRS.decode(srs)),
289 fcs[0]); 290 fcs[0]);
290 job.addLin(shapeLines.getAbsolutePath()); 291 job.addLin(shapeLines.getAbsolutePath());
291 292
292 GeometryUtils.writeShapefile( 293 GeometryUtils.writeShapefile(
293 shapePolys, 294 shapePolys,
294 GeometryUtils.buildFeatureType( 295 GeometryUtils.buildFeatureType("polygons", srs, Polygon.class),
295 "polygons", srs, Polygon.class, CRS.decode(srs)),
296 fcs[1]); 296 fcs[1]);
297 job.addLin(shapePolys.getAbsolutePath()); 297 job.addLin(shapePolys.getAbsolutePath());
298 } 298 }
299 catch (MalformedURLException mue) { 299 catch (MalformedURLException mue) {
300 logger.error("Error while writing shapefile: " + mue.getMessage()); 300 logger.error("Error while writing shapefile: " + mue.getMessage());
301 } 301 }
302 catch (IOException ioe) { 302 catch (IOException ioe) {
303 logger.error("Error while writing shapefile: " + ioe.getMessage()); 303 logger.error("Error while writing shapefile: " + ioe.getMessage());
304 } 304 }
305 catch (SchemaException se) {
306 logger.error("Error while writing shapefile: " + se.getMessage());
307 }
308 catch (NoSuchAuthorityCodeException nsae) {
309 logger.error("Error while writing shapefile: " + nsae.getMessage());
310 }
311 catch (FactoryException fe) {
312 logger.error("Error while writing shapefile: " + fe.getMessage());
313 }
314 } 305 }
315 306
316 307
317 protected List<SimpleFeature> getBarriersFeatures(String json, String srs) { 308 protected List<SimpleFeature> getBarriersFeatures(String json, String srs) {
318 SimpleFeatureType ft = null; 309 SimpleFeatureType ft = GeometryUtils.buildFeatureType(
319 List<SimpleFeature> features = null; 310 "barriers", srs,Geometry.class);
320 311
321 try { 312 return GeometryUtils.parseGeoJSON(json, ft);
322 ft = GeometryUtils.buildFeatureType(
323 "barriers", srs, Geometry.class, CRS.decode(srs));
324
325 features = GeometryUtils.parseGeoJSON(json, ft);
326 }
327 catch (SchemaException se) {
328 logger.warn("Error while reading GeoJSON: " + se.getMessage());
329 }
330 catch (NoSuchAuthorityCodeException nsae) {
331 logger.warn("Error while reading GeoJSON: " + nsae.getMessage());
332 }
333 catch (FactoryException fe) {
334 logger.warn("Error while reading GeoJSON: " + fe.getMessage());
335 }
336
337 return features;
338 } 313 }
339 314
340 315
341 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) { 316 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) {
342 FeatureCollection lines = FeatureCollections.newCollection(); 317 FeatureCollection lines = FeatureCollections.newCollection();
359 logger.debug("Found " + lines.size() + " barrier lines."); 334 logger.debug("Found " + lines.size() + " barrier lines.");
360 logger.debug("Found " + polygons.size() + " barrier polygons."); 335 logger.debug("Found " + polygons.size() + " barrier polygons.");
361 336
362 return new FeatureCollection[] { lines, polygons }; 337 return new FeatureCollection[] { lines, polygons };
363 } 338 }
339
340
341 protected void setAxis(FLYSArtifact artifact, File dir, WSPLGENJob job) {
342 String river = artifact.getDataAsString("river");
343 String srid = FLYSUtils.getRiverSrid(artifact);
344 String srs = "EPSG:" + srid;
345
346 RiverAxis axis = RiverAxis.getRiverAxis(river);
347 if (axis == null) {
348 logger.warn("Could not find river axis for: '" + river + "'");
349 return;
350 }
351
352 Geometry geom = axis.getGeom();
353
354 SimpleFeatureType ft = GeometryUtils.buildFeatureType(
355 "axis", srs, LineString.class);
356
357 SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft);
358 builder.add(geom);
359
360 FeatureCollection collection = FeatureCollections.newCollection();
361 collection.add(builder.buildFeature("0"));
362
363 File axisShape = new File(dir, WSPLGEN_AXIS);
364
365 try {
366 GeometryUtils.writeShapefile(
367 axisShape,
368 GeometryUtils.buildFeatureType("axis", srs, LineString.class),
369 collection);
370 job.setAxis(axisShape.getAbsolutePath());
371 }
372 catch (MalformedURLException mue) {
373 logger.error("Error while writing shapefile: " + mue.getMessage());
374 }
375 catch (IOException ioe) {
376 logger.error("Error while writing shapefile: " + ioe.getMessage());
377 }
378 }
379
380
381 protected void setPro(FLYSArtifact artifact, File dir, WSPLGENJob job) {
382 String river = artifact.getDataAsString("river");
383 String srid = FLYSUtils.getRiverSrid(artifact);
384 String srs = "EPSG:" + srid;
385
386 List<CrossSectionTrack> cst =
387 CrossSectionTrack.getCrossSectionTrack(river);
388
389 logger.debug("Found " + cst.size() + " CrossSectionTracks.");
390
391 SimpleFeatureType ft = GeometryUtils.buildFeatureType(
392 "qps", srs, LineString.class);
393
394 SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft);
395 FeatureCollection collection = FeatureCollections.newCollection();
396
397 int i = 0;
398 for (CrossSectionTrack track: cst) {
399 builder.reset();
400 builder.add(track.getGeom());
401
402 collection.add(builder.buildFeature(String.valueOf(i++)));
403 }
404
405 File qpsShape = new File(dir, WSPLGEN_QPS);
406
407 try {
408 GeometryUtils.writeShapefile(
409 qpsShape,
410 GeometryUtils.buildFeatureType("qps", srs, LineString.class),
411 collection);
412 job.setPro(qpsShape.getAbsolutePath());
413 }
414 catch (MalformedURLException mue) {
415 logger.error("Error while writing shapefile: " + mue.getMessage());
416 }
417 catch (IOException ioe) {
418 logger.error("Error while writing shapefile: " + ioe.getMessage());
419 }
420 }
364 } 421 }
365 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 422 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org