Mercurial > dive4elements > river
changeset 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 (2011-09-01) |
parents | 7398280b11a0 |
children | fb3947027e92 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java |
diffstat | 3 files changed, 44 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Aug 31 13:19:29 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Sep 01 07:04:01 2011 +0000 @@ -1,3 +1,12 @@ +2011-09-01 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/utils/GeometryUtils.java: New static + function that builds new SimpleFeatureTypes with additional attributes. + + * src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java: + Write attributes "ELEVATION" and "KILOMETER" into the crosssection + tracks shapefiles. + 2011-08-31 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/utils/FLYSUtils.java: Added a method
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Wed Aug 31 13:19:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Thu Sep 01 07:04:01 2011 +0000 @@ -335,7 +335,7 @@ FeatureCollection polygons = FeatureCollections.newCollection(); for (SimpleFeature feature: f) { - Object geom = feature.getDefaultGeometry(); + Geometry geom = (Geometry) feature.getDefaultGeometry(); if (geom instanceof LineString) { lines.add(feature); @@ -405,8 +405,12 @@ logger.debug("Found " + cst.size() + " CrossSectionTracks."); + Object[][] attrs = new Object[2][]; + attrs[0] = new Object[] { "ELEVATION", Double.class }; + attrs[1] = new Object[] { "KILOMETER", Double.class }; + SimpleFeatureType ft = GeometryUtils.buildFeatureType( - "qps", srs, LineString.class); + "qps", srs, LineString.class, attrs); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft); FeatureCollection collection = FeatureCollections.newCollection(); @@ -415,6 +419,8 @@ for (CrossSectionTrack track: cst) { builder.reset(); builder.add(track.getGeom()); + builder.add(track.getZ().doubleValue()); + builder.add(track.getKm().doubleValue()); collection.add(builder.buildFeature(String.valueOf(i++))); } @@ -424,7 +430,8 @@ try { GeometryUtils.writeShapefile( qpsShape, - GeometryUtils.buildFeatureType("qps", srs, LineString.class), + GeometryUtils.buildFeatureType( + "qps", srs, LineString.class, attrs), collection); job.setPro(qpsShape.getAbsolutePath()); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java Wed Aug 31 13:19:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java Thu Sep 01 07:04:01 2011 +0000 @@ -59,6 +59,25 @@ public static SimpleFeatureType buildFeatureType( String name, String srs, Class geometryType) { + return buildFeatureType(name, srs, geometryType, null); + } + + + /** + * Creates a new SimpleFeatureType using a SimpleFeatureTypeBuilder. + * + * @param name The name of the FeatureType. + * @param srs The SRS (e.g. "EPSG:31466"). + * @param geometryType The geometry type's class (e.g. Polygon.class). + * @param attrs Optional. An object with attribute-name/attribute-class + * pairs where index 0 specifies the name as string and index 1 the type + * as class. + * + * @return a new SimpleFeatureType. + */ + public static SimpleFeatureType buildFeatureType( + String name, String srs, Class geometryType, Object[][] attrs) + { try { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); CoordinateReferenceSystem crs = CRS.decode(srs); @@ -70,6 +89,12 @@ builder.add("geometry", geometryType, crs); + if (attrs != null) { + for (Object[] attr: attrs) { + builder.add((String) attr[0], (Class) attr[1]); + } + } + return builder.buildFeatureType(); } catch (NoSuchAuthorityCodeException nsae) {