I'm trying to load an Ordnance Survey GML file into PostGIS using the ST_GeomFromGML function. The problem is that the spatial reference system that is used in the file, osgb:BNG, is not recognized by PostGIS:

# SELECT ST_GeomFromGML('<gml:Point srsName="osgb:BNG">
ERROR:  unknown spatial reference system

Does "osgb:BNG" have an alternative name that is recognized by PostGIS?

I ended up replacing "osgb:BNG" with "EPSG:27700" in the GML file (in the srsName parameter), although the other two options (modifying the spatial_ref_sys table, or using the ST_GeomFromGML function http://postgis.net/docs/ST_GeomFromGML.html with two arguments for PostGIS 2.0+) are perfectly valid too.


2 Answers 2


You can add this projection to the projection table postgis uses and then refer to it with the new name (97460 or SR-ORG:7460 in this case):

INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) values ( 97460, 'sr-org', 7460, '+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 ', 'PROJCS["OSGB 1936 / British National Grid",GEOGCS["OSGB 1936",DATUM["OSGB_1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[375,-111,431,0,0,0,0],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4277"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","27700"]]');

But ouch, what's all this code? I used gdalsrsinfo to get the details of the projection and http://spatialreference.org/ref/sr-org/7460/ to generate the full INSERT command for updating the spatial_ref_sys table. It could be done manually, but this way other people searching for it will be able to skip a step — it didn't include any synonims for this projection either.

  • Thanks for the quick answer! What if I simply replaced "osgb:BNG" with "EPSG:27700" http://spatialreference.org/ref/epsg/27700/ in the GML file? Would that work too? Commented Jul 22, 2012 at 16:00
  • yes, they are practically identical (last digit rounding error and no TOWGS84 tag). Commented Jul 22, 2012 at 16:05

No need to insert anything special into the spatial_ref_sys table as it already contains the necessary entry for British National Grid. The British National Grid can be referenced using the EPSG code 27700 and I think the srid value in spatial_ref_sys table is the same. So, all you need to do is use the second form of the method and specify the correct srid to use:

geometry ST_GeomFromGML(text geomgml, integer srid)

So, replace text geomgml with the GML data you are getting the geometry from and integer srid with 27700. That should then work for you.

  • I'm getting an error: SELECT ST_GeomFromGML('<gml:Point srsName="osgb:BNG"><gml:coordinates>527347.0,181346.0</gml:coordinates></gml:Point>', 27700); ERROR: function st_geomfromgml(unknown, integer) does not exist LINE 1: SELECT ST_GeomFromGML('<gml:Point srsName><gml:coordinates>5... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. Any ideas? Commented Jul 22, 2012 at 16:12
  • You need at least postgis 2.0 for this to work, the parameter was not available earlier. Instead just change the srsName parameter in the GML. Commented Jul 22, 2012 at 16:14
  • Cool, thanks, I have PostGIS 1.5.3 installed at the moment. Commented Jul 22, 2012 at 16:16
  • Didn't realise that was only available in 2.0! But there is still no need to add the reference as 27700 srid exists in PostGIS 1.5.3.
    – CHenderson
    Commented Jul 22, 2012 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.