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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.