Search code examples
geospatialwms

How to convert latitude/longitude in degrees to BBOX where SRS=EPSG:27700


Anyone know how to convert latitude, longitude in degrees to define a BBOX where SRS=EPSG:27700?

I am trying to call a WMS service with a URL like following (not a real link): http://mysecretmappingserver.com/wms?user=myuser&pwd=mypassword&VERSION=1.1.1&REQUEST=GetMap&LAYERS=ap25cm&STYLES=&SRS=EPSG:27700&BBOX=229096,231675,229296,231875&width=400&height=400

Any language would be fine; C# preferable.

Spacedman has been trying to help me, but I can't seem to get Proj4Net to work for me - all me, I'm sure - but if someone knows either Proj4Net or the math involved, that might be better...


Solution

  • You need an interface to the PROJ.4 projections library in your language of choice. In R, for example, its in the rgdal package:

    Here's some points (1,1 to 2,2 degrees) in epsg:4326:

    > pts
    SpatialPoints:
         coords.x1 coords.x2
    [1,]         1         1
    [2,]         2         2
    Coordinate Reference System (CRS) arguments: +init=epsg:4326 
    

    and voila:

    > spTransform(pts,CRS("+init=epsg:27700"))
    SpatialPoints:
         coords.x1 coords.x2
    [1,]  734005.9  -5416918
    [2,]  845270.7  -5305999
    Coordinate Reference System (CRS) arguments: +init=epsg:27700
    

    Proj.4 docs here:

    http://trac.osgeo.org/proj/

    Since this is OSGB, probably a better example would be in the UK: here's a point in central london:

    > pts = SpatialPoints(cbind(-0.109863,51.460852),proj4string=CRS("+init=epsg:4326"))
    > spTransform(pts,CRS("+init=epsg:27700"))SpatialPoints:
         coords.x1 coords.x2
    [1,]  531407.1  175235.8
    Coordinate Reference System (CRS) arguments: +init=epsg:27700
    +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000
    +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs
    +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894