# HG changeset patch # User Ingo Weinzierl # Date 1314879803 0 # Node ID be9bb260b835fca6226998c1971023fd84f99911 # Parent 111794adf2851855ecfae6dc6cc0eeefca1bf260 Set the Z values of line and polygon barrier geometries used for WSPLGEN. flys-artifacts/trunk@2632 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 111794adf285 -r be9bb260b835 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Sep 01 12:15:46 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Sep 01 12:23:23 2011 +0000 @@ -1,3 +1,9 @@ +2011-09-01 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java: + Set the Z values of line and polygon barrier geometries. Both barrier + shapefiles will contain 3D geometries now. + 2011-08-31 Felix Wolfsteller Get real data to display in CrossSection (although ignorant of diff -r 111794adf285 -r be9bb260b835 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Thu Sep 01 12:15:46 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java Thu Sep 01 12:23:23 2011 +0000 @@ -4,10 +4,12 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import javax.xml.xpath.XPathConstants; +import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.MultiPolygon; @@ -288,7 +290,10 @@ String srid = FLYSUtils.getRiverSrid(artifact); String srs = "EPSG:" + srid; - List features = getBarriersFeatures(geoJSON, srs); + SimpleFeatureType ft = getBarriersFeatureType( + "barriers", srs, Geometry.class); + + List features = GeometryUtils.parseGeoJSON(geoJSON, ft); if (features == null || features.size() == 0) { logger.debug("No barrier features extracted."); return; @@ -305,6 +310,9 @@ fcs[0]); if (l) { + logger.debug( + "Successfully created barrier line shapefile. " + + "Write shapefile path into WSPLGEN job."); job.addLin(shapeLines.getAbsolutePath()); } @@ -314,16 +322,24 @@ fcs[1]); if (p) { + logger.debug( + "Successfully created barrier polygon shapefile. " + + "Write shapefile path into WSPLGEN job."); job.addLin(shapePolys.getAbsolutePath()); } } - protected List getBarriersFeatures(String json, String srs) { - SimpleFeatureType ft = GeometryUtils.buildFeatureType( - "barriers", srs,Geometry.class); + protected SimpleFeatureType getBarriersFeatureType( + String name, + String srs, + Class type + ) { + Object[][] attrs = new Object[2][]; + attrs[0] = new Object[] { "typ", String.class }; + attrs[1] = new Object[] { "elevation", Double.class }; - return GeometryUtils.parseGeoJSON(json, ft); + return GeometryUtils.buildFeatureType(name, srs, type, attrs); } @@ -334,10 +350,13 @@ for (SimpleFeature feature: f) { Geometry geom = (Geometry) feature.getDefaultGeometry(); + if (geom instanceof LineString) { + geom = applyElevationAttribute(feature, (LineString) geom); lines.add(feature); } else if (geom instanceof Polygon) { + geom = applyElevationAttribute(feature, (Polygon) geom); polygons.add(feature); } else { @@ -352,6 +371,68 @@ } + protected static Geometry applyElevationAttribute( + SimpleFeature feature, + Geometry geom + ) { + logger.debug("Apply elevations for: " + geom.getClass()); + + List elevations = extractElevations(feature); + int numPoints = geom.getNumPoints(); + int numElevation = elevations.size(); + + String typ = (String) feature.getAttribute("typ"); + + if (numPoints > numElevation) { + logger.warn("More vertices in Geometry than elevations given."); + } + + Coordinate[] c = geom.getCoordinates(); + for (int i = 0; i < numPoints; i++) { + if (i < numElevation) { + c[i].z = elevations.get(i); + } + else if (typ != null && typ.equals("Graben")) { + c[i].z = -9999d; + } + else { + c[i].z = 9999d; + } + } + + return geom; + } + + + protected static List extractElevations(SimpleFeature feature) { + String tmp = (String) feature.getAttribute("elevation"); + String typ = (String) feature.getAttribute("typ"); + + String[] elevations = tmp == null ? null : tmp.split(" "); + + int num = elevations != null ? elevations.length : 0; + + List list = new ArrayList(num); + + for (int i = 0; i < num; i++) { + try { + list.add(Double.parseDouble(elevations[i])); + } + catch (NumberFormatException nfe) { + logger.warn("Error while parsing elevation at pos: " + i); + if (typ != null && typ.equals("Graben")) { + list.add(new Double(-9999.0)); + } + else { + list.add(new Double(9999.0)); + } + } + } + + return list; + } + + protected void setAxis(FLYSArtifact artifact, File dir, WSPLGENJob job) { String river = artifact.getDataAsString("river"); String srid = FLYSUtils.getRiverSrid(artifact);