Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java @ 440:eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
gnv-artifacts/trunk@488 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 28 Dec 2009 17:13:12 +0000 |
parents | 8975de9d7483 |
children | da21c256a0ba |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java Mon Dec 28 16:24:05 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java Mon Dec 28 17:13:12 2009 +0000 @@ -12,8 +12,6 @@ import org.apache.log4j.Logger; import org.w3c.dom.Node; -import com.vividsolutions.jts.io.ParseException; - import de.intevation.artifactdatabase.Config; import de.intevation.gnv.artifacts.cache.CacheFactory; @@ -32,6 +30,8 @@ import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.HorizontalCrossProfileChart; +import de.intevation.gnv.state.InputData; + import de.intevation.gnv.utils.DistanceCalculator; import de.intevation.gnv.utils.WKTUtils; import de.intevation.gnv.utils.StringUtils; @@ -41,8 +41,6 @@ import org.jfree.chart.ChartTheme; import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.io.WKTReader; /** * @author Tim Englich <tim.englich@intevation.de> @@ -141,48 +139,50 @@ result = (Collection<Result>) (value.getObjectValue()); }else{ - if (this.inputData.containsKey("mesh_linestring")){ - - try { - LineString ls = (LineString)new WKTReader().read( - inputData.get("mesh_linestring").getValue()); - - Coordinate[] coords = ls.getCoordinates(); - - String additionWhere = - WKTUtils.worldCoordinatesToIndex( - result, - inputData, - ijkQueryID - ); + InputData meshLine = inputData.get("mesh_linestring"); + InputData meshId = inputData.get("meshid"); - String[] filterValues = - generateFilterValuesFromInputData(); - String[] addedFilterValues = - new String[filterValues.length+1]; - System.arraycopy( - filterValues, 0, - addedFilterValues, 0, - filterValues.length); - addedFilterValues[filterValues.length] = additionWhere; + if (meshLine == null) { + log.error("mesh_linestring is not defined"); + throw new IllegalStateException("missing mesh_linestring"); + } - QueryExecutor queryExecutor = QueryExecutorFactory - .getInstance() - .getQueryExecutor(); + if (meshId == null) { + log.error("meshid is not defined"); + throw new IllegalStateException("missing meshid"); + } - result = process( - Arrays.asList(coords), - queryExecutor.executeQuery( - queryID, - addedFilterValues) - ); - } catch (ParseException e) { - log.error(e,e); - }catch (QueryException e) { - log.error(e,e); - } - }else{ - // TODO: definieren was passiert wenn kein linestring vorhanden ist. + Coordinate [] coords = WKTUtils.toCoordinates( + meshLine.getValue()); + + if (coords == null) { + throw new IllegalStateException("cannot read coordinates"); + } + + try { + String additionWhere = + WKTUtils.worldCoordinatesToIndex( + coords, + result, + meshId.getValue(), + ijkQueryID); + + String[] addedFilterValues = StringUtils.append( + generateFilterValuesFromInputData(), + additionWhere); + + QueryExecutor queryExecutor = QueryExecutorFactory + .getInstance() + .getQueryExecutor(); + + result = process( + Arrays.asList(coords), + queryExecutor.executeQuery( + queryID, + addedFilterValues)); + } + catch (QueryException e) { + log.error(e,e); } if (CacheFactory.getInstance().isInitialized()) {