Mercurial > dive4elements > gnv-client
changeset 507:45be952a3215
Solved some issues. Removed encoding problems while formatting coordinates (issue137) and use this format as subtitle in charts (issue136).
gnv-artifacts/trunk@590 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 21 Jan 2010 14:42:51 +0000 (2010-01-21) |
parents | d41c155db337 |
children | 90f03b909bb0 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java gnv-artifacts/src/main/resources/lang/artifactMessages.properties gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties |
diffstat | 8 files changed, 117 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/ChangeLog Thu Jan 21 14:42:51 2010 +0000 @@ -1,3 +1,24 @@ +2010-01-21 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue136 & Issue137 + + * src/main/resources/lang/artifactMessages.properties, + src/main/resources/lang/artifactMessages_de_DE.properties, + src/main/resources/lang/artifactMessages_en.properties, + src/main/resources/lang/artifactMessages_de.properties: Added templates + to format coordinates to a human readable output. + + * src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java, + src/main/java/de/intevation/gnv/utils/WKTUtils.java: Moved function to + format coordinates from wkt string to human readalbe output to WKTUtils. + Modified the method: Read template out of the i18n files and use a Java + MessageFormatter to fill this template with string objects. A result of + this is a proper encoding (issue137). + + * src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java: + Use the method described above to format coordinate output and display + this as chart subtitle (issue136). + 2010-01-21 Ingo Weinzierl <ingo.weinzierl@intevation.de> Issue100
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java Thu Jan 21 14:42:51 2010 +0000 @@ -20,6 +20,7 @@ import de.intevation.gnv.state.describedata.NamedArrayList; import de.intevation.gnv.state.describedata.NamedCollection; import de.intevation.gnv.utils.InputValidator; +import de.intevation.gnv.utils.WKTUtils; import de.intevation.gnv.utils.exception.ValidationException; /** @@ -118,22 +119,7 @@ return keyValueDescibeData; } - protected String convert2DisplayCoordinate(String wkt){ - String formattedCoordinate = null; - try { - Point p = (Point)new WKTReader().read(wkt); - double lat = p.getY(); - double lon =p.getX(); - String nord="N"; - String ost="E"; - if (lat <0 ){nord="S"; lat=-lat;} - if (lon <0 ){ost="W"; lon=-lon;} - formattedCoordinate = String.format("%1$02d°%2$1S %3$05.2f' %4$03d°%5$1S %6$05.2f'", - (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon))); - } catch (ParseException e) { - log.error(e,e); - } - - return formattedCoordinate; + protected static String convert2DisplayCoordinate(String wkt){ + return WKTUtils.toText(wkt); } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java Thu Jan 21 14:42:51 2010 +0000 @@ -35,6 +35,7 @@ import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; import de.intevation.gnv.statistics.HorizontalProfileStatistics; import de.intevation.gnv.statistics.Statistics; +import de.intevation.gnv.utils.WKTUtils; /** * @author Tim Englich <tim.englich@intevation.de> @@ -255,16 +256,11 @@ if (qry.equals("SHAPE")) { try { - Point p = (Point) wktReader.read(result.getString(qry)); + String wktPoint = result.getString(qry); meta.append(getMessage(locale,"coordinate","coordinate")); meta.append(": "); - - log.debug( - "Add " + qry + " to meta information of subtitle: " - + p.toString() - ); - meta.append(p.getX() + ", " + p.getY()); + meta.append(WKTUtils.toText(wktPoint)); } catch (ParseException pe) { log.warn("Error while parsing point.", pe);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java Thu Jan 21 14:42:51 2010 +0000 @@ -12,12 +12,16 @@ import de.intevation.gnv.geobackend.base.query.QueryExecutor; import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; import de.intevation.gnv.geobackend.base.query.exception.QueryException; +import de.intevation.gnv.artifacts.ressource.RessourceFactory; import de.intevation.gnv.math.LinearFunction; +import java.text.MessageFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.fitting.CurveFitter; @@ -38,6 +42,16 @@ public static final String TRUE_EXPRESSION = "FEATUREID=FEATUREID"; + public static final String[] COORDINATE_OUT_FORMAT = { + "coordinate.template.northeast", + "coordinate.template.southeast", + "coordinate.template.northwest", + "coordinate.template.southwest" + }; + + public static final String DEFAULT_COORDINATE_TEMPLATE = + "{0}\u00b0N {1}'' {2}\u00b0E {3}''"; + public static boolean different(Result a, Result b, int [] indices) { for (int i = 0; i < indices.length; ++i) { String oa = a.getString(indices[i]); @@ -338,4 +352,64 @@ } return null; } + + public static String toText(String wkt) { + return toText(Locale.getDefault(), wkt); + } + + public static String toText(Locale locale, String wkt) { + String formattedCoordinate = null; + try { + Point p = (Point)new WKTReader().read(wkt); + double lat = p.getY(); + double lon =p.getX(); + + int choice = 0; + + if (lat <0 ) { + choice += 1; + lat=-lat; + } + + if (lon <0 ) { + choice += 2; + lon=-lon; + } + + RessourceFactory factory = RessourceFactory.getInstance(); + String template = factory.getRessource( + locale, + COORDINATE_OUT_FORMAT[choice], + DEFAULT_COORDINATE_TEMPLATE + ); + + NumberFormat minFormatter = NumberFormat.getInstance(locale); + minFormatter.setMaximumFractionDigits(3); + minFormatter.setMinimumFractionDigits(3); + + String minLat = minFormatter.format(60.*(lat-((int)lat))); + String minLon = minFormatter.format(60.*(lon-((int)lon))); + + NumberFormat degFormatter = NumberFormat.getInstance(locale); + degFormatter.setMinimumIntegerDigits(2); + + String formLat = degFormatter.format((int)lat); + String formLon = degFormatter.format((int)lon); + + MessageFormat formatter = new MessageFormat(template); + + Object[] args = { + formLat, minLat, + formLon, minLon + }; + + return formatter.format(args); + + } + catch (ParseException e) { + log.warn(e,e); + } + + return null; + } }
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages.properties Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages.properties Thu Jan 21 14:42:51 2010 +0000 @@ -53,6 +53,10 @@ subareaid=Subarea depth=depth coordinate=coordinate +coordinate.template.northeast={0}\u00b0N {1}'' {2}\u00b0E {3}'' +coordinate.template.southeast={0}\u00b0S {1}'' {2}\u00b0E {3}'' +coordinate.template.northwest={0}\u00b0N {1}'' {2}\u00b0W {3}'' +coordinate.template.southwest={0}\u00b0S {1}'' {2}\u00b0W {3}'' chart.timeseries.date.format=yyyy-MMM-dd chart.timeseries.title.xaxis=Time [UTC]
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties Thu Jan 21 14:42:51 2010 +0000 @@ -53,6 +53,10 @@ subareaid=Teilgebiet depth=Tiefe coordinate=Koordinate +coordinate.template.northeast={0}\u00b0N {1}'' {2}\u00b0O {3}'' +coordinate.template.southeast={0}\u00b0S {1}'' {2}\u00b0O {3}'' +coordinate.template.northwest={0}\u00b0N {1}'' {2}\u00b0W {3}'' +coordinate.template.southwest={0}\u00b0S {1}'' {2}\u00b0W {3}'' chart.timeseries.date.format=dd-MMM-yyyy chart.timeseries.title.xaxis=Zeit [UTC]
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties Thu Jan 21 14:42:51 2010 +0000 @@ -53,6 +53,10 @@ subareaid=Teilgebiet depth=Tiefe coordinate=Koordinate +coordinate.template.northeast={0}\u00b0N {1}'' {2}\u00b0O {3}'' +coordinate.template.southeast={0}\u00b0S {1}'' {2}\u00b0O {3}'' +coordinate.template.northwest={0}\u00b0N {1}'' {2}\u00b0W {3}'' +coordinate.template.southwest={0}\u00b0S {1}'' {2}\u00b0W {3}'' chart.timeseries.date.format=dd-MMM-yyyy chart.timeseries.title.xaxis=Zeit [UTC]
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties Thu Jan 21 10:09:01 2010 +0000 +++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties Thu Jan 21 14:42:51 2010 +0000 @@ -53,6 +53,10 @@ subareaid=Subarea depth=depth coordinate=coordinate +coordinate.template.northeast={0}\u00b0N {1}'' {2}\u00b0E {3}'' +coordinate.template.southeast={0}\u00b0S {1}'' {2}\u00b0E {3}'' +coordinate.template.northwest={0}\u00b0N {1}'' {2}\u00b0W {3}'' +coordinate.template.southwest={0}\u00b0S {1}'' {2}\u00b0W {3}'' chart.timeseries.date.format=yyyy-MMM-dd