Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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">
         <gml:coordinates>527347.0,181346.0</gml:coordinates></gml:Point>');
ERROR:  unknown spatial reference system

Is there any workaround? Does "osgb:BNG" have an alternative name that is recognized by PostGIS? Thank you.


EDIT: Thanks to everybody for their answers. 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.

share|improve this question
    
The code block isn't displayed correctly: # SELECT ST_GeomFromGML('<gml:Point srsName="osgb:BNG"><gml:coordinates>527347.0,181346.0</gml:coordinates></gml:Poi‌​nt>'); ERROR: unknown spatial reference system –  Orestis Tsinalis Jul 22 '12 at 14:50
    
add another space before it, so it will get converted to a code block. Now the site thinks you are including html and strips the gml tags. –  lynxlynxlynx Jul 22 '12 at 15:25
add comment

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
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? –  Orestis Tsinalis Jul 22 '12 at 16:00
    
yes, they are practically identical (last digit rounding error and no TOWGS84 tag). –  lynxlynxlynx Jul 22 '12 at 16:05
    
Many thanks for the help! –  Orestis Tsinalis Jul 22 '12 at 16:07
add comment

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.

share|improve this answer
    
I'm getting an error: SELECT ST_GeomFromGML('<gml:Point srsName="osgb:BNG"><gml:coordinates>527347.0,181346.0</gml:coordinates></gml:Poi‌​nt>', 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? –  Orestis Tsinalis Jul 22 '12 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. –  lynxlynxlynx Jul 22 '12 at 16:14
    
Cool, thanks, I have PostGIS 1.5.3 installed at the moment. –  Orestis Tsinalis Jul 22 '12 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 Jul 22 '12 at 16:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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