18

What is the function for getting SRID from Geometry field.

I have inserted a shapefile into SQL Server table with a Geometry field defined. I know the projection of shapefile is Swreff99_1800 (EPSG:3011).

Now my question is How I get this SRID:3011 by using some OGC method of the geometry field?

1
  • I'm not clear as to what you are needing. Do you need the definition of the SRID 3011 from SQL Server? It sounds like you have already inserted the data with the proper SRID set, yes? Commented Feb 7, 2012 at 12:54

3 Answers 3

33

Is this what you are looking for?

select distinct SP_GEOMETRY.STSrid from dbo.MYTABLE

This will give you a table with the different SRID's used in the table dbo.MYTABLE

2
  • Thanks!. My second question is SRID 3011 is not defined in sys.spatial_reference_systems table. And i need to transform the geometry from SRID 3011 to SRID 4326. What I do then ?
    – user1899
    Commented Feb 7, 2012 at 13:41
  • 1
    As far as I know, SQL Server 2008 is not able to transform your geometry data bewteen different coordinate systems - it sees all geometry data as stored in a mathematical coordinate system. Commented Mar 19, 2012 at 20:10
7

After trying the above with no luck, I tried the method below:

select [geomColumnName].STSrid
from [schema].[tableName]

This gives the SRID value for all records in the table. I would assume that since all records SHOULD have the same SRID, that if you wanted to simply get the value for one record it would tell you the SRID for the entire table:

select top 1 [geomColumnName].STSrid
from [schema].[tableName]
2
  • I'm wondering what version of MS SQL Server you are using and if there has been any change in the later versions that would make the use of Distinct not supported? Or is it just that your Geometry column name isn't SP_GEOMETRY? I have seen a few cases where the Geometry was stored with different SRIDs eventhough they were referring to similar coordinate systems. Commented Nov 11, 2016 at 7:49
  • 2
    @PeterHorsbøllMøller looking at this again, I didn't see that his use of SP_GEOMETRY was referring to the geometry column name, so my answer is almost the same as the accepted... Commented Nov 11, 2016 at 16:41
0

I believe the number that you'd want to use at this point would be srid 4619 or srid 4977 is SQL server.

These are both equivalent to EPSG 3011.

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.