Changeset 553 for trunk


Ignore:
Timestamp:
May 16, 2007, 6:06:55 PM (13 years ago)
Author:
Nick Burch
Message:

Update the export script to handle OSIE as well as OSGB

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

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/perllib/NPEMap/GeoConverter.pm

    r510 r553  
    1414use Geography::NationalGrid;
    1515use Geography::NationalGrid::GB;
     16use Geography::NationalGrid::IE;
    1617
    1718require Exporter;
     
    2021
    2122sub eastingNorthingToLatLong {
    22         my ($e,$n) = @_;
     23        my ($e,$n,$grid) = @_;
    2324
    24         # Turn e+n into OSGB lat+long
    25         my $point = Geography::NationalGrid::GB->new( Easting=>$e, Northing=>$n );
     25        # Turn e+n into OSGB/OSIE lat+long
     26        my $point = getNGPoint($e,$n,$grid);
    2627        my $oslat = $point->latitude;
    2728        my $oslong = $point->longitude;
    2829
    29         # Turn OSGB lat+long into WGS84 lat+long
    30         my $osgb_helper = Geo::HelmertTransform::datum("Airy1830");
     30        # Turn OSGB/OSIE lat+long into WGS84 lat+long
     31        my $datum = getDatum($grid);
     32        my $osgb_helper = Geo::HelmertTransform::datum($datum);
    3133        my $wgs84_helper = Geo::HelmertTransform::datum('WGS84');
    3234
     
    3840
    3941sub eastingNorthingToNGR {
    40         my ($e,$n) = @_;
     42        my ($e,$n,$grid) = @_;
    4143
    4244        # Turn e+n into 2+6 NGR
    43         my $point = Geography::NationalGrid::GB->new( Easting=>$e, Northing=>$n );
     45        my $point = getNGPoint($e,$n,$grid);
    4446        return $point->gridReference(100);
     47}
     48
     49###########################################################################
     50
     51sub getNGPoint {
     52        my ($e,$n,$grid) = @_;
     53        unless($grid) { $grid = "osgb"; }
     54
     55        if($grid eq "osgb") {
     56                return Geography::NationalGrid::GB->new( Easting=>$e, Northing=>$n );
     57        }
     58        if($grid eq "osie") {
     59                return Geography::NationalGrid::IE->new( Easting=>$e, Northing=>$n );
     60        }
     61
     62        warn("Unknown grid '$grid' requested, treating as osgb");
     63        return getNGPoint($e,$n,'osgb');
     64}
     65
     66sub getDatum {
     67        my $grid = shift;
     68        unless($grid) { $grid = "osgb"; }
     69
     70        if($grid eq "osgb") {
     71                return "Airy1830";
     72        }
     73        if($grid eq "osie") {
     74                return "Airy1830Modified";
     75        }
     76
     77        warn("Unknown grid '$grid' requested, treating as osgb");
     78        return getDatum('osgb');
    4579}
    4680
  • trunk/npemap.org.uk/scripts/exporter/export.pl

    r510 r553  
    2121use Geography::NationalGrid;
    2222use Geography::NationalGrid::GB;
     23use Geography::NationalGrid::IE;
    2324
    2425# Find our private perl libraries
     
    5051print "# This information is public domain, and comes from http://www.npemap.org.uk/\n";
    5152print "#\n";
    52 print "# <outward>,<inward>,<easting>,<northing>,<WGS84 lat>,<WGS84 long>,<2+6 NGR>\n";
     53print "# <outward>,<inward>,<easting>,<northing>,<WGS84 lat>,<WGS84 long>,<2+6 NGR>,<grid>\n";
    5354
    5455# Get our data fetch query
     
    5758# Process the query
    5859$query->execute;
    59 while(my ($outer,$inner,$e,$n) = $query->fetchrow_array) {
     60while(my ($outer,$inner,$e,$n,$ie_e,$ie_n) = $query->fetchrow_array) {
     61        # What grid are we on?
     62        my $grid = "osgb";
     63        if(!$e && $ie_e) {
     64                $grid = "osie";
     65                $e = $ie_e;
     66                $n = $ie_n;
     67        }
     68       
    6069        # Generate lat+long
    61         my ($lat,$long) = eastingNorthingToLatLong($e,$n);
     70        my ($lat,$long) = eastingNorthingToLatLong($e,$n,$grid);
    6271        # Generate 2+6 NGR
    63         my $ngr = eastingNorthingToNGR($e,$n);
     72        my $ngr = eastingNorthingToNGR($e,$n,$grid);
    6473
    6574        # Make e+n look nicer
     
    7180        $long = sprintf("%0.6f", $long);
    7281
    73         print "$outer,$inner,$e,$n,$lat,$long,$ngr\n";
     82        print "$outer,$inner,$e,$n,$lat,$long,$ngr,$grid\n";
    7483}
    7584
     
    95104
    96105                my $sql =
    97                         "SELECT outward, inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing ".
     106                        "SELECT outward, inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing, AVG(ie_easting) AS avg_easting_ie, AVG(ie_northing) AS avg_northing_ie ".
    98107                        "FROM postcodes   ".
    99108                        "WHERE source = ? AND NOT deleted ".
     
    106115        } elsif($mode eq "-outer") {
    107116                my $sql =
    108                         "SELECT outward, '###' AS inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing ".
     117                        "SELECT outward, '###' AS inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing, AVG(ie_easting) AS avg_easting_ie, AVG(ie_northing) AS avg_northing_ie ".
    109118                        "FROM postcodes WHERE NOT deleted ".
    110119                        "GROUP BY outward ".
     
    115124        } elsif($mode eq "-outer1") {
    116125                my $sql =
    117                         "SELECT outward, substr(inward,1,1) || '##' AS inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing ".
     126                        "SELECT outward, substr(inward,1,1) || '##' AS inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing, AVG(ie_easting) AS avg_easting_ie, AVG(ie_northing) AS avg_northing_ie ".
    118127                        "FROM postcodes WHERE NOT deleted ".
    119128                        "GROUP BY outward, substr(inward,1,1) ".
Note: See TracChangeset for help on using the changeset viewer.