Changeset 461 for trunk/npemap.org.uk


Ignore:
Timestamp:
Feb 7, 2007, 4:08:30 PM (14 years ago)
Author:
Nick Burch
Message:

Pull out e+n -> lat+long into a npemap perl module, and use from the geocoder

Location:
trunk/npemap.org.uk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/geocoder.fcgi

    r460 r461  
    2323use lib "$FindBin::Bin/../perllib";
    2424use NPEMap;
    25 use Geo::HelmertTransform;
     25use NPEMap::GeoConverter;
    2626
    2727sub print_err;
     
    185185        }
    186186
     187        # Generate the lat and long, if we had easting and northings
     188        foreach my $res (@results) {
     189                if($res->{easting} && $res->{northing}) {
     190                        ($res->{lat},$res->{long}) =
     191                                eastingNorthingToLatLong($res->{easting},$res->{northing});
     192                }       
     193        }
    187194
    188195        # Render
     
    209216                        print "    <northing>".$res->{inorthing}."</northing>\n";
    210217                        print "    <postcode>$res->{postcode}</postcode>\n";
     218                        print "     <latitude>$res->{lat}</latitude>\n";
     219                        print "     <longitude>$res->{long}</longitude>\n";
    211220                        if(scalar @results > 1) {
    212221                                print "  </result>\n";
     
    225234                #  (need to do some array magic probably)
    226235                foreach my $res (@results) {
    227                         print "{ pc: \"$res->{postcode}\", e: $res->{ieasting}, n: $res->{inorthing} }";
     236                        print "{ \"pc\": \"$res->{postcode}\", \"e\": $res->{ieasting}, \"n\": $res->{inorthing}, \"lat\": $res->{lat}, \"lng\": $res->{long} }";
    228237                }
    229238                if(defined $cgi->param("callback")) {
     
    233242    } else {
    234243                print header("text/plain");
    235                 print "# Easting,Northing,Matched Postcode\n";
     244                print "# Easting,Northing,Matched Postcode,Latitude,Longitude\n";
    236245
    237246                foreach my $res (@results) {
    238                         print $res->{ieasting}.",".$res->{inorthing}.",'".$res->{postcode}."'\n";
     247                        print $res->{ieasting}.",".$res->{inorthing}.",'".$res->{postcode}."',".$res->{lat}.",".$res->{long}."\n";
    239248                }
    240249        }
  • trunk/npemap.org.uk/scripts/exporter/export.pl

    r460 r461  
    2525use FindBin;
    2626use lib "$FindBin::Bin/../../perllib";
    27 use Geo::HelmertTransform;
     27use NPEMap::GeoConverter;
    2828
    2929my $mode = shift;
     
    5959while(my ($outer,$inner,$e,$n) = $query->fetchrow_array) {
    6060        # Generate lat+long
    61         my ($lat,$long) = makeLatLong($e,$n);
     61        my ($lat,$long) = eastingNorthingToLatLong($e,$n);
    6262
    6363        # Make e+n look nicer
     
    7575$conn->disconnect;
    7676
    77 
    78 ############################################################################
    79 
    80 sub makeLatLong {
    81         my ($e,$n) = @_;
    82 
    83         # Turn e+n into OSGB lat+long
    84         my $point = Geography::NationalGrid::GB->new( Easting=>$e, Northing=>$n );
    85         my $oslat = $point->latitude;
    86         my $oslong = $point->longitude;
    87 
    88         # Turn OSGB lat+long into WGS84 lat+long
    89         my $osgb_helper = Geo::HelmertTransform::datum("Airy1830");
    90         my $wgs84_helper = Geo::HelmertTransform::datum('WGS84');
    91 
    92         my ($lat,$long,$h) =
    93                 Geo::HelmertTransform::convert_datum($osgb_helper, $wgs84_helper, $oslat, $oslong, 0);
    94 
    95         return ($lat,$long);
    96 }
    9777
    9878############################################################################
Note: See TracChangeset for help on using the changeset viewer.