hope you are well
I am trying to convert lat/long coordinates to OSGB36 x and y using the proj.4 library.
Has anyone else successfully done this? I need to f
EPSG:27700 on spatialreference.org gives various strings for defining this, including one for proj4.
Here is example code in ruby using the proj4 bindings :
#!/usr/bin/ruby
require 'rubygems'
require 'proj4'
#Some example WGS84 lat lon coordinates to convert:
lon = -0.10322
lat = 51.52237
srcPoint = Proj4::Point.new(Math::PI * lon.to_f / 180,
Math::PI * lat.to_f / 180)
srcPrj = Proj4::Projection.new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
destPrj = Proj4::Projection.new("+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 +units=m +no_defs <>")
point = srcPrj.transform(destPrj, srcPoint)
puts "http://www.openstreetmap.org/?mlat=" + lat.to_s + "&mlon=" + lon.to_s + "&zoom=16"
puts "Converts to:";
puts "http://streetmap.co.uk/grid/" + point.x.round.to_s + "_" + point.y.round.to_s + "_106"
The output:
http://www.openstreetmap.org/?mlat=51.52237&mlon=-0.10322&zoom=16
Converts to:
http://streetmap.co.uk/grid/531691_182089_106
So this is working accurately now. Originally I was trying just the 'destPrj' string, and calling the 'forward' method, but this refused to do the datum conversion, resulting everything being 100m out. It seemed to be necessary to use the 'srcPrj' string and the 'transform' method, to get the datum conversion happening.
See also my blog post: Ruby code for converting to UK Ordnance Survey coordinate systems from WGS84? which includes a pure ruby version (not proj4) for doing the same