Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:20:08+00:00 2026-06-04T15:20:08+00:00

I have a database table which currently holds geometric data in SRID 27700 (British

  • 0

I have a database table which currently holds geometric data in SRID 27700 (British National Grid). While retrieving the data however I need to transform it to SRID 4326 (WGS84). Is there any way to apply a function such as ST_Transform found in PostGIS to my data in order to get the result I need?

NOTE: The solution needs to be able to be implemented using T-SQL and not stored procedures etc. I have to be able to construct a statement and have it saved in a table as a string field for retrieval later. This is because my solution is database agnostic.

The way I am currently doing this in Oracle is as follows:

select CLUSTER_ID, 
       NUM_POINTS, 
       FEATURE_PK, 
       A.CELL_CENTROID.SDO_POINT.X, 
       A.CELL_CENTROID.SDO_POINT.Y, 
       A.CLUSTER_CENTROID.SDO_POINT.X, 
       A.CLUSTER_CENTROID.SDO_POINT.Y, 
       TO_CHAR (A.CLUSTER_EXTENT.GET_WKT ()),  
       TO_CHAR (A.CELL_GEOM.GET_WKT ()), 
       A.CLUSTER_EXTENT.SDO_SRID 
from (SELECT CLUSTER_ID, 
             NUM_POINTS, 
             FEATURE_PK, 
             SDO_CS.transform (CLUSTER_CENTROID, 4326) cluster_centroid,
             CLUSTER_EXTENT, 
             SDO_CS.transform (CELL_CENTROID, 4326) cell_centroid, 
             CELL_GEOM FROM :0) a  
where sdo_filter( A.CELL_GEOM, 
                  SDO_CS.transform(mdsys.sdo_geometry(2003, :1, NULL, mdsys.sdo_elem_info_array(1,1003,3),mdsys.sdo_ordinate_array(:2, :3, :4, :5)),81989)) = 'TRUE'

In PostgreSQL using PostGIS I am doing it like this:

select CLUSTER_ID, 
       NUM_POINTS, 
       FEATURE_PK, ST_X(a.CELL_CENTROID), 
       ST_Y(a.CELL_CENTROID), 
       ST_X(ST_TRANSFORM(a.CLUSTER_CENTROID, 4326)),  
       ST_Y(ST_TRANSFORM(a.CLUSTER_CENTROID, 4326)), 
       ST_AsText(a.CLUSTER_EXTENT),  
       ST_AsText(a.CELL_GEOM), 
       ST_SRID(a.CLUSTER_EXTENT)  
FROM (SELECT CLUSTER_ID, 
      NUM_POINTS, 
      FEATURE_PK, 
      ST_TRANSFORM(ST_SetSRID(CLUSTER_CENTROID, 27700), 4326) cluster_centroid, 
      CLUSTER_EXTENT, 
      ST_TRANSFORM(ST_SetSRID(CELL_CENTROID, 27700), 4326) cell_centroid, 
      CELL_GEOM 
from :0) AS a 
where ST_Intersects(ST_Transform(ST_SetSRID(a.CELL_GEOM, 27700), :1), ST_Transform(ST_GeomFromText('POLYGON(('||:2||' '||:3||', '||:4||' '||:3||', '||:4||' '||:5||', '||:2||' '||:5||', '||:2||' '||:3||'))', 4326), :1))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:20:09+00:00Added an answer on June 4, 2026 at 3:20 pm

    You could wrap something like DotNetCoords in a SQL CLR function to do this.

    See here:- http://www.doogal.co.uk/dotnetcoords.php

    I’ve wrapped it in a CLR function to convert coordinates from Easting/Northing to Lat/Long which I think is what you are asking for. Once the CLR function is implemented it is a pure SQL solution (i.e. you can run it all in a Stored Procedure or View).

    EDIT: I will post some sample code up here when I get to work tomorrow, hopefully it will help.

    EDIT: You’ll need to download the source code from http://www.doogal.co.uk/dotnetcoords.php and you will need Visual Studio to open and modify it. Documentation for the library is here http://www.doogal.co.uk/Help/Index.html

    What you can do then is you can add a new class to the source files similar to this:-

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data.SqlTypes;
    using DotNetCoords;
    using Microsoft.SqlServer.Server;
    
    /// <summary>
    /// Sql Server CLR functions for the DotNetCoords library.
    /// </summary>
    public class CLRFunctions
    {
    
        /// <summary>
        /// Coordinateses the enumerable.
        /// </summary>
        /// <param name="Easting">The easting.</param>
        /// <param name="Northing">The northing.</param>
        /// <returns></returns>
        private static IEnumerable<OSRef> CoordinatesEnumerable(double Easting, double Northing)
        {
            return new List<OSRef> { new OSRef(Easting,Northing) };
        }
    
        /// <summary>
        /// Toes the lat long.
        /// </summary>
        /// <param name="Easting">The easting.</param>
        /// <param name="Northing">The northing.</param>
        /// <returns></returns>
        [SqlFunction(FillRowMethodName = "FillRow")]
        public static IEnumerable ToLatLong(double Easting, double Northing)
        {
            return CoordinatesEnumerable(Easting, Northing);
        }
    
        /// <summary>
        /// Fills the row.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="Lat">The lat.</param>
        /// <param name="Long">The long.</param>
        private static void FillRow(Object obj, out SqlDouble Lat, out SqlDouble Long)
        {
            OSRef Coordinates = (OSRef)obj;
            LatLng latlong = Coordinates.ToLatLng();
            latlong.ToWGS84();
            Lat = new SqlDouble(latlong.Latitude);
            Long = new SqlDouble(latlong.Longitude);
        }
    
    }
    

    You will then need to build and import the assembly into SQL Server (replace paths with your own locations) (for some reason I cannot get the assembly to install when PERMISSION_SET is ‘SAFE’ so I would sort this first before installing in a production environment).

    CREATE ASSEMBLY DotNetCoords
    FROM N'C:\Projects\DotNetCoords\bin\Debug\DotNetCoords.dll'
    WITH PERMISSION_SET = UNSAFE
    GO
    

    You’ll then need to create a SQL Server function to interface to the CLR function:-

    CREATE FUNCTION dbo.ToLatLong(@Easting float, @Northing float)
    RETURNS TABLE
    (Latitude float null, Longitude float null) with execute as caller
    AS
    EXTERNAL NAME [DotNetCoords].[CLRFunctions].[ToLatLong]
    

    This is the CLR function installed then.

    You should then be able to call the function direct from SQL Server to do your conversion (I have mixed up the numbers in this post too keep anonymity so they might not make sense here but the function does work fine).

    /*------------------------
    SELECT Latitude, Longitude FROM dbo.ToLatLong(327262, 357394)
    ------------------------*/
    Latitude            Longitude
    52.13413530182533       -9.34267170569508
    
    (1 row(s) affected)
    

    To use it in a resultset you need to use the CROSS APPLY clause:-

    /*------------------------
    SELECT TOP 2    a.[Column 0] AS osaddessp,
                                a.[Column 9] AS east,
                                a.[Column 10] AS north,
                                c.[Latitude] AS lat,
                                c.[Longitude] AS long
    FROM    MyTable AS a CROSS APPLY ToLatLong (a.[Column 9], a.[Column 10]) AS c;
    ------------------------*/
    osaddessp       east    north   lat         long
    100134385607    327862  334794  52.3434530182533    -2.19342342569508
    100123433149    780268  353406  52.3453417606796    -3.19252323679263
    
    (10 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have an arraylist in C# which holds the my data base table
I have an sqlite database which currently holds an integer field called Year which
I have a database table in Sql Server 2008 R2 which contains data stored
I have one database table which contains 8 columns. One of the columns is
I have a database table which link locations together; a location can be in
I have a database table which is full-text indexed and i use the CONTAINS-function
I have a database table A which stores records, A has a primary key
In an application we are developing, I have access to a database table which
i have a large mysql database table in which one column contains values ranging
I have a database table named 'student' in which there is one column named

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.