[NUUG fiksgatami] Decimal point separator
Matthew Somerville
matthew at mysociety.org
Sat Feb 14 22:43:25 CET 2009
Petter Reinholdtsen wrote:
> I had a few more changes, which I am not sure still make sense, but
> thought it best to show to you for comments.
I don't think the change to fetch_problem should be needed, given the
only variable involved is $id which is an integer. Perhaps it was to try
and get the easting and northing data at that point with "." instead of
"," perhaps? I think it's best for the locale to be set at time of use,
not time of creation, then it's clearer what's going on. Certainly, in
PHP, floats don't care about their decimal separator internally until
they are output.
I don't want to taint GeoUtil with Locale stuff, no - whatever at the
higher level calling GeoUtil should be responsible for that (as I think
one of my commits did for one location). Of course, you don't need
GeoUtil as you won't be using easting/northings! :)
Another volunteer has suggested some code for doing this en-gb push/pop
wherever it's needed which is clearer, so I'll try and commit that at
some point.
> I had to change these blocks as well to get things working for me. I
> have not tested if they are still required to get it working.
Okay. :)
ATB,
Matthew
> Index: bci/perllib/Problems.pm
> ===================================================================
> RCS file: /repos/mysociety/bci/perllib/Problems.pm,v
> retrieving revision 1.10
> diff -u -3 -p -r1.10 Problems.pm
> --- bci/perllib/Problems.pm 14 Feb 2009 11:30:49 -0000 1.10
> +++ bci/perllib/Problems.pm 14 Feb 2009 21:19:42 -0000
> @@ -173,7 +173,8 @@ sub fixed_nearby {
>
> sub fetch_problem {
> my $id = shift;
> - dbh()->selectrow_hashref(
> + mySociety::Locale::push('en-gb');
> + my $retval = dbh()->selectrow_hashref(
> "select id, easting, northing, council, category, title, detail, (photo is not null) as photo,
> used_map, name, anonymous, extract(epoch from confirmed) as time,
> state, extract(epoch from whensent-confirmed) as whensent,
> @@ -181,6 +182,8 @@ sub fetch_problem {
> from problem where id=? and state in ('confirmed','fixed', 'hidden')
> $site_restriction", {}, $id
> );
> + mySociety::Locale::pop();
> + return $retval;
> }
>
> 1;
> Index: perllib/mySociety/GeoUtil.pm
> ===================================================================
> RCS file: /repos/mysociety/perllib/mySociety/GeoUtil.pm,v
> retrieving revision 1.6
> diff -u -3 -p -r1.6 GeoUtil.pm
> --- perllib/mySociety/GeoUtil.pm 26 Jan 2009 14:21:52 -0000 1.6
> +++ perllib/mySociety/GeoUtil.pm 14 Feb 2009 21:19:43 -0000
> @@ -32,6 +32,7 @@ Northern Ireland. The latitude and long
> sub national_grid_to_wgs84($$$) {
> my ($easting, $northing, $coordsyst) = @_;
>
> + mySociety::Locale::push('en-gb');
> our ($wgs84, $airy1830, $airy1830m);
> $wgs84 ||= Geo::HelmertTransform::datum("WGS84");
> $airy1830 ||= Geo::HelmertTransform::datum("Airy1830");
> @@ -52,7 +53,9 @@ sub national_grid_to_wgs84($$$) {
> } else {
> die "bad value '$coordsyst' for coordinate system in nationalgrid_to_wgs84";
> }
> - return Geo::HelmertTransform::convert_datum($d, $wgs84, $lat, $lon, 0); # 0 is altitude
> + my @ret = Geo::HelmertTransform::convert_datum($d, $wgs84, $lat, $lon, 0); # 0 is altitude
> + mySociety::Locale::pop();
> + return @ret;
> }
>
> =item wgs84_to_national_grid LATITUDE LONGITUDE COORDSYST
> @@ -64,6 +67,7 @@ Northern Ireland. The easting and north
> sub wgs84_to_national_grid($$$) {
> my ($lat, $lon, $coordsyst) = @_;
>
> + mySociety::Locale::push('en-gb');
> our ($wgs84, $airy1830, $airy1830m);
> $wgs84 ||= Geo::HelmertTransform::datum("WGS84");
> $airy1830 ||= Geo::HelmertTransform::datum("Airy1830");
> @@ -89,6 +93,8 @@ sub wgs84_to_national_grid($$$) {
> } else {
> die "bad value '$coordsyst' for coordinate system in nationalgrid_to_wgs84";
> }
> + mySociety::Locale::pop();
> + print STDERR "Geo: ", $p->easting,",", $p->northing, "\n";
> return ($p->easting, $p->northing);
> }
>
More information about the fiksgatami
mailing list