- Timestamp:
- May 16, 2007, 6:06:55 PM (13 years ago)
- Location:
- trunk/npemap.org.uk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/npemap.org.uk/perllib/NPEMap/GeoConverter.pm
r510 r553 14 14 use Geography::NationalGrid; 15 15 use Geography::NationalGrid::GB; 16 use Geography::NationalGrid::IE; 16 17 17 18 require Exporter; … … 20 21 21 22 sub eastingNorthingToLatLong { 22 my ($e,$n ) = @_;23 my ($e,$n,$grid) = @_; 23 24 24 # Turn e+n into OSGB lat+long25 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); 26 27 my $oslat = $point->latitude; 27 28 my $oslong = $point->longitude; 28 29 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); 31 33 my $wgs84_helper = Geo::HelmertTransform::datum('WGS84'); 32 34 … … 38 40 39 41 sub eastingNorthingToNGR { 40 my ($e,$n ) = @_;42 my ($e,$n,$grid) = @_; 41 43 42 44 # 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); 44 46 return $point->gridReference(100); 47 } 48 49 ########################################################################### 50 51 sub 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 66 sub 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'); 45 79 } 46 80 -
trunk/npemap.org.uk/scripts/exporter/export.pl
r510 r553 21 21 use Geography::NationalGrid; 22 22 use Geography::NationalGrid::GB; 23 use Geography::NationalGrid::IE; 23 24 24 25 # Find our private perl libraries … … 50 51 print "# This information is public domain, and comes from http://www.npemap.org.uk/\n"; 51 52 print "#\n"; 52 print "# <outward>,<inward>,<easting>,<northing>,<WGS84 lat>,<WGS84 long>,<2+6 NGR> \n";53 print "# <outward>,<inward>,<easting>,<northing>,<WGS84 lat>,<WGS84 long>,<2+6 NGR>,<grid>\n"; 53 54 54 55 # Get our data fetch query … … 57 58 # Process the query 58 59 $query->execute; 59 while(my ($outer,$inner,$e,$n) = $query->fetchrow_array) { 60 while(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 60 69 # Generate lat+long 61 my ($lat,$long) = eastingNorthingToLatLong($e,$n );70 my ($lat,$long) = eastingNorthingToLatLong($e,$n,$grid); 62 71 # Generate 2+6 NGR 63 my $ngr = eastingNorthingToNGR($e,$n );72 my $ngr = eastingNorthingToNGR($e,$n,$grid); 64 73 65 74 # Make e+n look nicer … … 71 80 $long = sprintf("%0.6f", $long); 72 81 73 print "$outer,$inner,$e,$n,$lat,$long,$ngr \n";82 print "$outer,$inner,$e,$n,$lat,$long,$ngr,$grid\n"; 74 83 } 75 84 … … 95 104 96 105 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 ". 98 107 "FROM postcodes ". 99 108 "WHERE source = ? AND NOT deleted ". … … 106 115 } elsif($mode eq "-outer") { 107 116 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 ". 109 118 "FROM postcodes WHERE NOT deleted ". 110 119 "GROUP BY outward ". … … 115 124 } elsif($mode eq "-outer1") { 116 125 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 ". 118 127 "FROM postcodes WHERE NOT deleted ". 119 128 "GROUP BY outward, substr(inward,1,1) ".
Note: See TracChangeset
for help on using the changeset viewer.