comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java @ 1119:faca1825818e

Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles. flys-artifacts/trunk@2626 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 01 Sep 2011 07:04:01 +0000
parents 7398280b11a0
children fb3947027e92
comparison
equal deleted inserted replaced
1118:7398280b11a0 1119:faca1825818e
333 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) { 333 protected FeatureCollection[] splitLinesAndPolygons(List<SimpleFeature> f) {
334 FeatureCollection lines = FeatureCollections.newCollection(); 334 FeatureCollection lines = FeatureCollections.newCollection();
335 FeatureCollection polygons = FeatureCollections.newCollection(); 335 FeatureCollection polygons = FeatureCollections.newCollection();
336 336
337 for (SimpleFeature feature: f) { 337 for (SimpleFeature feature: f) {
338 Object geom = feature.getDefaultGeometry(); 338 Geometry geom = (Geometry) feature.getDefaultGeometry();
339 339
340 if (geom instanceof LineString) { 340 if (geom instanceof LineString) {
341 lines.add(feature); 341 lines.add(feature);
342 } 342 }
343 else if (geom instanceof Polygon) { 343 else if (geom instanceof Polygon) {
403 List<CrossSectionTrack> cst = 403 List<CrossSectionTrack> cst =
404 CrossSectionTrack.getCrossSectionTrack(river); 404 CrossSectionTrack.getCrossSectionTrack(river);
405 405
406 logger.debug("Found " + cst.size() + " CrossSectionTracks."); 406 logger.debug("Found " + cst.size() + " CrossSectionTracks.");
407 407
408 Object[][] attrs = new Object[2][];
409 attrs[0] = new Object[] { "ELEVATION", Double.class };
410 attrs[1] = new Object[] { "KILOMETER", Double.class };
411
408 SimpleFeatureType ft = GeometryUtils.buildFeatureType( 412 SimpleFeatureType ft = GeometryUtils.buildFeatureType(
409 "qps", srs, LineString.class); 413 "qps", srs, LineString.class, attrs);
410 414
411 SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft); 415 SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft);
412 FeatureCollection collection = FeatureCollections.newCollection(); 416 FeatureCollection collection = FeatureCollections.newCollection();
413 417
414 int i = 0; 418 int i = 0;
415 for (CrossSectionTrack track: cst) { 419 for (CrossSectionTrack track: cst) {
416 builder.reset(); 420 builder.reset();
417 builder.add(track.getGeom()); 421 builder.add(track.getGeom());
422 builder.add(track.getZ().doubleValue());
423 builder.add(track.getKm().doubleValue());
418 424
419 collection.add(builder.buildFeature(String.valueOf(i++))); 425 collection.add(builder.buildFeature(String.valueOf(i++)));
420 } 426 }
421 427
422 File qpsShape = new File(dir, WSPLGEN_QPS); 428 File qpsShape = new File(dir, WSPLGEN_QPS);
423 429
424 try { 430 try {
425 GeometryUtils.writeShapefile( 431 GeometryUtils.writeShapefile(
426 qpsShape, 432 qpsShape,
427 GeometryUtils.buildFeatureType("qps", srs, LineString.class), 433 GeometryUtils.buildFeatureType(
434 "qps", srs, LineString.class, attrs),
428 collection); 435 collection);
429 job.setPro(qpsShape.getAbsolutePath()); 436 job.setPro(qpsShape.getAbsolutePath());
430 } 437 }
431 catch (MalformedURLException mue) { 438 catch (MalformedURLException mue) {
432 logger.error("Error while writing shapefile: " + mue.getMessage()); 439 logger.error("Error while writing shapefile: " + mue.getMessage());

http://dive4elements.wald.intevation.org